Backport fix for SF bug #1550714, itertools.tee raises SystemError

This commit is contained in:
Neal Norwitz 2006-09-05 02:30:10 +00:00
parent 29a5fdb7ca
commit 7ae5f29465
3 changed files with 13 additions and 2 deletions

View 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)

View File

@ -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
-----

View 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;