From 8529d6414f637a168e970e89815d83759d1211dc Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 6 Feb 2025 16:22:41 +0300 Subject: [PATCH] [3.13] gh-129643: Fix `PyList_Insert` in free-threading builds (GH-129680) (#129725) (cherry picked from commit 63f0406d5ad25a55e49c3903b29407c50a17cfd5) --- .../2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst | 1 + Objects/listobject.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2025-02-05-11-29-52.gh-issue-129643.4mGzvg.rst 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 000000000000..420e1fb9781f --- /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 d581fc8b0b29..65a8b06d978d 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -498,8 +498,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; } -- 2.47.3