]> granicus.if.org Git - python/commitdiff
Backport fix for SF bug #1550714, itertools.tee raises SystemError
authorNeal Norwitz <nnorwitz@gmail.com>
Tue, 5 Sep 2006 02:30:10 +0000 (02:30 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Tue, 5 Sep 2006 02:30:10 +0000 (02:30 +0000)
Lib/test/test_itertools.py
Misc/NEWS
Modules/itertoolsmodule.c

index 4b631dda4809643e56018648a05e65f39b0bc6ab..68987257d75b7387cac034da261bcc6610ad6a3f 100644 (file)
@@ -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)
index 56f13fa2d67618aabc71d38a657037b19521f017..d7a118b6470acf7ab88f288b782a11802f8951c2 100644 (file)
--- 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
 -----
 
index d91389033ff4ec719105716ef4dafc8b0dbbd16d..a41f55b20d160671e951fa62d81bbfc020497d2c 100644 (file)
@@ -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;