[C++-sig] Wrappend objects identity problem
Victor Nakoryakov
nail-mail at mail.ru
Thu Mar 30 14:38:47 CEST 2006
Victor Nakoryakov wrote:
> Ok, I think my previous post was too complicated, here is simplified
> version:
>
>
>>class A
>>{
>>};
>>
>>boost::shared_ptr<A> ptr;
>>boost::shared_ptr<A> getA()
>>{
>> if (!ptr)
>> ptr = boost::shared_ptr<A>(new A);
>>
>> return ptr;
>>}
>>
>>void Init()
>>{
>> python::class_< A, boost::shared_ptr<A>, boost::noncopyable >( "AClass", python::no_init );
>> python::def("getA", &getA);
>>}
>
>
> And py code is:
>
>
>>a1 = getA()
>>a2 = getA()
>>l = [a1, a2]
>>print a1
>>print a2
>>print getA() in l
>>print a1 is a2
>>print a1 == a2
>
>
> Output is:
>
> <_mymodule.AClass object at 0x017DB070>
> <_mymodule.AClass object at 0x017DB0B0> <- another address!
> False
> False
> False
>
> The question is the same: What I have to do to have the same address of
> AClass every time I call getA() from python.
>
> I can't find solution already for 3 days. Have anyone ideas?
>
Ok... The question is simplified. Who knows a chain that converts
HeldType (boost::shared_ptr<A> in this case) to PyObject* ? And where I
can done any overloads or specializations to force c++ to return the
same PyObject* for the same raw pointer to A instance?
I don't know is it question simplification, or vice versa, but anyway
I'm in great need of an answer.
--
Victor (aka nail) Nakoryakov
nail-mail<at>mail<dot>ru
Krasnoznamensk, Moscow, Russia
More information about the Cplusplus-sig
mailing list