STINNER Victor <vstin...@python.org> added the comment:

PyType_GenericAlloc() cannot traverse the object since the object members are 
not initialized yet. For example, dict_traverse() can only be called when 
PyDict_New() completes.

A different approach would be to:

* (1) Add PyType_AllocNoTrack(), use it in built-in types, and call 
_PyObject_GC_TRACK() on the instance once it is fully initialized.
* (2) Modify PyType_GenericAlloc() to use a new variant of _PyObject_GC_TRACK() 
which will not traverse the instance.
* (3) Modify _PyObject_GC_TRACK() to traverse the instance.

In short, PyType_GenericAlloc() cannot be modified for backward compatibility.

Moreover, _PyObject_GC_TRACK() should only be used inside Python internals, 
since it's part the internal C API.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40142>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to