diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 7da6162744ffd6..45d91143aee9f1 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -3,6 +3,7 @@ #include "Python.h" #include "pycore_abstract.h" // _PyIndex_Check() #include "pycore_ceval.h" // _PyEval_GetBuiltin() +#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION() #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_modsupport.h" // _PyArg_NoKwnames() #include "pycore_range.h" @@ -813,16 +814,20 @@ PyTypeObject PyRange_Type = { in the normal case, but possible for any numeric value. */ + static PyObject * rangeiter_next(_PyRangeIterObject *r) { + PyObject *ret = NULL; + Py_BEGIN_CRITICAL_SECTION(r); if (r->len > 0) { long result = r->start; r->start = result + r->step; r->len--; - return PyLong_FromLong(result); + ret = PyLong_FromLong(result); } - return NULL; + Py_END_CRITICAL_SECTION(); + return ret; } static PyObject *