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

Brian Hall bhall at gamers-fix.com
Mon Jul 26 04:29:09 CEST 2004


Yes it was for nearly the case I posted (somewhat stripped for brevity).
But it was a runtime unhandled exception that was being thrown so I'm sure
if I would have don't the register_ptr_to_python thing it would have worked
out.

-----Original Message-----
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of David Abrahams
Sent: Sunday, July 25, 2004 6:49 PM
To: c++-sig at python.org
Subject: [C++-sig] Re: Shared Pointers and Boost.Python

"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
http://www.boost-consulting.com

_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig






More information about the Cplusplus-sig mailing list