[C++-sig] Wrappend objects identity problem

Victor Nakoryakov nail-mail at mail.ru
Thu Mar 30 12:57:46 CEST 2006


Roman Yakovenko wrote:
> On 3/30/06, Victor Nakoryakov <nail-mail at mail.ru> wrote:
> 
>>Victor Nakoryakov wrote:
> 
> 
> I am not sure whether you can do it with call policies, but what you
> are trying to do is
> described in FAQS
> 
> http://www.boost.org/libs/python/doc/v2/faq.html#xref
> 
> How can I find the existing PyObject that holds a C++ object?
> 
> 
>>Krasnoznamensk, Moscow, Russia
>>
> 
> 
> Hope this will help you.
> 
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/

Thanks for reply. Here is a quote from FAQ:

Another approach to this requires you to change your C++ code a bit; if 
that's an option for you it might be a better way to go. work we've been 
meaning to get to anyway. When a shared_ptr<X> is converted from Python, 
the shared_ptr actually manages a reference to the containing Python 
object. When a shared_ptr<X> is converted back to Python, the library 
checks to see if it's one of those "Python object managers" and if so 
just returns the original Python object. *So you could just write 
object(p) to get the Python object back*. To exploit this you'd have to 
be able to change the C++ code you're wrapping so that it deals with 
shared_ptr instead of raw pointers.

This is suitable approach for me, but phrase marked bold (between **) 
isn't clear for me: where to write "object(p)" and what is 'p' in this 
context?

-- 
Victor (aka nail) Nakoryakov
nail-mail<at>mail<dot>ru

Krasnoznamensk, Moscow, Russia




More information about the Cplusplus-sig mailing list