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

2011-06-07 Thread Jérôme Laheurte
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 
#include 

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_("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 "", 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 
way.

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 
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_2na7executeEP7_object ()
   from C:\Python22\DLLs\testmod.pyd
#9  0x69adbde9 in 
testmod!_ZN5boost6python7objects23caller_py_function_implINS0_

6detail6callerIPFvP7_objectENS0_21default_call_policiesENS_3mpl7vector2IvS6_
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_invoker0hon::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)

() 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.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


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

2011-06-07 Thread Lars Viklund
On Tue, Jun 07, 2011 at 09:40:25AM +0200, Jérôme Laheurte wrote:
> 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:

> 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:

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

> Any hint would be greatly appreciated.

Typically, you need to use the same major flavor of toolchain to build
Boost.Python and your extension as was used to build your Python.

If the runtimes (and exception handling) differ, you'll get ODR
violations on things like FILE* and error handling.

What you're observing there is probably console output crashing when an
error is printed. If the runtimes have different ideas of what
constitutes a FILE* (which output is done through), you blow up good.
This also includes using static runtimes to some extent.

-- 
Lars Viklund | [email protected]
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

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

2011-06-07 Thread Jérôme Laheurte

On 06/07/2011 09:59 AM, Lars Viklund wrote:


On Tue, Jun 07, 2011 at 09:40:25AM +0200, Jérôme Laheurte wrote:

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:



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:



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



Any hint would be greatly appreciated.


Typically, you need to use the same major flavor of toolchain to build
Boost.Python and your extension as was used to build your Python.

If the runtimes (and exception handling) differ, you'll get ODR
violations on things like FILE* and error handling.

What you're observing there is probably console output crashing when an
error is printed. If the runtimes have different ideas of what
constitutes a FILE* (which output is done through), you blow up good.
This also includes using static runtimes to some extent.


So the old Mingw 3.x runtime was compatible with the Visual 6 one but 
not the 4.5 one... Thanks for the suggestion; I'll try to get Python to 
build with GCC 4.5 and see if it fixes the issue.


Thanks!
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig