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 numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Make concurrent iteration over :class:`itertools.dropwhile` and
:class:`itertools.takewhile` safe under free-threading.
8 changes: 4 additions & 4 deletions Modules/itertoolsmodule.c
Original file line numberDiff line numberDiff line change
Expand Up@@ -1343,7 +1343,7 @@ dropwhile_next(PyObject *op)
item = iternext(it);
if (item == NULL)
return NULL;
if (lz->start == 1)
if (FT_ATOMIC_LOAD_LONG_RELAXED(lz->start) == 1)
return item;

good = PyObject_CallOneArg(lz->func, item);
Expand All@@ -1354,7 +1354,7 @@ dropwhile_next(PyObject *op)
ok = PyObject_IsTrue(good);
Py_DECREF(good);
if (ok == 0) {
lz->start = 1;
FT_ATOMIC_STORE_LONG_RELAXED(lz->start, 1);
return item;
}
Py_DECREF(item);
Expand DownExpand Up@@ -1460,7 +1460,7 @@ takewhile_next(PyObject *op)
PyObject *it = lz->it;
long ok;

if (lz->stop == 1)
if (FT_ATOMIC_LOAD_LONG_RELAXED(lz->stop) == 1)
return NULL;

item = (*Py_TYPE(it)->tp_iternext)(it);
Expand All@@ -1478,7 +1478,7 @@ takewhile_next(PyObject *op)
return item;
Py_DECREF(item);
if (ok == 0)
lz->stop = 1;
FT_ATOMIC_STORE_LONG_RELAXED(lz->stop, 1);
return NULL;
}

Expand Down
Loading