diff options
author | Kristjan Valur Jonsson <sweskman@gmail.com> | 2011-03-30 11:32:06 (GMT) |
---|---|---|
committer | Kristjan Valur Jonsson <sweskman@gmail.com> | 2011-03-30 11:32:06 (GMT) |
commit | 978da33c7a07bf133d144a7ad342de7e20777250 (patch) | |
tree | def7ddd3a75913c4cfd3aa0a8e5500856224f4ee /Modules/itertoolsmodule.c | |
parent | 1ebdd714acdfab938cabd45924de4e26b88aec4d (diff) | |
parent | fa3edbed251a06226ae77571dc9e16eb44bf902b (diff) | |
download | cpython-978da33c7a07bf133d144a7ad342de7e20777250.zip cpython-978da33c7a07bf133d144a7ad342de7e20777250.tar.gz cpython-978da33c7a07bf133d144a7ad342de7e20777250.tar.bz2 |
Merge 3.2
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 5f0715d..ad22ec7 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -3060,6 +3060,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", @@ -3097,9 +3098,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) |