[C++-sig] Trying to clone (again)
David Abrahams
dave at boost-consulting.com
Wed Aug 3 17:01:41 CEST 2005
"Paul F. Kunz" <Paul_Kunz at slac.stanford.edu> writes:
>>>>>> On Tue, 02 Aug 2005 23:39:50 -0400, David Abrahams <dave at boost-consulting.com> said:
>
>
>> The result of invoking an override is not meant to be used this way,
>> but you might be able to force it by doing:
>
>> py_result = boost::implicit_cast<object>(clone());
>
> Tried that and didn't get an error at runtime. However, the very
> next call to the object
>
> unsigned int
> FunctionWrap::
> dimensions () const
> {
> unsigned int dims = 0;
>
> if ( override member = this -> get_override ( "dimensions" ) ) {
> dims = member();
> }
> else { // didn't override it
> dims = FunctionBase::dimensions ();
> }
> return dims;
> }
>
> leads to
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread -1222050896 (LWP 14423)]
> PyErr_Restore (type=0xb75a671c, value=0xb74827b8, traceback=0x0)
> at Python/errors.c:33
> (gdb) up
> #1 0x080ceb80 in PyErr_Format (exception=0xb75a671c,
> format=0xb75a671c "\006") at Python/errors.c:51
> (gdb)
> #2 0x0807f3a0 in PyObject_GenericGetAttr (obj=0xb756c464, name=0xb7532cc8)
> at Objects/object.c:1303
> (gdb)
> #3 0x0807ec79 in PyObject_GetAttrString (v=0xb756c464,
> name=0x7d1ae5 "dimensions") at Objects/object.c:1016
> (gdb)
> #4 0x009ebcf9 in boost::python::detail::wrapper_base::get_override ()
> from /usr/local/lib/libboost_python-gcc-1_32.so.1.32.0
> (gdb)
> #5 0x00736447 in FunctionWrap::dimensions (this=0x94c7f40)
> at /usr/local/include/boost-1_32/boost/python/wrapper.hpp:29
> Current language: auto; currently c++
> (gdb)
I'm pretty sure that's an unrelated problem, and something you did is
corrupting memory somewhere.
> The object does *not* have "dimension" member function.
That's not relevant.
> If I give it one, I get the same error. By the way, the rest of the
> code in the clone() method of FunctionWrap executed without errors,
> namely
>
> FunctionWrap* result = extract<FunctionWrap*>(py_result);
>
> // Make the C++ result control the destiny of the Python result.
> result->invert_ownership = py_result;
> PyGILState_Release ( state );
I"m not sure about this invert_ownership business. Are you sure
you're not allowing your Python object to be destroyed prematurely?
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list