Repository navigation
[3.14] gh-160840: In PyType_GetModuleByDef, fall back to tp_bases if tp_mro is gone (GH-162160) - #162874
Open
encukou wants to merge 2 commits into
Open
[3.14] gh-160840: In PyType_GetModuleByDef, fall back to tp_bases if tp_mro is gone (GH-162160)#162874encukou wants to merge 2 commits into
encukou wants to merge 2 commits into
Conversation
…p_mro is gone (pythonGH-162160) `PyType_GetModuleByDef` asserted that a type's `mro` is not NULL, but this can happen when cleaning a GC cycle. If it does, we can still fall back to walking `tp_bases`. (cherry picked from commit 4499a94. This backport changes only `PyType_GetModuleByDef`, while in 3.15+, `*ByDef` is implemented on top of the new `PyType_GetModuleByToken`, which the original commit changes too.)
Member
Author
|
@da-woods The backport is not entirely trivial so I'd appreciate a quick check from a different pair of eyes. |
`PyModuleDef` is a typedef for `struct PyModuleDef`, but only one is recognized by the tool.
da-woods
reviewed
Nov 30, 2026
| PyObject *module = ((PyHeapTypeObject*)base)->ht_module; | ||
| if (module && _PyModule_GetDef(module) == def) { | ||
| return module; | ||
| break; |
Contributor
There was a problem hiding this comment.
I'm not sure this is the most useful break ever. But it isn't doing any harm and it's in the original
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyType_GetModuleByDefasserted that a type'smrois not NULL, but this can happen when cleaning a GC cycle. If it does, we can still fall back to walkingtp_bases.(cherry picked from commit 4499a94. This backport changes only
PyType_GetModuleByDef, while in 3.15+,*ByDefis implemented on top of the newPyType_GetModuleByToken, which the original commit changes too.)PyType_GetModuleByDefisn't safe to call intp_dealloc#160840