https://github.com/python/cpython/commit/63f0406d5ad25a55e49c3903b29407c50a17cfd5
commit: 63f0406d5ad25a55e49c3903b29407c50a17cfd5
branch: main
author: sobolevn <[email protected]>
committer: sobolevn <[email protected]>
date: 2025-02-06T15:54:40+03:00
summary:

gh-129643: Fix `PyList_Insert` in free-threading builds (#129680)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst
M Objects/listobject.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst
new file mode 100644
index 00000000000000..420e1fb9781ff3
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst
@@ -0,0 +1 @@
+Fix thread safety of :c:func:`PyList_Insert` in free-threading builds.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 86fa2149556463..120e353b709e7b 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -466,8 +466,8 @@ ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
         where = n;
     items = self->ob_item;
     for (i = n; --i >= where; )
-        items[i+1] = items[i];
-    items[where] = Py_NewRef(v);
+        FT_ATOMIC_STORE_PTR_RELAXED(items[i+1], items[i]);
+    FT_ATOMIC_STORE_PTR_RELEASE(items[where], Py_NewRef(v));
     return 0;
 }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to