[C++-sig] custom smart pointers

Roman Yakovenko roman.yakovenko at gmail.com
Sat Sep 9 22:29:32 CEST 2006


On 9/6/06, Alex Mohr <amohr at pixar.com> wrote:
> > I don't know and understand how I should do it, really :-(.
> >
> > Boost.Python creates new instance of shared_ptr with custom deleter. This way it
> > says to shared_ptr that the object is already managed.
>
> I believe it's just a hack to do what I call "object identity" -- which
> is just tracking the association between a C++ instance and a python
> object.  When converting a shared ptr to-python, boost python checks to
> see if it has its special deleter, and will use that to produce the
> python object rather than constructing a new one.
>
> This is a fragile scheme.  It fails frequently for shared ptrs, as has
> been discussed on this list before, and it doesn't work at all for
> custom shared pointers.
>
> Anyway, I consider object identity to be a different issue from the one
> we're currently discussing.  But I do think you should address it in
> py++.  We can talk about that later.

I am not completely understand what you are talking about ( object identity ).
I will be glad to discuss it with you and add the appropriate functionality
to Py++, really.

> > The smart pointer, the project use, does not provide this
> > functionality. More over,
> > I don't understand what data->convertible will contain.
>
> If I recall correctly (I'm not looking at the code) data->convertible is
> the result that the convertible method returned, so in this case it's a
> raw pointer to the C++ instance.
>
> > I think I do it:
> >
> > register_ptr_to_python< my_smart_ptr_t< base > >();
> > register_ptr_to_python< my_smart_ptr_t< derived > >();
> > implicitly_convertible< my_smart_ptr_t< derived >, my_smart_ptr_t< base > >();
> >
> > This is what yoy mean, right?
>
> No, these are to-python conversions.  I'm talking about rvalue
> from-python conversions.  Have a look at the last few messages in the
> concurrent thread on this list with subject "Is there a way to
> automatically convert a smart_ptr to a held_type (try 2)".
>
> I posted a message to that thread which has some (untested) smart
> pointer rvalue from-python conversion code in it.  Actually -- it
> probably looks something like shared_ptr_from_python.

I read the thread "Is there a way to automatically convert a smart_ptr
to a held_type (try 2)" and still I am not able to get to a solution
:-(. I have to say that
I am lost.  I implemented rvalue converter,  I am registering custom
to_python_converter - nothing happens.

I attach the minimal example. Any help is welcome.

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: classes.hpp
Type: text/x-c++hdr
Size: 1617 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060909/746d8bfb/attachment.hpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: expose_classes.cpp
Type: text/x-c++src
Size: 4825 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060909/746d8bfb/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smart_ptr.h
Type: text/x-chdr
Size: 1843 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060909/746d8bfb/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 240 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060909/746d8bfb/attachment.py>


More information about the Cplusplus-sig mailing list