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

Kristján Valur Jónsson report at bugs.python.org
Mon Apr 16 23:36:05 CEST 2012


Kristján Valur Jónsson <kristjan at ccpgames.com> added the comment:

Incidentally, Looking at this, I noticed code such as: (textio.c)

static int
_textiowrapper_clear(textio *self)
{
    if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
        return -1;

This shows something scary:  During a GC run, it is possible to invoke the  "close()" method on a textio object.  This is dangerous, and probably not allowed at all.
Returning -1 from a tp_clear() slot has no particular meaning, and the return value appears to be ignored by gcmodule.c (also, it won't ever ber resurrected through that pathway, since it is incref'd first:
    Py_INCREF(op);
    clear(op);
    Py_DECREF(op);
)

See Issue 9141 for more info.
IMHO, this is another case where objects must tell GC that they cannot be collected but instead must be placed in gc.garbage.

This probably requires a defect of its own.

----------

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


More information about the Python-bugs-list mailing list