[3.12] gh-126618: fix repr(itertools.count(sys.maxsize)) (GH-127048) (#127510)

(cherry picked from commit 930ba0ce60)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Sergey B Kirpichev 2024-12-02 17:19:59 +03:00 committed by GitHub
parent 34137cbd23
commit 34fe4af8a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 6 deletions

View file

@ -3981,7 +3981,7 @@ typedef struct {
fast_mode: when cnt an integer < PY_SSIZE_T_MAX and no step is specified.
assert(cnt != PY_SSIZE_T_MAX && long_cnt == NULL && long_step==PyLong(1));
assert(long_cnt == NULL && long_step==PyLong(1));
Advances with: cnt += 1
When count hits Y_SSIZE_T_MAX, switch to slow_mode.
@ -4037,9 +4037,6 @@ itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
PyErr_Clear();
fast_mode = 0;
}
else if (cnt == PY_SSIZE_T_MAX) {
fast_mode = 0;
}
}
} else {
cnt = 0;
@ -4071,7 +4068,7 @@ itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
else
cnt = PY_SSIZE_T_MAX;
assert((cnt != PY_SSIZE_T_MAX && long_cnt == NULL && fast_mode) ||
assert((long_cnt == NULL && fast_mode) ||
(cnt == PY_SSIZE_T_MAX && long_cnt != NULL && !fast_mode));
assert(!fast_mode ||
(PyLong_Check(long_step) && PyLong_AS_LONG(long_step) == 1));
@ -4143,7 +4140,7 @@ count_next(countobject *lz)
static PyObject *
count_repr(countobject *lz)
{
if (lz->cnt != PY_SSIZE_T_MAX)
if (lz->long_cnt == NULL)
return PyUnicode_FromFormat("%s(%zd)",
_PyType_Name(Py_TYPE(lz)), lz->cnt);