diff options
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r-- | Objects/genobject.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c index 1b08b43..24a4e94 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -10,7 +10,7 @@ #include "pycore_frame.h" // InterpreterFrame #include "frameobject.h" // PyFrameObject #include "structmember.h" // PyMemberDef -#include "opcode.h" // YIELD_FROM +#include "opcode.h" // SEND static PyObject *gen_close(PyGenObject *, PyObject *); static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *); @@ -356,14 +356,14 @@ _PyGen_yf(PyGenObject *gen) unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); if (frame->f_lasti < 0) { - /* Return immediately if the frame didn't start yet. YIELD_FROM + /* Return immediately if the frame didn't start yet. SEND always come after LOAD_CONST: a code object should not start - with YIELD_FROM */ - assert(code[0] != YIELD_FROM); + with SEND */ + assert(code[0] != SEND); return NULL; } - if (code[(frame->f_lasti+1)*sizeof(_Py_CODEUNIT)] != YIELD_FROM) + if (code[frame->f_lasti*sizeof(_Py_CODEUNIT)] != SEND || frame->stacktop < 0) return NULL; yf = _PyFrame_StackPeek(frame); Py_INCREF(yf); @@ -486,9 +486,13 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, ret = _PyFrame_StackPop((InterpreterFrame *)gen->gi_iframe); assert(ret == yf); Py_DECREF(ret); - /* Termination repetition of YIELD_FROM */ + /* Termination repetition of SEND loop */ assert(frame->f_lasti >= 0); - frame->f_lasti += 1; + PyObject *bytecode = gen->gi_code->co_code; + unsigned char *code = (unsigned char *)PyBytes_AS_STRING(bytecode); + assert(code[frame->f_lasti*sizeof(_Py_CODEUNIT)] == SEND); + int jump = code[frame->f_lasti*sizeof(_Py_CODEUNIT)+1]; + frame->f_lasti += jump; if (_PyGen_FetchStopIterationValue(&val) == 0) { ret = gen_send(gen, val); Py_DECREF(val); |