bpo-44881: Integrate GC untrack into trashcan begin. by nascheme · Pull Request #27718 · python/cpython

@nascheme

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.

pablogsal

@nascheme

It seems slightly cleaner to have the BEGIN/END macros at the start and
end of the dealloc function body.

vstinner

@ambv