Mercurial > cpython-lru_cache-weakref
diff Modules/itertoolsmodule.c @ 50635:fffd10c12a1b 3.0
Backport r68409 fixing itertools.permutations() and combinations().
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Thu, 08 Jan 2009 21:07:00 +0000 |
| parents | 94f64f11fdd0 |
| children | 87fbbf22adf3 c99ce0164699 |
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c Thu Jan 08 09:55:38 2009 +0000 +++ b/Modules/itertoolsmodule.c Thu Jan 08 21:07:00 2009 +0000 @@ -1880,10 +1880,6 @@ PyErr_SetString(PyExc_ValueError, "r must be non-negative"); goto error; } - if (r > n) { - PyErr_SetString(PyExc_ValueError, "r cannot be bigger than the iterable"); - goto error; - } indices = PyMem_Malloc(r * sizeof(Py_ssize_t)); if (indices == NULL) { @@ -1903,7 +1899,7 @@ co->indices = indices; co->result = NULL; co->r = r; - co->stopped = 0; + co->stopped = r > n ? 1 : 0; return (PyObject *)co; @@ -2143,10 +2139,6 @@ PyErr_SetString(PyExc_ValueError, "r must be non-negative"); goto error; } - if (r > n) { - PyErr_SetString(PyExc_ValueError, "r cannot be bigger than the iterable"); - goto error; - } indices = PyMem_Malloc(n * sizeof(Py_ssize_t)); cycles = PyMem_Malloc(r * sizeof(Py_ssize_t)); @@ -2170,7 +2162,7 @@ po->cycles = cycles; po->result = NULL; po->r = r; - po->stopped = 0; + po->stopped = r > n ? 1 : 0; return (PyObject *)po;
