bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType_FromSpec types (reverts GH-19414)#20264
Conversation
|
Would it be possible to prepare a PR to explain how to fix the issue? Also, is there someone interested to fix all C extensions of CPython stdlib for this issue? |
Sorry, something went wrong.
I can do both if we end agreeing that that is the way to go |
Sorry, something went wrong.
…r PyType_FromSpec types (pythonGH-19414)" This reverts commit 0169d30.
encukou
left a comment
There was a problem hiding this comment.
Are the type->tp_traverse == (traverseproc)foo_traverse checks (and the but not for subclasses remarks) necessary? AFAIK, the check will always be true for calls that Python itself makes.
It might necessary to do the check in the reproducer I posted on the bug, but only because that module's own call to base_traverse.
But it might be that I'm misunderstanding the situation.
Sorry, something went wrong.
|
Never mind; I'm wrong about that. Sorry. |
Sorry, something went wrong.
|
I'll try going with the idea that each instance of a heap type must Py_VISIT its class, and if it calls another heap type's |
Sorry, something went wrong.
|
@encukou Could you elaborate a bit more the idea you are proposing? I would love to eliminate the checks for subclasses bit sadly the subclass traverse is already visiting the type itself when traversing the hierarchy. |
Sorry, something went wrong.
If the base is a heap type, the responsibility to visit Py_TYPE(self) is delegated to the base's tp_traverse.
|
The Python 3.8 behavior is buggy. If a custom I don't like the "Ensure that all custom So, I'd like to acknowledge that Python 3.8 has the bug, set up a cleaner rule on what I'll make a PR out of that shortly. |
Sorry, something went wrong.
|
Gotcha! I very much agree with your analysis. Do you plant to backport this? Feel free to push to this PR of you wish |
Sorry, something went wrong.
|
I don't think it's worth it to backport, unfortunately. Not visiting IMO, it is more important to be consistent across 3.8.x than to avoid the leak. If backported to 3.8.4, we get an unfortunate case:
|
Sorry, something went wrong.
|
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, something went wrong.
|
Correction: I do want to backport to 3.9. That's probably what you were asking about, right? |
Sorry, something went wrong.
Heap types now always visit the type in tp_traverse. See added docs for details.
This reverts commit 0169d30.
https://bugs.python.org/issue40217
Automerge-Triggered-By: @encukou