https://github.com/python/cpython/commit/b0810916235ee01d0d3df565288e28ffc45875d3
commit: b0810916235ee01d0d3df565288e28ffc45875d3
branch: 3.13
author: Kumar Aditya <kumaradi...@python.org>
committer: kumaraditya303 <kumaradi...@python.org>
date: 2025-02-05T08:09:37Z
summary:

[3.13] gh-129643: fix thread safety of `PyList_SetItem` (#129644) (#129677)

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

files:
A Misc/NEWS.d/next/Core and 
Builtins/2025-02-04-12-42-40.gh-issue-129643.K24Zow.rst
M Objects/listobject.c

diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2025-02-04-12-42-40.gh-issue-129643.K24Zow.rst b/Misc/NEWS.d/next/Core 
and Builtins/2025-02-04-12-42-40.gh-issue-129643.K24Zow.rst
new file mode 100644
index 00000000000000..27dd3b7f652aca
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2025-02-04-12-42-40.gh-issue-129643.K24Zow.rst 
@@ -0,0 +1 @@
+Fix thread safety of :c:func:`PyList_SetItem` in free-threading builds. Patch 
by Kumar Aditya.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 31ec8d5e05cf50..d581fc8b0b290c 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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();

_______________________________________________
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

Reply via email to