Re: what happened with this std::string parameter inboost.python
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?
I paste the call stack of vc6 debugger as following: NTDLL! 77f813b1() NTDLL! 77fb6972() NTDLL! 77f8be26() KERNEL32! 77e7f76e() _CrtIsValidHeapPointer(const void * 0x005857b0) line 1697 _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 _STL::__node_alloc<1,0>::deallocate(void * 0x005857b0, unsigned int 414) line 253 + 42 bytes _STL::allocator<char>::deallocate(char * 0x005857b0, unsigned int 414) line 360 + 19 bytes _STL::_STLP_alloc_proxy<char *,char,_STL::allocator<char> >::deallocate(char * 0x005857b0, unsigned int 414) line 507 _STL::_String_base<char,_STL::allocator<char> >::_M_deallocate_block() line 124 + 58 bytes _STL::_String_base<char,_STL::allocator<char> >::~_String_base<char,_STL::allocator<char> >() line 135 + 65 bytes _STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >::~basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >() line 302 + 96 bytes boost::python::detail::value_destroyer<0>::execute(const _STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > * 0x0012f8c4) line 34 boost::python::detail::destroy_referent_impl(void * 0x0012f8c4, _STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > & (void)* 0x00000000) line 95 + 9 bytes boost::python::detail::destroy_referent(void * 0x0012f8c4, _STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > & (void)* 0x00000000) line 101 + 11 bytes boost::python::converter::rvalue_from_python_data<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > &>::~rvalue_from_python_data<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > &>() line 135 + 14 bytes boost::python::converter::arg_rvalue_from_python<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >::~arg_rvalue_from_python<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >() + 37 bytes boost::python::arg_from_python<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >::~arg_from_python<_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> > >() + 37 bytes boost::python::detail::caller_arity<1>::impl<void (__cdecl*)(_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >),boost::python::default_call_policies,boost::mpl::vector2<void,_STL::basic_string<char,_STL::char_traits<char>,_STbfdc5a11(_object * 0x00a81c90, _object * 0x00000000) line 201 + 42 bytes boost::python::objects::caller_py_function_impl<boost::python::detail::caller<void (__cdecl*)(_STL::basic_string<char,_STL::char_traits<char>,_STL::allocator<char> >),boost::python::default_call_policies,boost::mpl::vector2<void,_STL::basic_stringf77a00c5(_object * 0x00a81c90, _object * 0x00000000) line 39 boost::python::objects::py_function::operator()(_object * 0x00a81c90, _object * 0x00000000) line 139 + 32 bytes boost::python::objects::function::call(_object * 0x00a81c90, _object * 0x00000000) line 212 + 36 bytes boost::python::objects::`anonymous namespace'::bind_return::operator()() line 505 + 25 bytes boost::detail::function::void_function_obj_invoker0<boost::python::objects::`anonymous namespace'::bind_return,void>::invoke(boost::detail::function::any_pointer {...}) line 129 boost::function0<void,int>::operator()() line 320 + 28 bytes boost::python::handle_exception_impl(boost::function0<void,int> {...}) line 26 boost::python::handle_exception(boost::python::objects::`anonymous-namespace'::bind_return {...}) line 29 + 35 bytes function_call(_object * 0x00564a80, _object * 0x00a81c90, _object * 0x00000000) line 537 + 56 bytes PYTHON24! 1e01937c() Thanks Donnie Leen
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
participants (2)
-
David Abrahams -
Donnie Leen