[C++-sig] Re: what happened with this std::string parameter in boost.python

David Abrahams dave at boost-consulting.com
Fri Dec 17 00:05:02 CET 2004


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




More information about the Cplusplus-sig mailing list