summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-01-31 09:29:47 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-01-31 09:29:47 (GMT)
commit26f7b8acdc010801a8fe877376488e0b69a89dad (patch)
treebe0c85b2c6deaeecedc9313c6983f917a6943ce5 /Python
parentfdc995336f3884117f2ede573694b9f0f7b9c11c (diff)
downloadcpython-26f7b8acdc010801a8fe877376488e0b69a89dad.zip
cpython-26f7b8acdc010801a8fe877376488e0b69a89dad.tar.gz
cpython-26f7b8acdc010801a8fe877376488e0b69a89dad.tar.bz2
Issue #23353: Fix the exception handling of generators in PyEval_EvalFrameEx().
At entry, save or swap the exception state even if PyEval_EvalFrameEx() is called with throwflag=0. At exit, the exception state is now always restored or swapped, not only if why is WHY_YIELD or WHY_RETURN. Patch co-written with Antoine Pitrou.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 118f2b7..7656b8e 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1189,8 +1189,8 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
f->f_stacktop = NULL; /* remains NULL unless yield suspends frame */
f->f_executing = 1;
- if (co->co_flags & CO_GENERATOR && !throwflag) {
- if (f->f_exc_type != NULL && f->f_exc_type != Py_None) {
+ if (co->co_flags & CO_GENERATOR) {
+ if (!throwflag && f->f_exc_type != NULL && f->f_exc_type != Py_None) {
/* We were in an except handler when we left,
restore the exception state which was put aside
(see YIELD_VALUE). */
@@ -3172,7 +3172,8 @@ fast_block_end:
|| (retval == NULL && PyErr_Occurred()));
fast_yield:
- if (co->co_flags & CO_GENERATOR && (why == WHY_YIELD || why == WHY_RETURN)) {
+ if (co->co_flags & CO_GENERATOR) {
+
/* The purpose of this block is to put aside the generator's exception
state and restore that of the calling frame. If the current
exception state is from the caller, we clear the exception values