summaryrefslogtreecommitdiffstats
path: root/Objects/genobject.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-01-24 11:08:53 (GMT)
committerGitHub <noreply@github.com>2022-01-24 11:08:53 (GMT)
commit0367a36fdc36b9c909c4d5acf7cde6ceeec0ba69 (patch)
tree1a87e9cb04dca5ef87abc4bd55540bdb41bd2172 /Objects/genobject.c
parentd75a51bea3c2442f81d38ff850b81b8b7f3330f0 (diff)
downloadcpython-0367a36fdc36b9c909c4d5acf7cde6ceeec0ba69.zip
cpython-0367a36fdc36b9c909c4d5acf7cde6ceeec0ba69.tar.gz
cpython-0367a36fdc36b9c909c4d5acf7cde6ceeec0ba69.tar.bz2
bpo-43683: Streamline YIELD_VALUE and SEND (GH-30723)
* Split YIELD_VALUE into ASYNC_GEN_WRAP; YIELD_VALUE for async generators. * Split SEND into SEND; YIELD_VALUE. * Document new opcodes.
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 46b0190..b2d402e 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -353,7 +353,7 @@ _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 */
@@ -361,7 +361,7 @@ _PyGen_yf(PyGenObject *gen)
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);
@@ -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;