summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-12-08 12:09:26 (GMT)
committerGitHub <noreply@github.com>2021-12-08 12:09:26 (GMT)
commit69806b9516dbe092381f3ef884c7c64bb9b8414a (patch)
tree475262014715b235fa9a122ff09c973d47536f8e /Objects
parent3e0f13b9e48eec8c54a185e4180bfca4e5e685f6 (diff)
downloadcpython-69806b9516dbe092381f3ef884c7c64bb9b8414a.zip
cpython-69806b9516dbe092381f3ef884c7c64bb9b8414a.tar.gz
cpython-69806b9516dbe092381f3ef884c7c64bb9b8414a.tar.bz2
bpo-46009: Do not exhaust generator when send() method raises (GH-29986)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/genobject.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index c4ba660..147194c 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -157,6 +157,19 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
PyObject *result;
*presult = NULL;
+ if (frame->f_lasti < 0 && 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;
+ }
if (gen->gi_frame_valid && _PyFrame_IsExecuting(frame)) {
const char *msg = "generator already executing";
if (PyCoro_CheckExact(gen)) {