]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-153908: Fix data race in `itertools.count.__repr__` (GH-153917) (GH-153952)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 18 Jul 2026 13:29:04 +0000 (15:29 +0200)
committerGitHub <noreply@github.com>
Sat, 18 Jul 2026 13:29:04 +0000 (13:29 +0000)
(cherry picked from commit 5200f1192428becab0c31db98e7baa97f3c3c3e2)

Co-authored-by: John <me@joh.ng>
Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst [new file with mode: 0644]
Modules/itertoolsmodule.c

diff --git a/Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst b/Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst
new file mode 100644 (file)
index 0000000..6ee943a
--- /dev/null
@@ -0,0 +1 @@
+Fix data race when calling :func:`repr` on :class:`itertools.count` under the :term:`free-threaded build`.
index c307484d13377d4c2f3f5312b1cb530e53296684..2470a08885ad5c19f16172518617a997a84e120b 100644 (file)
@@ -3681,9 +3681,11 @@ static PyObject *
 count_repr(PyObject *op)
 {
     countobject *lz = countobject_CAST(op);
-    if (lz->long_cnt == NULL)
+    if (lz->long_cnt == NULL) {
+        Py_ssize_t cnt = FT_ATOMIC_LOAD_SSIZE_RELAXED(lz->cnt);
         return PyUnicode_FromFormat("%s(%zd)",
-                                    _PyType_Name(Py_TYPE(lz)), lz->cnt);
+                                    _PyType_Name(Py_TYPE(lz)), cnt);
+    }
 
     if (PyLong_Check(lz->long_step)) {
         long step = PyLong_AsLong(lz->long_step);