[C++-sig] Re: Shared Pointers and Boost.Python

David Abrahams dave at boost-consulting.com
Mon Jul 26 02:48:54 CEST 2004

"Brian Hall" <bhall at gamers-fix.com> writes:

> Actually, everything he did was fine.  Wrapping classes with
> shared_ptr is almost completely pointless now, since any Python object
> holding an X object can be converted to a shared_ptr<X>.  The
> shared_ptr has a custom deleter that manages the owning Python object's
> lifetime.
> You might want to use register_ptr_to_python<shared_ptr<X> >() for
> some shared pointers if you ever create them from C++ code, but in
> this case it never happens so they can all be automatically converted
> back into Python objects by (we just extract the owning Python object
> from the deleter).
> -----
> Actually before I tried putting the shared_ptr<> declaration in the class_
> exposure, the application would crash in some code having to do with the
> custom deleter.  

Details, please!  Was this for the precise test case you posted
(without the shared_ptr in the class_) or was it for some other code?

> It also was saying something about being unable to make a to_python
> coverter.

I'm pretty sure the message was that it was unable to *find* one (a
runtime message, right?)  That's why you use register_ptr_to_python.
That would only happen when calling a wrapped function returning a
shared_ptr that wasn't created from Python.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list