Commit 4ccc4e5a authored by Neal Norwitz's avatar Neal Norwitz

Bug #1550714: fix SystemError from itertools.tee on negative value for n.

Needs backport to 2.5.1 and earlier.
parent 8384bb41
......@@ -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)
......
......@@ -27,6 +27,8 @@ Extension Modules
- Bug #1548092: fix curses.tparm seg fault on invalid input.
- Bug #1550714: fix SystemError from itertools.tee on negative value for n.
Tests
-----
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment