Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a data race when iterating a shared :class:`types.GenericAlias` iterator
from multiple threads under the :term:`free-threaded build`.
12 changes: 9 additions & 3 deletions Objects/genericaliasobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,17 +939,23 @@ static PyObject *
ga_iternext(PyObject *op)
{
gaiterobject *gi = (gaiterobject*)op;
if (gi->obj == NULL) {
#ifdef Py_GIL_DISABLED
PyObject *obj = _Py_atomic_exchange_ptr(&gi->obj, NULL);
#else
PyObject* obj = gi->obj;
gi->obj = NULL;
#endif
if (obj == NULL) {
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}
gaobject *alias = (gaobject *)gi->obj;
gaobject *alias = (gaobject *)obj;
PyObject *starred_alias = Py_GenericAlias(alias->origin, alias->args);
Py_DECREF(obj);
if (starred_alias == NULL) {
return NULL;
}
((gaobject *)starred_alias)->starred = true;
Py_SETREF(gi->obj, NULL);
return starred_alias;
}

Expand Down
Loading