mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-129643: fix thread safety of `PyList_SetItem` (#129644)
This commit is contained in:
parent
4f0261561a
commit
b081091623
2 changed files with 4 additions and 3 deletions
|
@ -0,0 +1 @@
|
|||
Fix thread safety of :c:func:`PyList_SetItem` in free-threading builds. Patch by Kumar Aditya.
|
|
@ -451,7 +451,6 @@ int
|
|||
PyList_SetItem(PyObject *op, Py_ssize_t i,
|
||||
PyObject *newitem)
|
||||
{
|
||||
PyObject **p;
|
||||
if (!PyList_Check(op)) {
|
||||
Py_XDECREF(newitem);
|
||||
PyErr_BadInternalCall();
|
||||
|
@ -467,8 +466,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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue