mirror of
https://github.com/python/cpython.git
synced 2025-08-15 22:30:42 +00:00
Issue #10323: Predictable final state for slice().
This commit is contained in:
parent
1fea5c4472
commit
061bf7a11a
3 changed files with 13 additions and 3 deletions
|
@ -1215,6 +1215,7 @@ islice_next(isliceobject *lz)
|
|||
{
|
||||
PyObject *item;
|
||||
PyObject *it = lz->it;
|
||||
Py_ssize_t stop = lz->stop;
|
||||
Py_ssize_t oldnext;
|
||||
PyObject *(*iternext)(PyObject *);
|
||||
|
||||
|
@ -1226,7 +1227,7 @@ islice_next(isliceobject *lz)
|
|||
Py_DECREF(item);
|
||||
lz->cnt++;
|
||||
}
|
||||
if (lz->stop != -1 && lz->cnt >= lz->stop)
|
||||
if (stop != -1 && lz->cnt >= stop)
|
||||
return NULL;
|
||||
item = iternext(it);
|
||||
if (item == NULL)
|
||||
|
@ -1234,8 +1235,8 @@ islice_next(isliceobject *lz)
|
|||
lz->cnt++;
|
||||
oldnext = lz->next;
|
||||
lz->next += lz->step;
|
||||
if (lz->next < oldnext) /* Check for overflow */
|
||||
lz->next = lz->stop;
|
||||
if (lz->next < oldnext || (stop != -1 && lz->next > stop))
|
||||
lz->next = stop;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue