[C++-sig] First time pointers, first crash...

David Abrahams david.abrahams at rcn.com
Mon Feb 18 20:24:30 CET 2002


Is this the whole code?
Where's the cla
Your exact example works for me (Python-2.2, MSVC6Sp4, Win2K).

----- Original Message -----
From: "Stefan Franke" <franke at ableton.com>
To: <c++-sig at python.org>
Sent: Monday, February 18, 2002 1:57 PM
Subject: [C++-sig] First time pointers, first crash...


> I've just started trying to wrap a few of my class with Boost.Python.
> While the first toy examples worked well, trying to use raw pointers
> leads to the following problem.
>
> I don't think that the problem depends on the wrapped classes since
> it appears with following example as well:
>
> struct foo { int i; };
>
> // create one global instance for the whole lifetime of the program
> foo *pFoo = new foo();
> foo *GetFoo() { return pFoo; }
>
> BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
>   PyObject* to_python(foo* p)
>   {
>       return
>
boost::python::python_extension_class_converters<foo>::smart_ptr_to_python(p
> );
>   }
>   PyObject* to_python(const foo* p)
>   {
>       return to_python(const_cast<foo*>(p));
>   }
> BOOST_PYTHON_END_CONVERSION_NAMESPACE
>
>
> BOOST_PYTHON_MODULE_INIT(CompoundModule)
> {
>   py::module_builder this_module("compound2");
>
>   py::class_builder<foo> FooWrapper(this_module, "foo");
>   this_module.def(GetFoo, "getfoo");
> }
>
> If I compile & run run this in debug mode (with BOOST_DEBUG_PYTHON
enabled)
> and then type
>
> >>> from compound2 import *
> >>> getfoo()
> >>> 2         # to release the reference that _ holds to the last result
>
> it gives the following error on my Win2k/Visual Studio 6 SP5 box:
>
> HEAP[boosttest.exe]: Invalid Address specified to RtlValidateHeap( b60000,
> 3213ac0 )
>
> I've attached the call stack below. In release mode it works, since there
> are
> propably no heap checks.
>
> What I don't understand is if the foo wrapper calls foo's destructor when
> the wrapper object is destroyed. As far as I understand the doc, it only
> says that I have to take care that the object is not accidently deleted
> in C++ while the wrapper is still alive?
>
> Can you help me?
> Stefan
>
>
> --------------------------------------------------------------------------
> Call Stack:
>
> NTDLL! 77f9f9df()
> NTDLL! 77fb4966()
> NTDLL! 77f8b3d2()
> KERNEL32! 77e844cd()
> _CrtIsValidHeapPointer(const void * 0x03213ae0) line 1697
> _free_dbg_lk(void * 0x03213ae0, int 1) line 1044 + 9 bytes
> _free_dbg(void * 0x03213ae0, int 1) line 1001 + 13 bytes
> free(void * 0x03213ae0) line 956 + 11 bytes
> operator delete(void * 0x03213ae0) line 7 + 9 bytes
> boost::python::detail::extension_instance::`scalar deleting
> destructor'(unsigned int 1) + 56 bytes
>
boost::python::class_t<boost::python::detail::extension_instance>::delete_in
> stance(_object * 0x03213ae0) line 278 + 44 bytes
> boost::python::detail::class_base::instance_dealloc(_object * 0x03213ae0)
> line 345 + 20 bytes
>
boost::_mfi::mf<void>::inner_cmf1<void,boost::python::detail::type_object_ba
> se,_object *,void (__thiscall
> boost::python::detail::type_object_base::*)(_object *)const >::call() line
> 166 + 35 bytes
>
boost::_mfi::mf<void>::inner_cmf1<void,boost::python::detail::type_object_ba
> se,_object *,void (__thiscall
> boost::python::detail::type_object_base::*)(_object *)const
>::operator()()
> line 176
> boost::_bi::evaluator2<void>::eval(const
>
boost::_bi::list2<boost::_bi::value<boost::python::detail::type_object_base
> *>,boost::_bi::value<_object *> > & {...},
> boost::_mfi::cmf1<void,boost::python::detail::type_object_base,_object *>
> {...}, boost::_bi::list0 & {...}) line 698
>
boost::_bi::bind_t_generator<void>::implementation<boost::_mfi::cmf1<void,bo
> ost::python::detail::type_object_base,_object
>
*>,boost::_bi::list2<boost::_bi::value<boost::python::detail::type_object_ba
> se *>,boost::_bi::value<_object *> > >::operator()() line 21 + 26 bytes
>
boost::detail::function::void_function_obj_invoker0<boost::_bi::bind_t<void,
> boost::_mfi::cmf1<void,boost::python::detail::type_object_base,_object
>
*>,boost::_bi::list2<boost::_bi::value<boost::python::detail::type_object_ba
> se *>,boost::_bi::value<813e4f84(boost::detail::function::any_pointer
{...})
> line 129
>
boost::function0<void,boost::empty_function_policy,boost::empty_function_mix
> in,int>::operator()() line 302 + 19 bytes
>
boost::python::handle_exception_impl(boost::function0<void,boost::empty_func
> tion_policy,boost::empty_function_mixin,int> {...}) line 21
>
boost::python::handle_exception(boost::_bi::bind_t<void,boost::_mfi::cmf1<vo
> id,boost::python::detail::type_object_base,_object
>
*>,boost::_bi::list2<boost::_bi::value<boost::python::detail::type_object_ba
> se *>,boost::_bi::value<_object *> > > {...}) line 30 + 35 bytes
> do_instance_dealloc(_object * 0x03213ae0) line 182 + 101 bytes
> _Py_Dealloc(_object * 0x03213ae0) line 1820 + 7 bytes
> insertdict(_dictobject * 0x01bc0188, _object * 0x01c9b3c0,
long -724865314,
> _object * 0x1e172aa8 __Py_NoneStruct) line 373 + 59 bytes
> PyDict_SetItem(_object * 0x01bc0188, _object * 0x01c9b3c0, _object *
> 0x1e172aa8 __Py_NoneStruct) line 541 + 21 bytes
> PyObject_GenericSetAttr(_object * 0x01bc00b8, _object * 0x01c9b3c0,
_object
> * 0x1e172aa8 __Py_NoneStruct) line 1335 + 17 bytes
> PyObject_SetAttr(_object * 0x01bc00b8, _object * 0x01c9b3c0, _object *
> 0x1e172aa8 __Py_NoneStruct) line 1153 + 18 bytes
> PyObject_SetAttrString(_object * 0x01bc00b8, char * 0x1e18d0a4, _object *
> 0x1e172aa8 __Py_NoneStruct) line 1078 + 17 bytes
> sys_displayhook(_object * 0x00000000, _object * 0x01bbd1ac) line 90 + 19
> bytes
> PyCFunction_Call(_object * 0x019b4a88, _object * 0x01d0d778, _object *
> 0x00000000) line 90 + 14 bytes
> PyObject_Call(_object * 0x019b4a88, _object * 0x01d0d778, _object *
> 0x00000000) line 1665 + 15 bytes
> PyEval_CallObjectWithKeywords(_object * 0x019b4a88, _object * 0x01d0d778,
> _object * 0x00000000) line 3038 + 17 bytes
> eval_frame(_frame * 0x0320b9d0) line 1330 + 15 bytes
> PyEval_EvalCodeEx(PyCodeObject * 0x032184e8, _object * 0x01bd56d0, _object
*
> 0x01bd56d0, _object * * 0x00000000, int 0, _object * * 0x00000000, int 0,
> _object * * 0x00000000, int 0, _object * 0x00000000) line 2574 + 9 bytes
> PyEval_EvalCode(PyCodeObject * 0x032184e8, _object * 0x01bd56d0, _object *
> 0x01bd56d0) line 488 + 31 bytes
> run_node(_node * 0x03208850, char * 0x1e17d9b0, _object * 0x01bd56d0,
> _object * 0x01bd56d0, PyCompilerFlags * 0x0076e274 struct PyCompilerFlags
> flags) line 1083 + 17 bytes
> run_err_node(_node * 0x03208850, char * 0x1e17d9b0, _object * 0x01bd56d0,
> _object * 0x01bd56d0, PyCompilerFlags * 0x0076e274 struct PyCompilerFlags
> flags) line 1070 + 25 bytes
> PyRun_StringFlags(char * 0x01bf4838, int 256, _object * 0x01bd56d0,
_object
> * 0x01bd56d0, PyCompilerFlags * 0x0076e274 struct PyCompilerFlags  flags)
> line 1041 + 80 bytes
>
>
>
> Stefan Franke
> www.ableton.com
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list