From 8a813930d7257a215ba752c89332a5824124fdc5 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 15 Jun 2024 10:28:08 +0900 Subject: [PATCH 1/2] gh-120496: Use Critical section for rangeiter_next --- Objects/rangeobject.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 7da6162744ffd6..eeec6c79c188ef 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -813,16 +813,21 @@ PyTypeObject PyRange_Type = { in the normal case, but possible for any numeric value. */ +#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() + 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 * From 2422b2f3fc1c9396165de756e5a60addfdbb8676 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 15 Jun 2024 15:39:32 +0900 Subject: [PATCH 2/2] Clean up header --- Objects/rangeobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index eeec6c79c188ef..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,7 +814,6 @@ PyTypeObject PyRange_Type = { in the normal case, but possible for any numeric value. */ -#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() static PyObject * rangeiter_next(_PyRangeIterObject *r)