[PyQt] Smartpointer to Python

Arve Knudsen arve.knudsen at gmail.com
Tue May 27 12:21:10 BST 2008


On Mon, May 26, 2008 at 11:32 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Monday 26 May 2008 9:34:00 pm Arve Knudsen wrote:
>> On 5/26/08, Phil Thompson <phil at riverbankcomputing.com> wrote:
>> > On Monday 26 May 2008 2:10:53 pm Arve Knudsen wrote:
>> >  > On Mon, May 26, 2008 at 2:37 PM, Phil Thompson
>> >  >
>> >  > <phil at riverbankcomputing.com> wrote:
>> >  > > On Monday 26 May 2008 1:10:11 pm Arve Knudsen wrote:
>> >  > >> Hi
>> >  > >>
>> >  > >> Reading the SIP documentation I can't find any info on how C++
>> >  > >> objects are deleted (returned to the heap) from Python, only that
>> >  > >> their destructor is called.
>> >  > >
>> >  > > ...when the Python object is garbage collected and if the C++ object
>> >  > > is owned by Python.
>> >  >
>> >  > Yes, that much is clear.
>> >  >
>> >  > >> Does this mean that when returning new'ed
>> >  > >> pointers  to Python they should be managed by smartpointers? If so,
>> >  > >> is there any mechanism in SIP for treating smartpointers as objects
>> >  > >> of their managed type from Python?
>> >  > >
>> >  > > SIP effectively implements its own smartpointer mechanism - so long
>> >  > > as the C++ type has a virtual dtor and the C++ object is created
>> >  > > from Python.
>> >  >
>> >  > Could the SIP documentation be more clear about this? I can only see
>> >  > that it says that pointers to C structs will be free'ed, and that C++
>> >  > objects are destroyed. I need to make sure that C++ objects are
>> >  > deleted, not just destroyed.
>> >
>> > ...err, what's the difference?
>>
>> Can you define "destroying" a C++ object as deleting it? When you say
>> destroy, I think of invoking its destructor. A destroyed object isn't
>> necessarily freed, and it's not immediately obvious how to free a
>> heap-allocated object in C++ (depends on how it's allocated).
>
> Stroustrup talks of objects being "destroyed by delete". As far as SIP is
> concerned they are synonymous.

Sure, delete implies that an object be destroyed, but destruction does
not imply deletion. Look at the first link resulting from googling
"c++ destroy object":
http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=/com.ibm.xlcpp8l.doc/language/ref/cplr380.htm.
Destroying an object is defined as having its destructor invoked.

You may not agree with me, but your documentation *will* leave things
to be desired, from its audience's perspective, since it doesn't
completely define at least SIP's handling of object ownership.

Arve


More information about the PyQt mailing list