Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3531,23 +3531,26 @@ count_traverse(PyObject *op, visitproc visit, void *arg)
static PyObject *
count_nextlong(countobject *lz)
{
PyObject *long_cnt;
PyObject *stepped_up;

long_cnt = lz->long_cnt;
if (long_cnt == NULL) {
if (lz->long_cnt == NULL) {
/* Switch to slow_mode */
long_cnt = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
if (long_cnt == NULL)
lz->long_cnt = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
if (lz->long_cnt == NULL) {
return NULL;
}
}
assert(lz->cnt == PY_SSIZE_T_MAX && long_cnt != NULL);
assert(lz->cnt == PY_SSIZE_T_MAX && lz->long_cnt != NULL);

// We hold one reference to "result" (a.k.a. the old value of
// lz->long_cnt); we'll either return it or keep it in lz->long_cnt.
PyObject *result = lz->long_cnt;

stepped_up = PyNumber_Add(long_cnt, lz->long_step);
if (stepped_up == NULL)
PyObject *stepped_up = PyNumber_Add(result, lz->long_step);
if (stepped_up == NULL) {
return NULL;
}
lz->long_cnt = stepped_up;
return long_cnt;

return result;
}
Comment on lines 3531 to 3554
Copy link
Copy Markdown
Member

@encukou encukou Mar 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the way to make it less confusing?

static PyObject *
count_nextlong(countobject *lz)
{
    if (lz->long_cnt == NULL) {
        /* Switch to slow_mode */
        lz->long_cnt = PyLong_FromSsize_t(PY_SSIZE_T_MAX);
        if (lz->long_cnt == NULL) {
            return NULL;
        }
    }
    assert(lz->cnt == PY_SSIZE_T_MAX && lz->long_cnt != NULL);

    // We hold one reference to "result" (a.k.a. the old value of
    // lz->long_cnt); we'll either return it or keep it in lz->long_cnt.
    PyObject *result = lz->long_cnt;

    PyObject *stepped_up = PyNumber_Add(result, lz->long_step);
    if (stepped_up == NULL) {
        return NULL;
    }
    lz->long_cnt = stepped_up;

    return result;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks less confusing.


static PyObject *
Expand Down
1 change: 1 addition & 0 deletions Objects/enumobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ increment_longindex_lock_held(enumobject *en)
if (next_index == NULL) {
return NULL;
}
en->en_longindex = next_index;
Comment thread
sergey-miryanov marked this conversation as resolved.
Outdated
}
assert(next_index != NULL);
Comment thread
eendebakpt marked this conversation as resolved.
Outdated
PyObject *stepped_up = PyNumber_Add(next_index, en->one);
Expand Down
4 changes: 3 additions & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4270,7 +4270,9 @@ listiter_reduce_general(void *_it, int forward)
}
/* empty iterator, create an empty list */
list = PyList_New(0);
if (list == NULL)
if (list == NULL) {
Py_DECREF(iter);
return NULL;
}
return Py_BuildValue("N(N)", iter, list);
}
Loading