[PyQt] SIP, object destruction, and sip.setdeleted

Phil Thompson phil at riverbankcomputing.com
Wed Apr 30 00:32:42 BST 2008

On Tuesday 29 April 2008, Kevin Watters wrote:
> I've got a couple quick questions about SIP's handling of object
> destruction.
> The docs for sip.setdeleted says
> setdeleted(obj)
>     This marks the C++ instance or C structure as having been destroyed or
> returned to the heap so that future references to it raise an exception
> rather than cause a program crash. Normally SIP handles such things
> automatically, but there are circumstances where this isn't possible. obj
> is the Python object.
> How does SIP handle this situation "automatically?" I don't see anything
> going on in the release_XXX methods in my class wrappers, other than
>     delete reinterpret_cast<XXX *>(ptr);
> Also, some of my classes have a Destroy method whose implementation is to
> just to call
> delete this;
> Without the SIP wrappers defining a virtual destructor of their own, is
> there any way for SIP to recognize that it should mark any existing Python
> instances as "deleted?"

No - it relies on the class being wrapped having a virtual dtor.


More information about the PyQt mailing list