bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType_FromSpec types#19414
bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType_FromSpec types#19414vstinner merged 1 commit into
Conversation
ea96f0b to
88f807c
Compare
April 7, 2020 20:25
|
Before this PR: With this PR: |
Sorry, something went wrong.
353f682 to
ab1ca32
Compare
April 7, 2020 21:58
|
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit ab1ca32 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
vstinner
left a comment
There was a problem hiding this comment.
LGTM, but I have a few minor remarks.
Sorry, something went wrong.
|
@pablogsal: I added "skip news" to be able to merge your PR, but IMHO it's worth it to add a NEWS entry for it (I suggest the C API category). Would you mind to add one? |
Sorry, something went wrong.
Will do but I didn't had time to add your suggestions for this PR before you merged it. Should I add this in the future PR? |
Sorry, something went wrong.
Yeah. |
Sorry, something went wrong.
…r PyType_FromSpec types (pythonGH-19414)" This reverts commit 0169d30.
https://bugs.python.org/issue40217
Types created by PyType_FromSpec own a strong reference to their type, but this was added in Python 3.8. The tp_traverse function needs to call Py_VISIT on the type but all existing traverse functions cannot be updated (especially the ones from existing user functions) so we need to provide a tp_traverse that manually calls Py_VISIT(Py_TYPE(self)) and then call the provided tp_traverse. In this way, user functions do not need to be updated, preserve backwards compatibility.
To do this, we store the user-provided traverse function at the end of the type (we need to allocate space for it) so we can call it from our PyType_FromSpec_tp_traverse wrapper.