[3.13] gh-125221: Fix free-threading data race in object.__reduce_ex__ (GH-125267) (#125305)

gh-125221: Fix free-threading data race in `object.__reduce_ex__` (GH-125267)
(cherry picked from commit b12e99261e)

Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-10-11 10:26:23 +02:00 committed by GitHub
parent 49f171d9ea
commit b3badabcd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 15 deletions

View file

@ -2353,6 +2353,14 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
}
}
// Cache __reduce__ from PyBaseObject_Type object
PyObject *baseobj_dict = _PyType_GetDict(&PyBaseObject_Type);
PyObject *baseobj_reduce = PyDict_GetItemWithError(baseobj_dict, &_Py_ID(__reduce__));
if (baseobj_reduce == NULL && PyErr_Occurred()) {
return _PyStatus_ERR("Can't get __reduce__ from base object");
}
_Py_INTERP_CACHED_OBJECT(interp, objreduce) = baseobj_reduce;
// Must be after static types are initialized
if (_Py_initialize_generic(interp) < 0) {
return _PyStatus_ERR("Can't initialize generic types");