bpo-44881: Integrate GC untrack into trashcan begin. by nascheme · Pull Request #27718 · python/cpython
For subtle reasons, PyObject_GC_UnTrack() function must be called before Py_TRASHCAN_BEGIN(). There have been a number of bugs over the years related to not doing this particular dance just right. Integrating the PyObject_GC_UnTrack() call makes it harder to do things incorrectly. That avoids some hard to find bugs (e.g. only triggered when object nesting gets deep enough). Extensions that still call PyObject_GC_UnTrack() explictly will still work correctly but the call is unneeded after this change. It would still be needed for the extension to work correctly with older versions of Python.
It seems slightly cleaner to have the BEGIN/END macros at the start and end of the dealloc function body.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters