Skip to content

Commit 57bd4ff

Browse files
Fix data race on a shared types.GenericAlias iterator in ga_iter_reduce under free-threading
1 parent 5afbb60 commit 57bd4ff

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix data race when calling :meth:`~object.__reduce__` on a shared :class:`types.GenericAlias` iterator
2+
under the :term:`free-threaded build`.

Objects/genericaliasobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,13 +992,14 @@ ga_iter_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
992992
{
993993
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
994994
gaiterobject *gi = (gaiterobject *)self;
995+
PyObject *obj = FT_ATOMIC_LOAD_PTR(gi->obj);
995996

996997
/* _PyEval_GetBuiltin can invoke arbitrary code,
997998
* call must be before access of iterator pointers.
998999
* see issue #101765 */
9991000

1000-
if (gi->obj)
1001-
return Py_BuildValue("N(O)", iter, gi->obj);
1001+
if (obj)
1002+
return Py_BuildValue("N(O)", iter, obj);
10021003
else
10031004
return Py_BuildValue("N(())", iter);
10041005
}

0 commit comments

Comments
 (0)