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 vstinner
Recipients nascheme, pablogsal, vstinner
Date 2021-08-12.10:00:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628762441.48.0.238063396437.issue44881@roundup.psfhosted.org>
In-reply-to
Content
The problem of PyObject_GC_UnTrack() is just the most visible effect of the trashcan mecanism: tp_dealloc can be called twice, and this is *not* expected by the tp_dealloc API.

Putting trashcan mecanism outside tp_dealloc can allow to make sure that tp_dealloc is called exactly once. _Py_Dealloc() sounds like a good candidate, but I didn't check if it's the only way to call tp_dealloc. Are there other places where tp_dealloc is called *directly*?

Using military grade regex, I found the following functions calling tp_dealloc:

grep 'dealloc[) ]*([a-zA-Z]\+)' */*.c

* _Py_Dealloc() obviously
* _PyTrash_thread_destroy_chain()
* subtype_dealloc()
* Modules/_testcapimodule.c: check_pyobject_freed_is_freed() <= unit test, it can be ignored

So if we move the trashcan usage inside functions, 3 functions must be modified:

* _Py_Dealloc()
* _PyTrash_thread_destroy_chain()
* subtype_dealloc()
History
Date User Action Args
2021-08-12 10:00:41vstinnersetrecipients: + vstinner, nascheme, pablogsal
2021-08-12 10:00:41vstinnersetmessageid: <1628762441.48.0.238063396437.issue44881@roundup.psfhosted.org>
2021-08-12 10:00:41vstinnerlinkissue44881 messages
2021-08-12 10:00:41vstinnercreate