[C++-sig] Re: call_method and reference_existing_object results in "Attempt to return dangling pointer..."

David Abrahams dave at boost-consulting.com
Tue Aug 26 13:51:33 CEST 2003

"Evgeny O. Kochenyuk" <evgeny at digitalfun.ru> writes:

> Hello c++-sig,
>   I've got a python class method that wraps a c++ function returning
>   class reference(as "reference_existing_object"). When using
>   call_method on it this error message shown:
> Traceback (most recent call last):
>   File "test_xxx.py", line 6, in ?
>     xxx.call_getValue(T())
> ReferenceError: Attempt to return dangling reference to object of type: struct C
>   Here's the code:
>   (Surely a reference on object such as "static C c" can't be
>   "dangling"?)

It's the enclosing Python object which would be dangling.  This is a
limitation of Boost.Python at the moment.  Please see
http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1781761 and
http://mail.python.org/pipermail/c++-sig/2003-August/005288.html for
a workaround.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list