Skip to content

Commit 8a81393

Browse files
committed
pythongh-120496: Use Critical section for rangeiter_next
1 parent 5c58e72 commit 8a81393

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Objects/rangeobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,16 +813,21 @@ PyTypeObject PyRange_Type = {
813813
in the normal case, but possible for any numeric value.
814814
*/
815815

816+
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
817+
816818
static PyObject *
817819
rangeiter_next(_PyRangeIterObject *r)
818820
{
821+
PyObject *ret = NULL;
822+
Py_BEGIN_CRITICAL_SECTION(r);
819823
if (r->len > 0) {
820824
long result = r->start;
821825
r->start = result + r->step;
822826
r->len--;
823-
return PyLong_FromLong(result);
827+
ret = PyLong_FromLong(result);
824828
}
825-
return NULL;
829+
Py_END_CRITICAL_SECTION();
830+
return ret;
826831
}
827832

828833
static PyObject *

0 commit comments

Comments
 (0)