gh-148907: fix performance regression in PyType_GetModuleByDef on free-threading (#148908)

This commit is contained in:
Kumar Aditya
2026-04-23 16:42:57 +05:30
committed by GitHub
parent ab41a347eb
commit 29917d51ab
+7 -9
View File
@@ -5878,7 +5878,13 @@ PyType_GetModuleByToken_DuringGC(PyTypeObject *type, const void *token)
PyObject *
PyType_GetModuleByToken(PyTypeObject *type, const void *token)
{
PyObject *mod = PyType_GetModuleByToken_DuringGC(type, token);
return Py_XNewRef(PyType_GetModuleByDef(type, (PyModuleDef *)token));
}
PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
{
PyObject *mod = PyType_GetModuleByToken_DuringGC(type, def);
if (!mod) {
PyErr_Format(
PyExc_TypeError,
@@ -5886,14 +5892,6 @@ PyType_GetModuleByToken(PyTypeObject *type, const void *token)
type->tp_name);
return NULL;
}
return Py_NewRef(mod);
}
PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
{
PyObject *mod = PyType_GetModuleByToken(type, def);
Py_XDECREF(mod); // return borrowed ref
return mod;
}