]> granicus.if.org Git - python/commitdiff
* regression bug, count_next was coercing a Py_ssize_t to an unsigned Py_size_t
authorJack Diederich <jackdied@gmail.com>
Thu, 21 Sep 2006 17:50:26 +0000 (17:50 +0000)
committerJack Diederich <jackdied@gmail.com>
Thu, 21 Sep 2006 17:50:26 +0000 (17:50 +0000)
  which breaks negative counts
* added test for negative numbers
will backport to 2.5.1

Lib/test/test_itertools.py
Modules/itertoolsmodule.c

index 68987257d75b7387cac034da261bcc6610ad6a3f..2baa50755403c96a39329e477dade7418cc3a658 100644 (file)
@@ -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'))
index a41f55b20d160671e951fa62d81bbfc020497d2c..7fcbb103667a81aa83c6b32771cf8c24719c0d20 100644 (file)
@@ -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 *