gh-129643: fix thread safety of `PyList_SetItem` (#129644)

This commit is contained in:
Kumar Aditya 2025-02-05 13:08:02 +05:30 committed by GitHub
parent e41ec8e18b
commit fb5d1c9236
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -0,0 +1 @@
Fix thread safety of :c:func:`PyList_SetItem` in free-threading builds. Patch by Kumar Aditya.

View File

@ -419,7 +419,6 @@ int
PyList_SetItem(PyObject *op, Py_ssize_t i,
PyObject *newitem)
{
PyObject **p;
if (!PyList_Check(op)) {
Py_XDECREF(newitem);
PyErr_BadInternalCall();
@ -435,8 +434,9 @@ PyList_SetItem(PyObject *op, Py_ssize_t i,
ret = -1;
goto end;
}
p = self->ob_item + i;
Py_XSETREF(*p, newitem);
PyObject *tmp = self->ob_item[i];
FT_ATOMIC_STORE_PTR_RELEASE(self->ob_item[i], newitem);
Py_XDECREF(tmp);
ret = 0;
end:;
Py_END_CRITICAL_SECTION();