[C++-sig] Incrementing reference count of returned object pointer
David Abrahams
dave at boost-consulting.com
Sat Nov 23 21:17:40 CET 2002
Patrick Hartling <patrick at vrac.iastate.edu> writes:
> Patrick Hartling wrote:
>
>> Base* obj = boost::python::call<Base*>(factory_func);
>
> Okay, I think I got this worked out. Instead of the above, I am doing
> the following (assuming namespace python = boost::python):
>
> python::object base_obj = python::call<python::object>(factory_func);
> Base* obj = python::extract<Base*>(base_obj);
>
> This seems to do the trick. Is there anything fundamentally wrong
> with this?
Nothing fundamental. Of course if you were getting the dangling
reference exception when using call<Base*>, it's an indication that
base_obj (or a copy) must survive at least as long as obj does, or it
will be dangling again (and I can't protect you from that by throwing
a nice exception ;->).
-Dave
--
David Abrahams
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig
mailing list