[3.13] gh-129643: Fix PyList_Insert in free-threading builds (GH-129680) (#129725)

(cherry picked from commit 63f0406d5a)
This commit is contained in:
sobolevn 2025-02-06 16:22:41 +03:00 committed by GitHub
parent fc78ed9e6f
commit 8529d6414f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View file

@ -0,0 +1 @@
Fix thread safety of :c:func:`PyList_Insert` in free-threading builds.

View file

@ -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;
}