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

2020-06-25 Thread STINNER Victor
STINNER Victor added the comment: > I think PEP 442 makes this request obsolete: you can simply implement > tp_finalize() and incref the object naturally from there. Right. I close the issue. -- nosy: +vstinner resolution: -> fixed stage: needs patch -> resolved status: open -> clos

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

2014-09-26 Thread Antoine Pitrou
Antoine Pitrou added the comment: I think PEP 442 makes this request obsolete: you can simply implement tp_finalize() and incref the object naturally from there. Kristjan, what do you think? -- ___ Python tracker

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

2012-04-16 Thread Kristján Valur Jónsson
Kristján Valur Jónsson added the comment: Here is a patch with the suggested change. I put _PyObject_ResurrectFromDealloc into typeobject.c since it seems more at home there than in object.c, but I'm not sure. Also note that other types, that were calling _PyIOBase_finalize() from their tp_dea

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

2012-04-16 Thread Kristján Valur Jónsson
Kristján Valur Jónsson added the comment: __del__ methods are never invoked from GC. All objects that have finalizers, and all objects reachable from them _must_ be put in gc.garbage. If I'm not mistaken, this is a fundamental rule of python's gc module and it is not because of the unknown or

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

2012-04-16 Thread Antoine Pitrou
Antoine Pitrou added the comment: > 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. T

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

2012-04-16 Thread Kristján Valur Jónsson
Kristján Valur Jónsson 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 poss

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

2012-04-16 Thread Antoine Pitrou
Antoine Pitrou added the comment: > Ok, that sounds reasonable, particularly in light of that > _NewReference stuff. I'll work out a different patch then. But I > think the API must be public, since it would need to work from > extension modules. Needing to work from (stdlib) extension module

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

2012-04-16 Thread Kristján Valur Jónsson
Kristján Valur Jónsson added the comment: Ok, that sounds reasonable, particularly in light of that _NewReference stuff. I'll work out a different patch then. But I think the API must be public, since it would need to work from extension modules. So: if a c type decides that it wants to liv

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

2012-04-16 Thread Antoine Pitrou
Antoine Pitrou added the comment: Urg, that's a horrible hack. How about instead having an API function to resurrect an object from a tp_dealloc? That way the iobase_dealloc code would be written: if (_PyIOBase_finalize((PyObject *) self) < 0) { _PyObject_ResurrectFromDealloc(self

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

2012-04-16 Thread Kristján Valur Jónsson
Kristján Valur Jónsson added the comment: Updated the patch with better documentation, and recursion safety. -- Added file: http://bugs.python.org/file25236/basedealloc.diff ___ Python tracker _

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

2012-04-15 Thread Meador Inge
Changes by Meador Inge : -- nosy: +meador.inge ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pytho

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

2012-04-15 Thread Kristján Valur Jónsson
Kristján Valur Jónsson added the comment: Another, less hacky but more intrusive, way would be to change the signature of tp_dealloc in a backwards compatible way: typedef void (*destructor)(PyObject *, int *destroyed); The destructor can then set the flag pointed to by 'destroyed' to 1 or 0,

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

2012-04-15 Thread Kristján Valur Jónsson
Kristján Valur Jónsson added the comment: Here is a patch that rectifies this situation, albeit in a somewhat 'hacky' manner. It works by injecting a monitoring 'tp_free' call into the type during the basedealloc call, which sets a flag if it was called with the object, i.e. if actual deletio

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

2010-08-09 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- versions: -Python 2.7 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mai

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

2010-03-23 Thread Antoine Pitrou
Antoine Pitrou 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

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

2010-03-23 Thread Kristján Valur Jónsson
New submission from Kristján Valur Jónsson : 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 objec