Skip to content

Commit 20272e9

Browse files
kumaraditya303cmaloney
authored andcommitted
pythongh-129643: fix thread safety of PyList_SetItem (python#129644)
1 parent 779357a commit 20272e9

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix thread safety of :c:func:`PyList_SetItem` in free-threading builds. Patch by Kumar Aditya.

Objects/listobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ int
419419
PyList_SetItem(PyObject *op, Py_ssize_t i,
420420
PyObject *newitem)
421421
{
422-
PyObject **p;
423422
if (!PyList_Check(op)) {
424423
Py_XDECREF(newitem);
425424
PyErr_BadInternalCall();
@@ -435,8 +434,9 @@ PyList_SetItem(PyObject *op, Py_ssize_t i,
435434
ret = -1;
436435
goto end;
437436
}
438-
p = self->ob_item + i;
439-
Py_XSETREF(*p, newitem);
437+
PyObject *tmp = self->ob_item[i];
438+
FT_ATOMIC_STORE_PTR_RELEASE(self->ob_item[i], newitem);
439+
Py_XDECREF(tmp);
440440
ret = 0;
441441
end:;
442442
Py_END_CRITICAL_SECTION();

0 commit comments

Comments
 (0)