Skip to content

Commit 9ef7a2b

Browse files
committed
gh-129643: Fix PyList_Insert in free-threading builds
1 parent fb5d1c9 commit 9ef7a2b

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix thread safety of :c:func:`PyList_Insert` in free-threading builds.

Objects/listobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ static int
447447
ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
448448
{
449449
Py_ssize_t i, n = Py_SIZE(self);
450-
PyObject **items;
451450
if (v == NULL) {
452451
PyErr_BadInternalCall();
453452
return -1;
@@ -464,10 +463,9 @@ ins1(PyListObject *self, Py_ssize_t where, PyObject *v)
464463
}
465464
if (where > n)
466465
where = n;
467-
items = self->ob_item;
468466
for (i = n; --i >= where; )
469-
items[i+1] = items[i];
470-
items[where] = Py_NewRef(v);
467+
FT_ATOMIC_STORE_PTR_RELEASE(self->ob_item[i+1], self->ob_item[i]);
468+
FT_ATOMIC_STORE_PTR_RELEASE(self->ob_item[where], Py_NewRef(v));
471469
return 0;
472470
}
473471

0 commit comments

Comments
 (0)