diff Modules/itertoolsmodule.c @ 39747:9d44792063bb 2.5

Backport fix for SF bug #1550714, itertools.tee raises SystemError
author Neal Norwitz <nnorwitz@gmail.com>
date Tue, 05 Sep 2006 02:30:10 +0000
parents e9773fc27e9b
children 69530aa21b8a
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c	Tue Sep 05 02:21:38 2006 +0000
+++ b/Modules/itertoolsmodule.c	Tue Sep 05 02:30:10 2006 +0000
@@ -618,11 +618,15 @@
 static PyObject *
 tee(PyObject *self, PyObject *args)
 {
-	int i, n=2;
+	Py_ssize_t i, n=2;
 	PyObject *it, *iterable, *copyable, *result;
 
-	if (!PyArg_ParseTuple(args, "O|i", &iterable, &n))
+	if (!PyArg_ParseTuple(args, "O|n", &iterable, &n))
 		return NULL;
+	if (n < 0) {
+		PyErr_SetString(PyExc_ValueError, "n must be >= 0");
+		return NULL;
+	}
 	result = PyTuple_New(n);
 	if (result == NULL)
 		return NULL;