Opened 12 years ago

Closed 12 years ago

#4671 closed Bugs (worksforme)

std::bad_cast crash seems to be linked to boost_regex

Reported by: Spinach <spinachio@…> Owned by: John Maddock
Milestone: To Be Determined Component: regex
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

I've gotten the exact same code compiled on Ubuntu and am now trying to get my program working on a MacOS 10.6.4. I installed boost 1.4.4 as root using ./bootstrap.sh and then ./bjam

I also performed the following: ./bjam install variant=debug define=_GLIBCXX_DEBUG --with-regex

I compiled the program using Codeblocks (without any errors) but when I run the program I get the following error:

./graph_search 
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Abort trap

When I look into the error using Console, I see the following error

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libSystem.B.dylib             	0x00007fff837c33d6 __kill + 10
1   libSystem.B.dylib             	0x00007fff83863972 abort + 83
2   libstdc++.6.dylib             	0x00007fff826785d2 __tcf_0 + 0
3   libstdc++.6.dylib             	0x00007fff82676ae1 __cxxabiv1::__terminate(void (*)()) + 11
4   libstdc++.6.dylib             	0x00007fff82676b16 __cxxabiv1::__unexpected(void (*)()) + 0
5   libstdc++.6.dylib             	0x00007fff82676bfc __gxx_exception_cleanup(_Unwind_Reason_Code, _Unwind_Exception*) + 0
6   libstdc++.6.dylib             	0x00007fff8263293f std::__throw_bad_alloc() + 0
7   libboost_regex.dylib          	0x00000001000c34b8 std::collate<char> const& std::use_facet<std::collate<char> >(std::locale const&) + 85 (locale_facets.tcc:117)
8   libboost_regex.dylib          	0x000000010009b794 boost::re_detail::cpp_regex_traits_base<char>::imbue(std::locale const&) + 124 (cpp_regex_traits.hpp:218)
9   libboost_regex.dylib          	0x00000001000cde35 boost::re_detail::cpp_regex_traits_base<char>::cpp_regex_traits_base(std::locale const&) + 43 (cpp_regex_traits.hpp:173)
10  libboost_regex.dylib          	0x00000001000cde83 boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::locale const&) + 30 (cpp_regex_traits.hpp:852)
11  libboost_regex.dylib          	0x00000001000cdeed boost::cpp_regex_traits<char>::cpp_regex_traits() + 35 (cpp_regex_traits.hpp:872)
12  libboost_regex.dylib          	0x00000001000cdf33 boost::regex_traits<char, boost::cpp_regex_traits<char> >::regex_traits() + 21 (regex_traits.hpp:75)
13  libboost_regex.dylib          	0x00000001000cdf4b boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_traits_wrapper() + 21 (regex_traits.hpp:169)
14  libboost_regex.dylib          	0x00000001000cdf8d boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_data() + 63 (basic_regex.hpp:212)
15  libboost_regex.dylib          	0x00000001000ce041 boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::basic_regex_implementation() + 21 (basic_regex.hpp:248)
16  libboost_regex.dylib          	0x000000010009b815 boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int) + 75 (basic_regex.hpp:698)
17  graph_search                  	0x00000001000055e5 main + 773
18  graph_search                  	0x0000000100001048 start + 52

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x00007fff7066e2d8  rcx: 0x00007fff5fbfdc18  rdx: 0x0000000000000000
  rdi: 0x000000000000a367  rsi: 0x0000000000000006  rbp: 0x00007fff5fbfdc30  rsp: 0x00007fff5fbfdc18
   r8: 0x0000000000000000   r9: 0x0000000100600460  r10: 0x00007fff837bf412  r11: 0x0000000000000202
  r12: 0x00007fff8267b530  r13: 0x0000000100600420  r14: 0x0000000000000000  r15: 0x0000000000000000
  rip: 0x00007fff837c33d6  rfl: 0x0000000000000202  cr2: 0x00007fff7067f058

I would be so appreciative of any help anyone could provide.

Thank you, Spinach

Change History (3)

comment:1 by Marshall Clow, 12 years ago

Component: Noneregex
Owner: set to John Maddock

comment:2 by anonymous, 12 years ago

This is a problem with the locale you are using - for whatever reason it doesn't contain a std::collate<char> facet - as it's required to do so by the standard.

You could try and reproduce with:

std::locale l;
std::use_facet<std::collate<char> >(l);

and see if that also throws.

If it does, I'm not sure what the cause/solution is - it certainly should be reported to the libstdc++ developers if it's reproducable. I'm also not sure why we don't see this problem on any of our MacOS test machines. As a workaround you could try defining BOOST_REGEX_USE_C_LOCALE in boost/regex/user.hpp so the library doesn't use the C++ locale at all (and rebuild obviously).

One final check, I note that you're building the library with _GLIBCXX_DEBUG defined, I assume that your app is also built with that defined? If not it will crash for sure as in general you can't mix object files with and without that define.

HTH, John.

comment:3 by John Maddock, 12 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.