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

Mark Williams mark at image-engine.com
Wed Oct 25 19:36:33 CEST 2006




 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?

Thanks again,

Mark



More information about the Cplusplus-sig mailing list