[C++-sig] Python __init__ that copies internal reference, boost.python

Jim Bosch talljimbo at gmail.com
Tue Aug 17 02:08:33 CEST 2010


On 08/16/2010 04:21 PM, Branan Purvine-Riley wrote:
>
> That's definitely on the right track. Not quite right because of some of the
> oddities of what I'm working with here. It's a game engine, and none of the
> pointers are stored in a smart pointer container of any kind. Unfortunately
> make_constructor will convert a raw ptr to an std::auto_ptr, which deletes the
> object somewhere in boost code.
>

Glad to see you've got something that works.  Don't dismiss the 
shared_ptr version automatically, though; Boost.Python can construct a 
shared_ptr for a wrapped C++ object held inside a Python object even if 
it wasn't wrapped using shared_ptr - it uses a shared_ptr deleter that 
owns a Python reference.

Of course, if there's no concern about whether the C++ object will get 
destroyed while the second Python object that refers to it is still 
alive, then your solution is just fine.


Jim


More information about the Cplusplus-sig mailing list