Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove _PyType_GetModuleByDef2() impl
  • Loading branch information
neonene authored Sep 24, 2024
commit a4e712a7827fa7a116d25ade7bc358452e9c5726
33 changes: 5 additions & 28 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5207,8 +5207,8 @@ PyType_GetModuleState(PyTypeObject *type)
/* Get the module of the first superclass where the module has the
* given PyModuleDef.
*/
static inline PyObject *
get_module_by_def(PyTypeObject *type, PyModuleDef *def)
PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
{
assert(PyType_Check(type));

Expand Down Expand Up @@ -5241,7 +5241,7 @@ get_module_by_def(PyTypeObject *type, PyModuleDef *def)
Py_ssize_t n = PyTuple_GET_SIZE(mro);
for (Py_ssize_t i = 1; i < n; i++) {
PyObject *super = PyTuple_GET_ITEM(mro, i);
if(!_PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) {
if (!_PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) {
// Static types in the MRO need to be skipped
continue;
}
Expand All @@ -5254,37 +5254,14 @@ get_module_by_def(PyTypeObject *type, PyModuleDef *def)
}
}
END_TYPE_LOCK();
return res;
}

PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
{
PyObject *module = get_module_by_def(type, def);
if (module == NULL) {
if (res == NULL) {
PyErr_Format(
PyExc_TypeError,
"PyType_GetModuleByDef: No superclass of '%s' has the given module",
type->tp_name);
}
return module;
}

PyObject *
_PyType_GetModuleByDef2(PyTypeObject *left, PyTypeObject *right,
PyModuleDef *def)
{
PyObject *module = get_module_by_def(left, def);
if (module == NULL) {
module = get_module_by_def(right, def);
if (module == NULL) {
PyErr_Format(
PyExc_TypeError,
"PyType_GetModuleByDef: No superclass of '%s' nor '%s' has "
"the given module", left->tp_name, right->tp_name);
}
}
return module;
return res;
}


Expand Down