This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kristjan.jonsson
Recipients kristjan.jonsson
Date 2010-03-23.13:28:29
SpamBayes Score 2.8236238e-07
Marked as misclassified No
Message-id <1269350912.78.0.210466349131.issue8212@psf.upfronthosting.co.za>
In-reply-to
Content
The tp_dealloc of a type can chose to resurrect an object.  the subtype_dealloc() in typeobject.c does this when it calls the tp_del() member and it has increased the refcount.

The problem is, that if you subclass a custom C object, and that C object's tp_dealloc() chooses to resurrect a dying object, that doesn't go well with subtype_dealloc().

After calling basedealloc() (line 1002 in typeobject.c), the object's type is decrefed.  But if the object was resurrected by basedealloc() this shouldn't have been done.  The object will be alive, but the type will be missing a reference.  This will cause a crash later.

This could be fixable if we knew somehow after calling basedealloc() if the object were still alive.  But we cannot check "self" because it may have died.

The only way out of this conundrum that I can see is to change the signature of tp_dealloc() to return a flag, whether it did actually delete the object or not.

Of course, I see no easy way around not clearing the slots, but the clearing of the dict could be postponed until after the call to basedealloc().

Since tp_dealloc _can_ resurrect objects (subtype_dealloc does it), subclassing such objects should work, and not crash the interpreter if the base class' dp_dealloc() decides to do so.
No suggested
History
Date User Action Args
2010-03-23 13:28:33kristjan.jonssonsetrecipients: + kristjan.jonsson
2010-03-23 13:28:32kristjan.jonssonsetmessageid: <1269350912.78.0.210466349131.issue8212@psf.upfronthosting.co.za>
2010-03-23 13:28:30kristjan.jonssonlinkissue8212 messages
2010-03-23 13:28:29kristjan.jonssoncreate