From: Jack Diederich Date: Thu, 21 Sep 2006 18:32:11 +0000 (+0000) Subject: backport of r51950 X-Git-Tag: v2.5.1c1~379 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=187e64806fca812453f6864b2bd6428c03c2c1a5;p=thirdparty%2FPython%2Fcpython.git backport of r51950 * regression bug, count_next was coercing a Py_ssize_t to an unsigned Py_size_t which breaks negative counts * added test for negative numbers --- diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index 68987257d75b..2baa50755403 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -58,6 +58,10 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(repr(c), 'count(3)') c.next() self.assertEqual(repr(c), 'count(4)') + c = count(-9) + self.assertEqual(repr(c), 'count(-9)') + c.next() + self.assertEqual(c.next(), -8) def test_cycle(self): self.assertEqual(take(10, cycle('abc')), list('abcabcabca')) diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index a41f55b20d16..7fcbb103667a 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2072,7 +2072,7 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject * count_next(countobject *lz) { - return PyInt_FromSize_t(lz->cnt++); + return PyInt_FromSsize_t(lz->cnt++); } static PyObject *