mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Bugfix: Properly test for errors from PyLong_AsLong() in itertools.cycle.
ti can raise an exception even if PyLong_Check() has succeeded.
This commit is contained in:
parent
ad45bfe2d3
commit
35722a9376
2 changed files with 11 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue