Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Split SEND into SEND; YIELD_VALUE.
  • Loading branch information
markshannon committed Jan 20, 2022
commit 3e85ca2694366bb400701a9fd4af29fe6b34c3f6
6 changes: 4 additions & 2 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ _PyGen_yf(PyGenObject *gen)
PyObject *bytecode = gen->gi_code->co_code;
unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode);

if (frame->f_lasti < 0) {
if (frame->f_lasti < 1) {
/* Return immediately if the frame didn't start yet. SEND
always come after LOAD_CONST: a code object should not start
with SEND */
assert(code[0] != SEND);
return NULL;
}

if (code[frame->f_lasti*sizeof(_Py_CODEUNIT)] != SEND || frame->stacktop < 0)
if (code[(frame->f_lasti-1)*sizeof(_Py_CODEUNIT)] != SEND || frame->stacktop < 0)
return NULL;
yf = _PyFrame_StackPeek(frame);
Py_INCREF(yf);
Expand Down Expand Up @@ -488,6 +488,8 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
assert(frame->f_lasti >= 0);
PyObject *bytecode = gen->gi_code->co_code;
unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode);
/* Backup to SEND */
frame->f_lasti--;
assert(code[frame->f_lasti*sizeof(_Py_CODEUNIT)] == SEND);
int jump = code[frame->f_lasti*sizeof(_Py_CODEUNIT)+1];
frame->f_lasti += jump;
Expand Down
13 changes: 2 additions & 11 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2650,17 +2650,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
}
assert (gen_status == PYGEN_NEXT);
assert (retval != NULL);
frame->f_state = FRAME_SUSPENDED;
_PyFrame_SetStackPointer(frame, stack_pointer);
TRACE_FUNCTION_EXIT();
DTRACE_FUNCTION_EXIT();
_Py_LeaveRecursiveCall(tstate);
/* Restore previous cframe and return. */
tstate->cframe = cframe.previous;
tstate->cframe->use_tracing = cframe.use_tracing;
assert(tstate->cframe->current_frame == frame->previous);
assert(!_PyErr_Occurred(tstate));
return retval;
PUSH(retval);
DISPATCH();
}

TARGET(ASYNC_GEN_WRAP) {
Expand Down
1 change: 1 addition & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ compiler_add_yield_from(struct compiler *c, int await)
compiler_use_next_block(c, start);
ADDOP_JUMP(c, SEND, exit);
compiler_use_next_block(c, resume);
ADDOP(c, YIELD_VALUE);
ADDOP_I(c, RESUME, await ? 3 : 2);
ADDOP_JUMP(c, JUMP_NO_INTERRUPT, start);
compiler_use_next_block(c, exit);
Expand Down