[Python-checkins] r51684 - in python/trunk: Lib/test/test_itertools.py Misc/NEWS Modules/itertoolsmodule.c
neal.norwitz
python-checkins at python.org
Sat Sep 2 04:58:14 CEST 2006
Author: neal.norwitz
Date: Sat Sep 2 04:58:13 2006
New Revision: 51684
Modified:
python/trunk/Lib/test/test_itertools.py
python/trunk/Misc/NEWS
python/trunk/Modules/itertoolsmodule.c
Log:
Bug #1550714: fix SystemError from itertools.tee on negative value for n.
Needs backport to 2.5.1 and earlier.
Modified: python/trunk/Lib/test/test_itertools.py
==============================================================================
--- python/trunk/Lib/test/test_itertools.py (original)
+++ python/trunk/Lib/test/test_itertools.py Sat Sep 2 04:58:13 2006
@@ -371,6 +371,7 @@
# 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)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Sep 2 04:58:13 2006
@@ -27,6 +27,8 @@
- Bug #1548092: fix curses.tparm seg fault on invalid input.
+- Bug #1550714: fix SystemError from itertools.tee on negative value for n.
+
Tests
-----
Modified: python/trunk/Modules/itertoolsmodule.c
==============================================================================
--- python/trunk/Modules/itertoolsmodule.c (original)
+++ python/trunk/Modules/itertoolsmodule.c Sat Sep 2 04:58:13 2006
@@ -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;
More information about the Python-checkins
mailing list