summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorKristjan Valur Jonsson <sweskman@gmail.com>2011-03-30 11:04:28 (GMT)
committerKristjan Valur Jonsson <sweskman@gmail.com>2011-03-30 11:04:28 (GMT)
commit35722a93768e942be31270fe60acff138d878b26 (patch)
treefb473822ae05deb7d91424fefcc7ce4b09d1bd37 /Modules
parentad45bfe2d390eb94cf6d0e91b97c1db4bef2a2a9 (diff)
downloadcpython-35722a93768e942be31270fe60acff138d878b26.zip
cpython-35722a93768e942be31270fe60acff138d878b26.tar.gz
cpython-35722a93768e942be31270fe60acff138d878b26.tar.bz2
Bugfix: Properly test for errors from PyLong_AsLong() in itertools.cycle.
ti can raise an exception even if PyLong_Check() has succeeded.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index d5336f2..e7a7fbe 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2918,6 +2918,7 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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",
@@ -2955,9 +2956,11 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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)