
::resize(boost::re_detail::raw_storage<boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012eff0, unsigned int 1120) line 223 boost::re_detail::raw_storage<boost::detail::allocator_adapter<char,boost::detail::simple_alloc> ::extend(boost::re_detail::raw_storage<boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012eff0, unsigned int 268) line 131 + 27 bytes boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> ::compile_set_aux(boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012efe8, ...) line 1145 + 17 bytes boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> ::compile_set_simple(boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012efe8, boost::re_detail::re_syntax_base * 0x012e6534, unsigned long 8, unsigned char 0) line 737 + 48 bytes boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> ::set_expression(boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012efe8, const char * 0x0846601c `string', const char * 0x08466049, unsigned int 34055) line 1651 + 20 bytes boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> ::set_expression(boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012efe8, const char * 0x0846601c `string', unsigned int
The code snippet: struct Grepper { int nPriority; boost::regex re; pONGREPFOUNDCALLBACK pOnGrepFoundSymbols; friend bool operator< (const Grepper& g1, const Grepper& g2) { return g1.nPriority > g2.nPriority; } }; if (...){ Grepper gp; if (QueryGreppers(gp)) g_vecGreppers.push_back(gp); } bool QueryGreppers(Grepper& gp) { gp.nPriority = 1; gp.re ="\\s*#define\\s+([^\\s]+)\\s+([^/\\r\\n]+)([^\\r\\n]*)"; gp.pOnGrepFoundSymbols = OnGrepSingleLineSymbols; return true; } Program fails at gp.re = ... The call stack is: _CrtIsValidHeapPointer(const void * 0x012e61f8) line 1606 _free_dbg_lk(void * 0x012e61f8, int 1) line 1011 + 9 bytes _free_dbg(void * 0x012e61f8, int 1) line 970 + 13 bytes free(void * 0x012e61f8) line 926 + 11 bytes operator delete(void * 0x012e61f8) line 7 + 9 bytes boost::detail::simple_alloc::deallocate(void * 0x012e61f8, unsigned int 1024) line 213 + 9 bytes boost::detail::allocator_adapter<unsigned char,boost::detail::simple_alloc>::deallocate(unsigned char * 0x012e61f8, unsigned int 1024) line 258 boost::re_detail::raw_storage<boost::detail::allocator_adapter<char,boost::detail::simple_alloc> 34055) line 238 + 59 bytes boost::reg_expression<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc>
::assign(const char * 0x0846601c `string', unsigned int 33031) line 89 + 20 bytes boost::basic_regex<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> ::operator=(boost::basic_regex<char,boost::regex_traits<char>,boost::detail::allocator_adapter<char,boost::detail::simple_alloc> * const 0x0012efe8, const char * 0x0846601c `string') line 356 QueryGreppers(Grepper & {...}) line 35 + 17 bytes
What's wrong with it?

What's wrong with it?
Works for me with Boost-1.33 if I just use: int main(void) { boost::regex re; re ="\\s*#define\\s+([^\\s]+)\\s+([^/\\r\\n]+)([^\\r\\n]*)"; return 0; } Can you please provide: Boost version (please try 1.33 as well). Platform/compiler. A simple test case that reporduces the issue. Please make sure that you're linking to the correct regex lib build version as well (are you letting the regex headers select the lib?), if there is a mismatch and the regex lib is built against a different runtime from your application then all kinds of strange problems like this can arise. John.

Thank John! I tried this, and it's ok: struct Grepper { int nPriority; boost::regex re; friend bool operator< (const Grepper& g1, const Grepper& g2) { return g1.nPriority > g2.nPriority; } }; bool QueryGreppers(Grepper& gp) { gp.nPriority = 1; gp.re = boost::regex("\\s*#define\\s+([^\\s]+)\\s+([^/\\r\\n]+)([^\\r\\n]*)"); return true; } int main(void) { Grepper gp; QueryGreppers(gp); return 0; } But in my real project env, this code snippet is place into a DLL: Grepper gp; QueryGreppers(gp); And QueryGreppers is a function pointer get from another dll, any comments about this? Another questions: I only used Vc6 as develop tools, I know little about lib and dll selection issue. Where can I learn about how to select boost lib and dlls? "John Maddock" <john@johnmaddock.co.uk> $)ATZNDUBVPLa5=:
int main(void) { boost::regex re; re ="\\s*#define\\s+([^\\s]+)\\s+([^/\\r\\n]+)([^\\r\\n]*)"; return 0; }

OK, I know now. it could be set at VC project settings. Always use DLL. Aaron <yilu@21cn.com> wrote:
Thank John! I tried this, and it's ok:
struct Grepper { int nPriority; boost::regex re;
friend bool operator< (const Grepper& g1, const Grepper& g2) { return g1.nPriority > g2.nPriority; } }; bool QueryGreppers(Grepper& gp) { gp.nPriority = 1; gp.re = boost::regex("\\s*#define\\s+([^\\s]+)\\s+([^/\\r\\n]+)([^\\r\\n]*)");
return true; }
int main(void) { Grepper gp; QueryGreppers(gp);
return 0; }
But in my real project env, this code snippet is place into a DLL: Grepper gp; QueryGreppers(gp);
And QueryGreppers is a function pointer get from another dll, any comments about this?
Another questions: I only used Vc6 as develop tools, I know little about lib and dll selection issue. Where can I learn about how to select boost lib and dlls?
"John Maddock" <john@johnmaddock.co.uk> $)ATZNDUBVPLa5=:
int main(void) { boost::regex re; re ="\\s*#define\\s+([^\\s]+)\\s+([^/\\r\\n]+)([^\\r\\n]*)"; return 0; }

And QueryGreppers is a function pointer get from another dll, any comments about this?
Yes: better make sure you link against the dll version of the library, otherwise you will have multiple "versions" of the code in your application. Define BOOST_REGEX_DYN_LINK when building your application and dll's to do this (see http://www.boost.org/libs/regex/doc/configuration.html#linkage). If you link to other Boost libs then you have the same issue with them as well (defining BOOST_ALL_DYN_LINK will force all Boost libs to link against their dll versions). John.
participants (2)
-
Aaron
-
John Maddock