what happened with this std::string parameter in boost.python
I made a program embedding boost.python, writting a module as following: void write( std::string s ) { // do nothing } BOOST_PYTHON_MODULE(mym) { def( "write", &write ); } I run the python code: import mym s = 'hello' mym.write(s) it runs ok, but if i run the python code as following: import mym s = int.__doc__ mym.write(s) it crashed, and it seems to crashed while boost.python try to delete the parameter s. Can someone tell me what happened to it? Thanks first. Donnie Leen
Donnie Leen wrote:
I made a program embedding boost.python, writting a module as following:
void write( std::string s ) { // do nothing } BOOST_PYTHON_MODULE(mym) { def( "write", &write ); }
I run the python code: import mym s = 'hello' mym.write(s)
it runs ok, but if i run the python code as following: import mym s = int.__doc__ mym.write(s)
it crashed
What do you mean by "crashed?" Are you sure it didn't throw an exception that was never caught?
, and it seems to crashed while boost.python try to delete the parameter s. Can someone tell me what happened to it? Thanks first.
I suggest you insert the contents of libs/python/test/module_tail.cpp into your program, run it again, and see where the JIT debugger says the "crash" occurs. I also suggest you try putting the logic of your program inside a call to python::handle_exception, per libs/python/test/embedding.cpp: if (python::handle_exception(something)) { if (PyErr_Occurred()) PyErr_Print(); return 1; } -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
David Abrahams wrote:
Donnie Leen wrote:
I made a program embedding boost.python, writting a module as following:
void write( std::string s ) { // do nothing } BOOST_PYTHON_MODULE(mym) { def( "write", &write ); }
I run the python code: import mym s = 'hello' mym.write(s)
it runs ok, but if i run the python code as following: import mym s = int.__doc__ mym.write(s)
it crashed
What do you mean by "crashed?" Are you sure it didn't throw an exception that was never caught?
I had this problem earlier. It would just access violate, as though the string had a bad buffer pointer. I didn't look into it too much and changed it to const char*'s so I could just get things working. Although now, when I change it back to test, it doesn't crash anymore. :( FWIW kalin
"kalin" == kalin <kalin.eh@gmail.com> writes:
kalin> David Abrahams wrote: >> Donnie Leen wrote: >> >>> I made a program embedding boost.python, writting a module as following: >>> >>> void write( std::string s ) >>> { >>> // do nothing >>> } >>> BOOST_PYTHON_MODULE(mym) >>> { >>> def( "write", &write ); >>> } >>> >>> >>> I run the python code: >>> import mym >>> s = 'hello' >>> mym.write(s) >>> >>> it runs ok, but if i run the python code as following: >>> import mym >>> s = int.__doc__ >>> mym.write(s) >>> >>> it crashed >> What do you mean by "crashed?" Are you sure it didn't throw an >> exception that was never caught? >> [...] Is this under Windows? We had problems like that -- short string (<16 bytes?) work, long strings cause a crash. We traced this to multiple versions of the C++ runtime library. Are you linking the runtime library statically? Holger
participants (4)
-
David Abrahams -
Donnie Leen -
Holger Duerer -
kalin