Skip to content

Commit 5200f11

Browse files
authored
gh-153908: Fix data race in itertools.count.__repr__ (GH-153917)
1 parent 87f8fc8 commit 5200f11

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix data race when calling :func:`repr` on :class:`itertools.count` under the :term:`free-threaded build`.

Modules/itertoolsmodule.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,9 +3675,11 @@ static PyObject *
36753675
count_repr(PyObject *op)
36763676
{
36773677
countobject *lz = countobject_CAST(op);
3678-
if (lz->long_cnt == NULL)
3678+
if (lz->long_cnt == NULL) {
3679+
Py_ssize_t cnt = FT_ATOMIC_LOAD_SSIZE_RELAXED(lz->cnt);
36793680
return PyUnicode_FromFormat("%s(%zd)",
3680-
_PyType_Name(Py_TYPE(lz)), lz->cnt);
3681+
_PyType_Name(Py_TYPE(lz)), cnt);
3682+
}
36813683

36823684
if (PyLong_Check(lz->long_step)) {
36833685
long step = PyLong_AsLong(lz->long_step);

0 commit comments

Comments
 (0)