summaryrefslogtreecommitdiffstats
path: root/Modules/itertoolsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-01-08 21:01:54 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-01-08 21:01:54 (GMT)
commit5bad41eefc9f80298bb1abe00a5475be8b015c57 (patch)
treed4b8064de3b2baaa474fb80133a1b6970ad69c07 /Modules/itertoolsmodule.c
parent5e4e4278c9ddec1d143962a53de653442a61f443 (diff)
downloadcpython-5bad41eefc9f80298bb1abe00a5475be8b015c57.zip
cpython-5bad41eefc9f80298bb1abe00a5475be8b015c57.tar.gz
cpython-5bad41eefc9f80298bb1abe00a5475be8b015c57.tar.bz2
Merge in r68394 fixing itertools.permutations() and combinations().
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r--Modules/itertoolsmodule.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 3a095b6..8125dcb 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1880,10 +1880,6 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
po->cycles = cycles;
po->result = NULL;
po->r = r;
- po->stopped = 0;
+ po->stopped = r > n ? 1 : 0;
return (PyObject *)po;