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 Christian.Tismer
Recipients Christian.Tismer, Dormouse759, docs@python, loewis, nascheme, ncoghlan, petr.viktorin, serhiy.storchaka
Date 2018-10-26.14:37:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1540564637.28.0.788709270274.issue26979@psf.upfronthosting.co.za>
In-reply-to
Content
The default of PyType_FromSpec for tp_dealloc is wrong!
-------------------------------------------------------

After a long struggle with crashes and leaks, the situation
was finally clarified:

When a type is converted from a static type to a heaptype
via PyType_FromSpec, and the tp_dealloc field is NULL,
then subtype_dealloc is inserted.

This is not correct.
The reasoning in the code is that a heaptype has subtype_dealloc.
But before the conversion, the type was static, and for
static types the function object_dealloc was inserted.

In the given type, the only change is to become a heaptype.
The by default inserted object_dealloc should not be changed,
since the existing code was written with object_dealloc in 
mind and not the consequences of replacing it with subtype_dealloc.

Before this solution, I used a dummy function to prevend
subpype_dealloc being inserted, but that caused leaks.

It was hard to understand that the default for a static type
is object_dealloc. After that, it was easy to fix that:

The now correctly working workaround is to explicitly insert
an object_dealloc function whenever the default for tp_dealloc
is NULL.

Again, in order to use this fix, it is necessary to break the
Limited API, because in order to write an object_dealloc function
(it is not public) you need access to type objects.
History
Date User Action Args
2018-10-26 14:37:17Christian.Tismersetrecipients: + Christian.Tismer, loewis, nascheme, ncoghlan, petr.viktorin, docs@python, serhiy.storchaka, Dormouse759
2018-10-26 14:37:17Christian.Tismersetmessageid: <1540564637.28.0.788709270274.issue26979@psf.upfronthosting.co.za>
2018-10-26 14:37:17Christian.Tismerlinkissue26979 messages
2018-10-26 14:37:17Christian.Tismercreate