Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
bpo-42100: Add _PyType_GetModuleByDef#22835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -3155,6 +3155,44 @@ PyType_GetModuleState(PyTypeObject *type) | ||||||
return PyModule_GetState(m); | ||||||
} | ||||||
/* Get the module of the first superclass where the module has the | ||||||
* given PyModuleDef. | ||||||
* Implemented by walking the MRO, is relatively slow. | ||||||
* | ||||||
* This is internal API for experimentation within stdlib. Discussion: | ||||||
* https://mail.python.org/archives/list/capi-sig@python.org/thread/T3P2QNLNLBRFHWSKYSTPMVEIL2EEKFJU/ | ||||||
*/ | ||||||
PyObject * | ||||||
_PyType_GetModuleByDef(PyTypeObject *type, struct PyModuleDef *def) | ||||||
{ | ||||||
assert(PyType_Check(type)); | ||||||
assert(type->tp_mro); | ||||||
int i; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||
for (i = 0; i < PyTuple_GET_SIZE(type->tp_mro); i++) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||
PyObject *super = PyTuple_GET_ITEM(type->tp_mro, i); | ||||||
if (!PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) { | ||||||
/* Currently, there's no way for static types to inherit | ||||||
* from heap types, but to allow that possibility, | ||||||
* we `continue` rather than `break`. | ||||||
* We'll just potentially loop a few more times before throwing | ||||||
* the error. | ||||||
*/ | ||||||
continue; | ||||||
} | ||||||
PyHeapTypeObject *ht = (PyHeapTypeObject*)super; | ||||||
if (ht->ht_module && PyModule_GetDef(ht->ht_module) == def) { | ||||||
return ht->ht_module; | ||||||
} | ||||||
} | ||||||
PyErr_Format( | ||||||
PyExc_TypeError, | ||||||
"_PyType_GetModuleByDef: No superclass of '%s' has the given module", | ||||||
type->tp_name); | ||||||
return NULL; | ||||||
} | ||||||
/* Internal API to look for a name through the MRO, bypassing the method cache. | ||||||
This returns a borrowed reference, and might set an exception. | ||||||
'error' is set to: -1: error with exception; 1: error without exception; 0: ok */ | ||||||