summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-08-02 17:44:20 (GMT)
committerGitHub <noreply@github.com>2023-08-02 17:44:20 (GMT)
commit0d30a5a40968cce19750be78154232fae25d641f (patch)
treee6bc0cbcda38de59e6306524b247e5f6866f75be /Objects
parentdd693d6320feeca887174fa592537669d017ca9b (diff)
downloadcpython-0d30a5a40968cce19750be78154232fae25d641f.zip
cpython-0d30a5a40968cce19750be78154232fae25d641f.tar.gz
cpython-0d30a5a40968cce19750be78154232fae25d641f.tar.bz2
GH-100964: Break cycles involving exception state when returning from generator (GH-107563)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genobject.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index a630f84..65782be 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -149,14 +149,16 @@ gen_dealloc(PyGenObject *gen)
gen->gi_frame_state = FRAME_CLEARED;
frame->previous = NULL;
_PyFrame_ClearExceptCode(frame);
+ _PyErr_ClearExcState(&gen->gi_exc_state);
}
+ assert(gen->gi_exc_state.exc_value == NULL);
if (_PyGen_GetCode(gen)->co_flags & CO_COROUTINE) {
Py_CLEAR(((PyCoroObject *)gen)->cr_origin_or_finalizer);
}
Py_DECREF(_PyGen_GetCode(gen));
Py_CLEAR(gen->gi_name);
Py_CLEAR(gen->gi_qualname);
- _PyErr_ClearExcState(&gen->gi_exc_state);
+
PyObject_GC_Del(gen);
}
@@ -252,10 +254,7 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
!PyErr_ExceptionMatches(PyExc_StopAsyncIteration));
}
- /* generator can't be rerun, so release the frame */
- /* first clean reference cycle through stored exception traceback */
- _PyErr_ClearExcState(&gen->gi_exc_state);
-
+ assert(gen->gi_exc_state.exc_value == NULL);
assert(gen->gi_frame_state == FRAME_CLEARED);
*presult = result;
return result ? PYGEN_RETURN : PYGEN_ERROR;