◐ Shell
clean mode source ↗

bpo-44263: Py_TPFLAGS_HAVE_GC requires tp_traverse by vstinner · Pull Request #26463 · python/cpython

This change breaks C extensions which define types with Py_TPFLAGS_HAVE_GC but without tp_traverse, even if instances of the type are never tracked by the GC. Such extensions worked properly previously.

Maybe the check could be restricted to heap types?

If we don't want to break the backward compatibility, we should check in PyObject_GC_Track() if type->tp_traverse is not NULL.

Many instances are created by PyType_GenericAlloc() which calls _PyObject_GC_TRACK(). I tried to modify _PyObject_GC_TRACK() to ensure that it's possible to traverse the instance, as I did in PyObject_GC_Track(), but I got a lot of issues. Many types call _PyObject_GC_TRACK() too early, and it's really difficult to change that (it would require a lot of work).

cc @pablogsal @erlend-aasland @corona10