[C++-sig] A very strange behaviour of Boost (Mingw, gcc 4.5)

Jérôme Laheurte fraca7 at free.fr
Tue Jun 7 09:40:25 CEST 2011

Hello. I already asked this on StackOverflow but it doesn't seem to 
inspire many people. I managed to reduce my problem to a trivial 
extension module:

#include <Python.h>
#include <boost/python.hpp>

using namespace boost::python ;
using namespace boost;

class PyTest

     PyErr_SetString(PyExc_RuntimeError, "FOO");

     class_<PyTest>("Test", init<>())

On Windows XP SP3, if I build Boost 1.46.1 and then this extension with 
GCC 3.4.5 from an older version of Mingw, everything behaves as expected:

 >>> import testmod
 >>> testmod.Test()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
RuntimeError: FOO

Now if I rebuild both Boost and the module using a newer Mingw, with GCC 
4.5.2, this happens:

 >>> import testmod
 >>> testmod.Test()

This application has requested the Runtime to terminate it in an unusual 
Please contact the application's support team for more information.

Putting a break on abort in GDB and printing the stack gives this:

(gdb) bt
#0  0x77c36bb3 in msvcrt!abort () from C:\WINDOWS\system32\msvcrt.dll
#1  0x69acfdb2 in testmod!_Unwind_SetGR () from C:\Python22\DLLs\testmod.pyd
#2  0x69b2a45d in 
EE9signatureEv () from C:\Python22\DLLs\testmod.pyd
#3  0x6e9544a3 in libgcc_s_dw2-1!__trunctfxf2 ()
    from C:\WINDOWS\system32\libgcc_s_dw2-1.dll
#4  0x6e954877 in libgcc_s_dw2-1!_Unwind_RaiseException ()
    from C:\WINDOWS\system32\libgcc_s_dw2-1.dll
#5  0x6fcbc6e2 in libstdc++-6!__cxa_throw ()
    from C:\WINDOWS\system32\libstdc++-6.dll
#6  0x63455d4c in boost::python::throw_error_already_set() ()
    from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#7  0x69ac12de in testmod!_ZN6PyTestC2Ev () from 
#8  0x69adbbf1 in 
12value_holderI6PyTestEENS_3mpl7vector0IN4mpl_2naEEEE7executeEP7_object ()
    from C:\Python22\DLLs\testmod.pyd
#9  0x69adbde9 in 
EclES6_S6_ () from C:\Python22\DLLs\testmod.pyd
#10 0x63450031 in boost::python::objects::function::call(_object*, 
_object*) con
st () from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#11 0x634501fb in 
hon::objects::(anonymous namespace)::bind_return, 
unction::function_buffer&) ()
    from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#12 0x63455e5a in 
     () from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#13 0x634512be in function_call ()
    from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#14 0x1e006ccc in python22!PyObject_Call ()
    from C:\WINDOWS\system32\python22.dll
#15 0x0089d138 in ?? ()
#16 0x63469420 in boost::python::docstring_options::show_py_signatures_ ()
    from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#17 0x0084d0f0 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

It looks like the error_already_set exception is somewhat not catched as 
it should be. In my actual use case, the class has several methods. This 
only happens with some of them; I couldn't find any difference between 
the methods for which the mechanism works and the other ones (same 
number and type of parameters, same exception type)...

Any hint would be greatly appreciated.

More information about the Cplusplus-sig mailing list