summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-05-24 10:18:13 (GMT)
committerGitHub <noreply@github.com>2024-05-24 10:18:13 (GMT)
commitc864efba25465eb6a4fff7e0a6df80a9ba449370 (patch)
treed4c9968b1ac36ac938a4b595d55534ea7f2ac5ea /Python/ceval.c
parente27e36922ee9fa970d3d8e602ac7eeb442ca530a (diff)
downloadcpython-c864efba25465eb6a4fff7e0a6df80a9ba449370.zip
cpython-c864efba25465eb6a4fff7e0a6df80a9ba449370.tar.gz
cpython-c864efba25465eb6a4fff7e0a6df80a9ba449370.tar.bz2
[3.13] gh-118692: Avoid creating unnecessary StopIteration instances for monitoring (GH-119216) (#119497)
* gh-118692: Avoid creating unnecessary StopIteration instances for monitoring (GH-119216) (cherry picked from commit 6e9863d7a3516cc76d6ce13923b15620499f3855) --------- Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 128e041..324d062 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -231,7 +231,8 @@ static void monitor_reraise(PyThreadState *tstate,
_Py_CODEUNIT *instr);
static int monitor_stop_iteration(PyThreadState *tstate,
_PyInterpreterFrame *frame,
- _Py_CODEUNIT *instr);
+ _Py_CODEUNIT *instr,
+ PyObject *value);
static void monitor_unwind(PyThreadState *tstate,
_PyInterpreterFrame *frame,
_Py_CODEUNIT *instr);
@@ -2215,12 +2216,19 @@ monitor_reraise(PyThreadState *tstate, _PyInterpreterFrame *frame,
static int
monitor_stop_iteration(PyThreadState *tstate, _PyInterpreterFrame *frame,
- _Py_CODEUNIT *instr)
+ _Py_CODEUNIT *instr, PyObject *value)
{
if (no_tools_for_local_event(tstate, frame, PY_MONITORING_EVENT_STOP_ITERATION)) {
return 0;
}
- return do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_STOP_ITERATION);
+ assert(!PyErr_Occurred());
+ PyErr_SetObject(PyExc_StopIteration, value);
+ int res = do_monitor_exc(tstate, frame, instr, PY_MONITORING_EVENT_STOP_ITERATION);
+ if (res < 0) {
+ return res;
+ }
+ PyErr_SetRaisedException(NULL);
+ return 0;
}
static void