[python] Crash when running variant=debug-python libraries

Hi, First off I am using Boost 1.34.1 and I have built the libraries myself using the following command line. My compiler is MSVC 9.0. *bjam --toolset=msvc --layout=system link=shared threading=multi variant=debug-python stage* The code I'm running has worked fine using *variant=debug*, however it crashes with an "access violation" against NULL with *variant=debug-python*, which I had assumed defined BOOST_DEBUG_PYTHON. My goal was to get the debug Boost.Python library to link against the debug python25 shared library (it seemed to work). Below is the code I'm compiling. BEGIN CODE --------------------------------------------- #define BOOST_PYTHON_DEF( func ) boost::python::def( #func, func ) using namespace boost::python; static char const* PrintHelloWorld() { return "Hello World!"; } BOOST_PYTHON_MODULE(Script) { BOOST_PYTHON_DEF( PrintHelloWorld ); } object GetNamespace( char const* mod ) { object theModule = import( mod ); return theModule.attr( "__dict__" ); } void BeginPythonTest() { try { Py_Initialize(); initScript(); object main = GetNamespace( "__main__" ); object sys = GetNamespace( "sys" ); list path( sys["path"] ); path.insert( 0, "python" ); sys["path"] = path; main["Script"] = import( "Script" ); main["rocket"] = import( "rocket" ); exec_file( "pythontest.py", main, main ); Py_Finalize(); } catch( error_already_set const& /*err*/ ) { PyErr_Print(); } catch( std::invalid_argument const& /*err*/ ) { PyErr_Print(); } } --------------------------------------------- END CODE And, for your reference, the callstack at the time of the crash (note that it may be a little bit mangled): *> boost_python-mt-gy.dll!boost::python::objects::function::function(const boost::python::objects::py_function & implementation={...}, const boost::python::detail::keyword * const names_and_defaults=0x7ffdb000, unsigned int num_keywords=3435973836) Line 104 + 0xb bytes C++ 0012f520() boost_python- mt-gy.dll!boost::detail::function::void_function_ref_invoker0<void (__cdecl*)(void),void>::invoke(boost::detail::function::function_buffer & function_obj_ptr={...}) Line 191 C++ boost_python-mt-gy.dll!boost::function0<void,std::allocator<boost::function_base>
::operator()() Line 692 + 0x11 bytes C++ boost_python-mt-gy.dll!boost::python::handle_exception_impl(boost::function0<void,std::allocator<boost::function_base> f={...}) Line 26 C++ boost_python-mt-gy.dll!boost::python::handle_exception<void (__cdecl*)(void)>(void (void)* f=0x00474695) Line 29 + 0x2c bytes C++ boost_python-mt-gy.dll!boost::python::detail::init_module(const char * name=0x0055ea08, void (void)* init_function=0x00474695) Line 39 + 0x9 bytes C++ rocket_test_Debug.exe!initScript() Line 15 + 0x30 bytes C++ rocket_test_Debug.exe!BeginPythonTest() Line 34 C++*

Well I did a little more Trial & Error experimentation, and I've found that I get different behavior if I include <Python.h> before <boost/python.hpp> versus if I just omit <Python.h> inclusion all together. When I only include <boost/python.hpp>, I get an assertion instead of a crash. This assertion spits text out to my console window as follows: *Assertion failed: (op->_ob_prev == NULL) == (op->_ob_next == NULL), file ..\Objects\object.c, line 63* This assertion occurs during the call to Py_Initialize(). At this point this seems a little out of scope of boost (since at this point I haven't even called anything from boost that I'm aware of). I'm going to post this on the python mailing list to see if I can get some opinions there as well.

on Thu Feb 21 2008, "Robert Dailey" <rcdailey-AT-gmail.com> wrote:
Well I did a little more Trial & Error experimentation, and I've found that I get different behavior if I include <Python.h> before <boost/python.hpp> versus if I just omit <Python.h> inclusion all together.
Yes, http://boost.org/libs/python/doc/building.html#include-issues and the section that follow explain why you should not include <Python.h>
When I only include <boost/python.hpp>, I get an assertion instead of a crash. This assertion spits text out to my console window as follows:
*Assertion failed: (op->_ob_prev == NULL) == (op->_ob_next == NULL), file ..\Objects\object.c, line 63*
Which tells me that you have a mismatch between Boost.Python's idea of whether it is a debugging build and the Python executable or library's idea.
This assertion occurs during the call to Py_Initialize(). At this point this seems a little out of scope of boost (since at this point I haven't even called anything from boost that I'm aware of). I'm going to post this on the python mailing list to see if I can get some opinions there as well.
If you follow the instructions at http://boost.org/libs/python/doc/building.html and pass python-debugging=on on your bjam command line, everything "just works." -- Dave Abrahams Boost Consulting http://boost-consulting.com
participants (2)
-
David Abrahams
-
Robert Dailey