From: Kumar Aditya Date: Thu, 23 Apr 2026 11:12:57 +0000 (+0530) Subject: gh-148907: fix performance regression in `PyType_GetModuleByDef` on free-threading... X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=29917d51ab41df9a00f1bb35fa9d3e1392ac48e8;p=thirdparty%2FPython%2Fcpython.git gh-148907: fix performance regression in `PyType_GetModuleByDef` on free-threading (#148908) --- diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 08b95cfbc6ce..fb3c71014106 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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; }