https://github.com/python/cpython/commit/7fd708b727fe19403726da6cb912b81768a96946 commit: 7fd708b727fe19403726da6cb912b81768a96946 branch: main author: Kumar Aditya <kumaradi...@python.org> committer: kumaraditya303 <kumaradi...@python.org> date: 2025-04-18T21:03:42+05:30 summary:
gh-132685: fix thread safety of `PyMember_GetOne` with `_Py_T_OBJECT` (#132690) files: M Python/structmember.c diff --git a/Python/structmember.c b/Python/structmember.c index d36e049d6b5d20..574acf296157f3 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -85,10 +85,22 @@ PyMember_GetOne(const char *obj_addr, PyMemberDef *l) break; } case _Py_T_OBJECT: - v = *(PyObject **)addr; - if (v == NULL) + v = FT_ATOMIC_LOAD_PTR(*(PyObject **) addr); + if (v != NULL) { +#ifdef Py_GIL_DISABLED + if (!_Py_TryIncrefCompare((PyObject **) addr, v)) { + Py_BEGIN_CRITICAL_SECTION((PyObject *) obj_addr); + v = FT_ATOMIC_LOAD_PTR(*(PyObject **) addr); + Py_XINCREF(v); + Py_END_CRITICAL_SECTION(); + } +#else + Py_INCREF(v); +#endif + } + if (v == NULL) { v = Py_None; - Py_INCREF(v); + } break; case Py_T_OBJECT_EX: v = member_get_object(addr, obj_addr, l); _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com