]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129643: Fix `PyList_Insert` in free-threading builds (#129680)
authorsobolevn <mail@sobolevn.me>
Thu, 6 Feb 2025 12:54:40 +0000 (15:54 +0300)
committerGitHub <noreply@github.com>
Thu, 6 Feb 2025 12:54:40 +0000 (15:54 +0300)
Misc/NEWS.d/next/Core_and_Builtins/2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst [new file with mode: 0644]
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 (file)
index 0000000..420e1fb
--- /dev/null
@@ -0,0 +1 @@
+Fix thread safety of :c:func:`PyList_Insert` in free-threading builds.
index 86fa21495564631cf29d12fb847ecffc87d4a7ec..120e353b709e7bfbaf6dbe4d1bdfc63fae11b744 100644 (file)
@@ -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;
 }