[C++-sig] Passing objects between python / c++

Roman Yakovenko roman.yakovenko at gmail.com
Wed Oct 25 23:54:18 CEST 2006


On 10/25/06, Mark Williams <mark at image-engine.com> wrote:
>
>
>
>  On Tue Oct 24 23:11 , "Roman Yakovenko"  sent:
>
> >On 10/25/06, Mark Williams mark at image-engine.com> wrote:
> >>
> >> >I think you are wrong. Remove from example derived class, make base class to
> >> >be constructable( no pure virtual function ) and replace smart_ptr_t with
> >> >intrusive_ptr. I think this will work.
> >> >
> >>
> >> Below is what I've tried, following your suggestion. The original tests pass, but the one I added to test passing an instance of the class through C++ fails :
> >>
> >>   File "test.py", line 44, in test_object_passing
> >>     self.assert_( c is d )
> >>
> >> This assert definitely passes if shared_ptr is used in place of intrusive_ptr.
> >
> >I think this is "an identity problem". Search for it in the mailing
> >list. Also c and expose
> >same object they are different Python objects.
> >
> >Am I right?
> >
>
> You are right - it is an identity problem. However, before posting my original question I had  already been through the lists to see if there was an existing solution. The threads I've found on the subject - the most notable of which appears to be http://mail.python.org/pipermail/c++-sig/2006-March/010458.html - seem
> to tail off without a conclusion being made. I see that internally boost.python contains many references to shared_ptr, and I have confirmed through a number of tests that the identity problem appears to be solved if shared_ptrs are employed, unfortunately I'm in a position where I cannot change the C++ I'm
> binding to use a different smart pointer type.
>
> Is there anything else I might try, or is this unfixable?

I don't have enough knowledge to answer the question.
It seems to me that you can create small work around:
redefine store and retrieve function in Python, save the reference to the python
object somewhere, next time user will ask to retrieve the object, you can return
the object you stored earlier in Python.


-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list