Skip to content
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Feb 14, 2024
commit 6e170cc130ce662951ce4216a15aaa21ac9fc226
8 changes: 4 additions & 4 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3393,19 +3393,19 @@ listiter_next(PyObject *self)
{
_PyListIterObject *it = (_PyListIterObject *)self;
Py_ssize_t index = LOAD_SSIZE(it->it_index);
if (it->it_seq == NULL || index < 0) {
if (index < 0) {
return NULL;
}

PyObject *item = list_get_item_ref(it->it_seq, index);
if (item == NULL) {
// out-of-bounds
STORE_SSIZE(it->it_index, -1);
#ifndef Py_GIL_DISABLED
PyListObject *seq = it->it_seq;
it->it_seq = NULL;
Py_DECREF(seq);
#endif
STORE_SSIZE(it->it_index, -1);
return NULL;
}
STORE_SSIZE(it->it_index, index + 1);
Expand Down Expand Up @@ -3551,19 +3551,19 @@ listreviter_next(PyObject *self)
assert(PyList_Check(seq));

Py_ssize_t index = LOAD_SSIZE(it->it_index);
if (it->it_seq == NULL || index < 0) {
if (index < 0) {
return NULL;
}
PyObject *item = list_get_item_ref(seq, index);
if (item != NULL) {
STORE_SSIZE(it->it_index, index - 1);
return item;
}
STORE_SSIZE(it->it_index, -1);
Comment thread
colesbury marked this conversation as resolved.
#ifndef Py_GIL_DISABLED
it->it_seq = NULL;
Py_DECREF(seq);
#endif
STORE_SSIZE(it->it_index, -1);
return NULL;
}

Expand Down