Mercurial > cpython-lru_cache-weakref
diff Modules/itertoolsmodule.c @ 66548:9e9a709b389e 3.1
Issue #10323: Predictable final state for slice().
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Tue, 30 Nov 2010 03:09:05 +0000 |
| parents | 4467c4c1d38e |
| children | 9a6da9bc257d 5da093b49c2a |
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c Tue Nov 30 01:01:02 2010 +0000 +++ b/Modules/itertoolsmodule.c Tue Nov 30 03:09:05 2010 +0000 @@ -1215,6 +1215,7 @@ { PyObject *item; PyObject *it = lz->it; + Py_ssize_t stop = lz->stop; Py_ssize_t oldnext; PyObject *(*iternext)(PyObject *); @@ -1226,7 +1227,7 @@ 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 @@ 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; }
