diff options
author | Sam Gross <colesbury@gmail.com> | 2024-10-11 07:56:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-11 07:56:01 (GMT) |
commit | b12e99261e656585ffbaa395af7c5dbaee5ad1ad (patch) | |
tree | 2c8f481edb4e08dbe51733abdfa59b3ae9febf07 /Objects/typeobject.c | |
parent | c1913effeed4e4da4d5310a40ab518945001ffba (diff) | |
download | cpython-b12e99261e656585ffbaa395af7c5dbaee5ad1ad.zip cpython-b12e99261e656585ffbaa395af7c5dbaee5ad1ad.tar.gz cpython-b12e99261e656585ffbaa395af7c5dbaee5ad1ad.tar.bz2 |
gh-125221: Fix free-threading data race in `object.__reduce_ex__` (#125267)
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index d90bb58..6ca4406 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7359,18 +7359,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; } @@ -7384,10 +7373,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; } @@ -7396,7 +7387,6 @@ object___reduce_ex___impl(PyObject *self, int protocol) } return _common_reduce(self, protocol); -#undef objreduce } static PyObject * |