Pablo Galindo Salgado <pablog...@gmail.com> added the comment:

> What would be the downsides of reverting and documenting that tp_traverse 
> must visit Py_TYPE(self)?

Not much IMHO, I actually would prefer this solution over any automatic 
"hacks". The reason is that any hack will be technically violating the 
contract: if I read the tp_traverse of any of these classes I would say "wait a 
minute....this is wrong: the class owns a strong reference to its parent 
so...why is not visiting it?". But the answer would be that we are hacking 
because we didn't want to force users to migrate once we added the strong 
reference.


Notice that the root of this problem was bpo-35810. In that issue we added a 
guide to the docs: 
https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api. In  there it 
says that you should decref now the parent on tp_dealloc:

static void
foo_dealloc(foo_struct *instance) {
    PyObject *type = Py_TYPE(instance);
    PyObject_GC_Del(instance);
#if PY_VERSION_HEX >= 0x03080000
    // This was not needed before Python 3.8 (Python issue 35810)
    Py_DECREF(type);
#endif
}

but it forgot about that you should also visit the parent in tp_traverse.

So, I propose to do the following:

* Revert the hack.
* Fix the tp_traverse of all the relevant classes in the stdlib to correctly 
visit its parent.
* Modify the documentation of master, 3.9 and 3.8 to add the missing 
information: You MUST visit the parent in tp_traverse:

What do you think?

----------

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

Reply via email to