From: Neal Norwitz Date: Tue, 5 Sep 2006 02:30:10 +0000 (+0000) Subject: Backport fix for SF bug #1550714, itertools.tee raises SystemError X-Git-Tag: v2.5c2~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7ae5f294658caaf4de4afabbc779317cca0217da;p=thirdparty%2FPython%2Fcpython.git Backport fix for SF bug #1550714, itertools.tee raises SystemError --- diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 4b631dda4809..68987257d75b 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -371,6 +371,7 @@ class TestBasicOps(unittest.TestCase): # test values of n self.assertRaises(TypeError, tee, 'abc', 'invalid') + self.assertRaises(ValueError, tee, [], -1) for n in xrange(5): result = tee('abc', n) self.assertEqual(type(result), tuple) diff --git a/Misc/NEWS b/Misc/NEWS index 56f13fa2d676..d7a118b6470a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -43,6 +43,12 @@ Library - Bug #1543303, patch #1543897: remove NUL padding from tarfiles. +Extension Modules +----------------- + +- Bug #1550714: fix SystemError from itertools.tee on negative value for n. + + Tests ----- diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index d91389033ff4..a41f55b20d16 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -618,11 +618,15 @@ static PyTypeObject tee_type = { 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;