[Python-checkins] r51952 - in python/branches/release25-maint: Lib/test/test_itertools.py Modules/itertoolsmodule.c

jack.diederich python-checkins at python.org
Thu Sep 21 20:32:12 CEST 2006


Author: jack.diederich
Date: Thu Sep 21 20:32:11 2006
New Revision: 51952

Modified:
   python/branches/release25-maint/Lib/test/test_itertools.py
   python/branches/release25-maint/Modules/itertoolsmodule.c
Log:
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


Modified: python/branches/release25-maint/Lib/test/test_itertools.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_itertools.py	(original)
+++ python/branches/release25-maint/Lib/test/test_itertools.py	Thu Sep 21 20:32:11 2006
@@ -58,6 +58,10 @@
         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'))

Modified: python/branches/release25-maint/Modules/itertoolsmodule.c
==============================================================================
--- python/branches/release25-maint/Modules/itertoolsmodule.c	(original)
+++ python/branches/release25-maint/Modules/itertoolsmodule.c	Thu Sep 21 20:32:11 2006
@@ -2072,7 +2072,7 @@
 static PyObject *
 count_next(countobject *lz)
 {
-	return PyInt_FromSize_t(lz->cnt++);
+	return PyInt_FromSsize_t(lz->cnt++);
 }
 
 static PyObject *


More information about the Python-checkins mailing list