mirror of
https://github.com/python/cpython.git
synced 2026-05-06 12:49:07 -04:00
gh-148907: fix performance regression in PyType_GetModuleByDef on free-threading (#148908)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user