[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

@ -7050,18 +7050,7 @@ static PyObject *
object___reduce_ex___impl(PyObject *self, int protocol)
/*[clinic end generated code: output=2e157766f6b50094 input=f326b43fb8a4c5ff]*/
{
#define objreduce \
(_Py_INTERP_CACHED_OBJECT(_PyInterpreterState_GET(), objreduce))
PyObject *reduce, *res;
if (objreduce == NULL) {
PyObject *dict = lookup_tp_dict(&PyBaseObject_Type);
objreduce = PyDict_GetItemWithError(dict, &_Py_ID(__reduce__));
if (objreduce == NULL && PyErr_Occurred()) {
return NULL;
}
}
PyObject *reduce;
if (PyObject_GetOptionalAttr(self, &_Py_ID(__reduce__), &reduce) < 0) {
return NULL;
}
@ -7075,10 +7064,12 @@ object___reduce_ex___impl(PyObject *self, int protocol)
Py_DECREF(reduce);
return NULL;
}
override = (clsreduce != objreduce);
PyInterpreterState *interp = _PyInterpreterState_GET();
override = (clsreduce != _Py_INTERP_CACHED_OBJECT(interp, objreduce));
Py_DECREF(clsreduce);
if (override) {
res = _PyObject_CallNoArgs(reduce);
PyObject *res = _PyObject_CallNoArgs(reduce);
Py_DECREF(reduce);
return res;
}
@ -7087,7 +7078,6 @@ object___reduce_ex___impl(PyObject *self, int protocol)
}
return _common_reduce(self, protocol);
#undef objreduce
}
static PyObject *