[C++-sig] Best way to register shared_ptr<const T>
Roman Yakovenko
roman.yakovenko at gmail.com
Fri Jan 25 11:25:09 CET 2008
On Jan 25, 2008 12:00 AM, Alex Mohr <amohr at pixar.com> wrote:
> > It looks you know a lot about it... would you be able to help me on the other issue I posted recently:
> > http://mail.python.org/pipermail/c++-sig/2008-January/013254.html
> >
> > somehow boost::python is able to tell when 2 different instances of a boost::shared_ptr<> point to
> > the same C++ object.
> >
> > This is not the case for custom smart pointers.
> >
> > I'm happy to investigate, but I could not find where to start. Do you know how it works?
>
> Boost.python has special-case code for shared_ptr. When boost.python
> creates a shared_ptr for a class, it supplies a special custom deleter
> that tracks the python object identified with the c++ object.
>
> When a shared_ptr is converted to_python, boost.python checks to see if
> it has its special deleter, and if so, it can get the existing python
> object from it. That's how "object identity" is maintained for shared_ptr.
>
> It is possible to make object identity work for custom smart pointers,
> but it is hard. What we're doing is totally gross. After a class_<> is
> registered with boost.python, I manually replace the to_python
> converter that boost.python registered with my own that wraps it but
> also does custom object-identity mapping. This requires digging into
> the conversion registry using private api, and doing nasty stuff, but
> you *can* make it work.
Can you post some complete example?
Thank you
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list