Skip to content

Commit bc30930

Browse files
committed
make repeat_next ft safe
1 parent f9d0531 commit bc30930

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Modules/itertoolsmodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,10 +3630,13 @@ static PyObject *
36303630
repeat_next(PyObject *op)
36313631
{
36323632
repeatobject *ro = repeatobject_CAST(op);
3633-
if (ro->cnt == 0)
3633+
Py_ssize_t cnt = FT_ATOMIC_LOAD_SSIZE_RELAXED(ro->cnt);
3634+
if (cnt == 0) {
36343635
return NULL;
3635-
if (ro->cnt > 0)
3636-
ro->cnt--;
3636+
}
3637+
cnt--;
3638+
assert(cnt >=0);
3639+
FT_ATOMIC_STORE_SSIZE_RELAXED(ro->cnt, cnt);
36373640
return Py_NewRef(ro->element);
36383641
}
36393642

0 commit comments

Comments
 (0)