Skip to content

Commit 950e7fb

Browse files
[3.14] gh-153908: Fix data race in itertools.count.__repr__ (GH-153917) (GH-153952)
(cherry picked from commit 5200f11) Co-authored-by: John <me@joh.ng>
1 parent 6f0f2cf commit 950e7fb

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
@@ -3681,9 +3681,11 @@ static PyObject *
36813681
count_repr(PyObject *op)
36823682
{
36833683
countobject *lz = countobject_CAST(op);
3684-
if (lz->long_cnt == NULL)
3684+
if (lz->long_cnt == NULL) {
3685+
Py_ssize_t cnt = FT_ATOMIC_LOAD_SSIZE_RELAXED(lz->cnt);
36853686
return PyUnicode_FromFormat("%s(%zd)",
3686-
_PyType_Name(Py_TYPE(lz)), lz->cnt);
3687+
_PyType_Name(Py_TYPE(lz)), cnt);
3688+
}
36873689

36883690
if (PyLong_Check(lz->long_step)) {
36893691
long step = PyLong_AsLong(lz->long_step);

0 commit comments

Comments
 (0)