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

David Abrahams dave at boost-consulting.com
Mon Dec 20 21:44:39 CET 2004


Donnie Leen wrote:
> Dave Abrahams wrote:
>>What do you mean by "crashed?"  Are you sure it didn't throw an
>>exception that was never caught?
> yes, I try to catch the exception, but it crashed in the function PyRun_SimpleString I called to run python code,and it didn't throw exception to my try-catch.
> 
>>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;
>>    }
> Thanks your suggestion, I had followed you suggestion, but I didn't get any more information about the "crash", the result was the same as the first time I run it.
> I made the c++ program in vc6, use stlport std library, my system is win2000+sp4.
> and in the vc6 debugger, i found the exception was caught by the following function in src/object/function.cpp of boost.python:
>     static PyObject *
>     function_call(PyObject *func, PyObject *args, PyObject *kw)
>     {
>         PyObject* result = 0;
>         handle_exception(bind_return(result, static_cast<function*>(func), args, kw));
>         return result;
>     }
> I use PyRun_SimpleString to run python code, and the python code call my function through function_call of boost.python, the function_call had handled the exception, could I catch the exception any more?

No you can't; it has been translated into a Python exception.  You can
see that exception by calling PyErr_Print.

> I paste the call stack of vc6 debugger as following:
> NTDLL! 77f813b1()
> NTDLL! 77fb6972()
> NTDLL! 77f8be26()
> KERNEL32! 77e7f76e()
> _CrtIsValidHeapPointer(const void * 0x005857b0) line 1697

This means you have heap corruption.  Something you have done is walking
over and modifying memory it shouldn't touch.

> _free_dbg_lk(void * 0x005857b0, int 1) line 1044 + 9 bytes
> _free_dbg(void * 0x005857b0, int 1) line 1001 + 13 bytes
> free(void * 0x005857b0) line 956 + 11 bytes
> operator delete(void * 0x005857b0) line 7 + 9 bytes
> _STL::__stl_delete(void * 0x005857b0) line 99 + 33 bytes


-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list