[Python-checkins] cpython (merge 3.2 -> default): Merge 3.2

kristjan.jonsson python-checkins at python.org
Wed Mar 30 13:56:50 CEST 2011


http://hg.python.org/cpython/rev/b63eeb5a5c07
changeset: 69064:b63eeb5a5c07
parent: 69037:7a8ada66c07d
parent: 69063:50e9d4515ea2
user: Kristjan Valur Jonsson <sweskman at gmail.com>
date: Wed Mar 30 11:32:06 2011 +0000
summary:
 Merge 3.2
files:
 Lib/test/test_itertools.py | 5 +++++
 Modules/itertoolsmodule.c | 9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -367,6 +367,8 @@
 list(range(maxsize-5, maxsize+5)))
 self.assertEqual(list(islice(count(-maxsize-5), 10)),
 list(range(-maxsize-5, -maxsize+5)))
+ self.assertEqual(list(islice(count(10, maxsize+5), 3)),
+ list(range(10, 10+3*(maxsize+5), maxsize+5)))
 c = count(3)
 self.assertEqual(repr(c), 'count(3)')
 next(c)
@@ -389,6 +391,9 @@
 self.assertEqual(next(copy.deepcopy(c)), value)
 self.assertEqual(next(pickle.loads(pickle.dumps(c))), value)
 
+ #check proper internal error handling for large "step' sizes
+ count(1, maxsize+5); sys.exc_info()
+
 def test_count_with_stride(self):
 self.assertEqual(lzip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
 self.assertEqual(lzip('abc',count(start=2,step=3)),
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3060,6 +3060,7 @@
 Py_ssize_t cnt = 0;
 PyObject *long_cnt = NULL;
 PyObject *long_step = NULL;
+ long step;
 static char *kwlist[] = {"start", "step", 0};
 
 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:count",
@@ -3097,9 +3098,11 @@
 assert(long_cnt != NULL && long_step != NULL);
 
 /* Fast mode only works when the step is 1 */
- if (!PyLong_Check(long_step) ||
- PyLong_AS_LONG(long_step) != 1) {
- slow_mode = 1;
+ step = PyLong_AsLong(long_step);
+ if (step != 1) {
+ slow_mode = 1;
+ if (step == -1 && PyErr_Occurred())
+ PyErr_Clear();
 }
 
 if (slow_mode)
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /