gh-132685: fix thread safety of PyMember_GetOne with _Py_T_OBJECT (#132690)

This commit is contained in:
Kumar Aditya 2025-04-18 21:03:42 +05:30 committed by GitHub
parent e77d6784e7
commit 7fd708b727
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);