Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 71151:cc7ae81cfe91 3.2
restore a generator's caller's exception state both on yield and (last) return
This prevents generator exception state from leaking into the caller.
Closes #12475.
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sun, 03 Jul 2011 13:44:00 -0500 |
| parents | 2a19d09b08f8 |
| children | 419871c62bb3 33dca840938d |
line wrap: on
line diff
--- a/Python/ceval.c Sun Jul 03 13:31:34 2011 -0500 +++ b/Python/ceval.c Sun Jul 03 13:44:00 2011 -0500 @@ -1881,10 +1881,6 @@ retval = POP(); f->f_stacktop = stack_pointer; why = WHY_YIELD; - /* Put aside the current exception state and restore - that of the calling frame. This only serves when - "yield" is used inside an except handler. */ - SWAP_EXC_STATE(); goto fast_yield; TARGET(POP_EXCEPT) @@ -3021,6 +3017,11 @@ retval = NULL; fast_yield: + if (co->co_flags & CO_GENERATOR && (why == WHY_YIELD || why == WHY_RETURN)) + /* Put aside the current exception state and restore that of the + calling frame. */ + SWAP_EXC_STATE(); + if (tstate->use_tracing) { if (tstate->c_tracefunc) { if (why == WHY_RETURN || why == WHY_YIELD) {
