diff options
author | Mark Shannon <mark@hotpy.org> | 2021-04-06 10:48:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 10:48:59 (GMT) |
commit | b37181e69209746adc2119c471599a1ea5faa6c8 (patch) | |
tree | 3605b5e9447fe18ed0c87b745daef1216301583f /Objects | |
parent | 489c36920e94bfb4988b6f965bd0aafdfaff0d4f (diff) | |
download | cpython-b37181e69209746adc2119c471599a1ea5faa6c8.zip cpython-b37181e69209746adc2119c471599a1ea5faa6c8.tar.gz cpython-b37181e69209746adc2119c471599a1ea5faa6c8.tar.bz2 |
bpo-43683: Handle generator entry in bytecode (GH-25138)
* Handle check for sending None to starting generator and coroutine into bytecode.
* Document new bytecode and make it fail gracefully if mis-compiled.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/genobject.c | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c index 6998967..b02a558 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -176,27 +176,12 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, } assert(_PyFrame_IsRunnable(f)); - if (f->f_lasti == -1) { - if (arg && arg != Py_None) { - const char *msg = "can't send non-None value to a " - "just-started generator"; - if (PyCoro_CheckExact(gen)) { - msg = NON_INIT_CORO_MSG; - } - else if (PyAsyncGen_CheckExact(gen)) { - msg = "can't send non-None value to a " - "just-started async generator"; - } - PyErr_SetString(PyExc_TypeError, msg); - return PYGEN_ERROR; - } - } else { - /* Push arg onto the frame's value stack */ - result = arg ? arg : Py_None; - Py_INCREF(result); - gen->gi_frame->f_valuestack[gen->gi_frame->f_stackdepth] = result; - gen->gi_frame->f_stackdepth++; - } + assert(f->f_lasti >= 0 || ((unsigned char *)PyBytes_AS_STRING(f->f_code->co_code))[0] == GEN_START); + /* Push arg onto the frame's value stack */ + result = arg ? arg : Py_None; + Py_INCREF(result); + gen->gi_frame->f_valuestack[gen->gi_frame->f_stackdepth] = result; + gen->gi_frame->f_stackdepth++; /* Generators always return to their most recent caller, not * necessarily their creator. */ |