[issue8212] A tp_dealloc of a subclassed class cannot resurrect an object

Antoine Pitrou report at bugs.python.org
Tue Mar 23 16:25:40 CET 2010


Antoine Pitrou <pitrou at free.fr> added the comment:

Indeed. The io module has had to circumvent this and uses the following snippet when resurrecting an instance of a subclass of one of its types (see iobase_dealloc() in Modules/_io/iobase.c):

        /* When called from a heap type's dealloc, the type will be
           decref'ed on return (see e.g. subtype_dealloc in typeobject.c). */
        if (PyType_HasFeature(Py_TYPE(self), Py_TPFLAGS_HEAPTYPE))
            Py_INCREF(Py_TYPE(self));
        return;


I agree it would be nice to have an automatic way of handling this. I don't see an obvious solution, though.

----------
components: +Interpreter Core
nosy: +benjamin.peterson, pitrou
priority:  -> normal
stage:  -> needs patch
type: crash -> feature request
versions: +Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8212>
_______________________________________


More information about the Python-bugs-list mailing list