bpo-46841: Don't jump during `throw()` by brandtbucher · Pull Request #31968 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
When a sub-iterator returns a value during a ``throw()`` call, perform the
resulting jump during the next :opcode:`SEND` instruction (rather than as
part of the ``throw()`` implementation).
10 changes: 2 additions & 8 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,8 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
ret = _PyFrame_StackPop((_PyInterpreterFrame *)gen->gi_iframe);
assert(ret == yf);
Py_DECREF(ret);
// XXX: Performing this jump ourselves is awkward and problematic.
// See https://github.com/python/cpython/pull/31968.
/* Termination repetition of SEND loop */
assert(_PyInterpreterFrame_LASTI(frame) >= 0);
/* Backup to SEND */
assert(_Py_OPCODE(frame->prev_instr[-1]) == SEND);
int jump = _Py_OPARG(frame->prev_instr[-1]);
frame->prev_instr += jump - 1;
// NULL tells SEND to quit sending:
_PyFrame_StackPush((_PyInterpreterFrame *)gen->gi_iframe, NULL);
if (_PyGen_FetchStopIterationValue(&val) == 0) {
ret = gen_send(gen, val);
Py_DECREF(val);
Expand Down
6 changes: 6 additions & 0 deletions Python/ceval.c