2

Using Python 2.2.3, Boost 1.46 and this trivial extension module:

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

using namespace boost::python ;
using namespace boost;

class PyTest
{
public:
    PyTest();
};

PyTest::PyTest()
{
    PyErr_SetString(PyExc_RuntimeError, "FOO");
    throw_error_already_set();
}

BOOST_PYTHON_MODULE(testmod)
{
    class_<PyTest>("Test", init<>())
        ;
}

If I build Boost, then this module, using GCC 3.4.5 (Mingw on XP SP3), everything works well:

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

Not changing anything but the compiler (GCC 4.5.2) gives this:

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

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

So I launch gdb and put a break on abort. Seems to me like the error_already_set exception isn't catched by anybody:

(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 testmod!_ZNK5boost6python7objects23caller_py_function_implINS0
_6detail6callerIPFvP7_objectENS0_21default_call_policiesENS_3mpl7vector2IvS6_EEE
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 C:\Python22\DLLs\testmod.pyd
#8  0x69adbbf1 in testmod!_ZN5boost6python7objects11make_holderILi0EE5applyINS1_
12value_holderI6PyTestEENS_3mpl7vector0IN4mpl_2naEEEE7executeEP7_object ()
   from C:\Python22\DLLs\testmod.pyd
#9  0x69adbde9 in testmod!_ZN5boost6python7objects23caller_py_function_implINS0_
6detail6callerIPFvP7_objectENS0_21default_call_policiesENS_3mpl7vector2IvS6_EEEE
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 boost::detail::function::void_function_ref_invoker0<boost::pyt
hon::objects::(anonymous namespace)::bind_return, void>::invoke(boost::detail::f
unction::function_buffer&) ()
   from C:\WINDOWS\system32\libboost_python-mgw45-mt-1_46_1.dll
#12 0x63455e5a in boost::python::handle_exception_impl(boost::function0<void>)
    () 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?)

The funny thing is that in my actual use case, the class has several methods wrapped; for some of them the error_already_set mechanism works; for some others it doesn't... Does a C++ guru have any hint about this ?

fraca7
  • 1,178
  • 5
  • 11

0 Answers0