summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-12-08 14:46:32 (GMT)
committerGitHub <noreply@github.com>2021-12-08 14:46:32 (GMT)
commit99c72326d245fb604609a87a51ef1ad0845467b7 (patch)
tree62317e0c33adb14af339a75d924365c2957ba8c3 /Objects
parentcca3004f64d49c9e170396ac787712fe03bffb29 (diff)
downloadcpython-99c72326d245fb604609a87a51ef1ad0845467b7.zip
cpython-99c72326d245fb604609a87a51ef1ad0845467b7.tar.gz
cpython-99c72326d245fb604609a87a51ef1ad0845467b7.tar.bz2
[3.10] bpo-46009: Do not exhaust generator when send() method raises (GH-29986). (GH-29988)
* [3.10] bpo-46009: Do not exhaust generator when send() method raises (GH-29986). (cherry picked from commit 69806b9516dbe092381f3ef884c7c64bb9b8414a) Co-authored-by: Mark Shannon <mark@hotpy.org> * Rename variable after cherry-pick. * Add NULL check.
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 3ac38de..33fc4a5 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -145,6 +145,19 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
PyObject *result;
*presult = NULL;
+ if (f != NULL && f->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 (f != NULL && _PyFrame_IsExecuting(f)) {
const char *msg = "generator already executing";
if (PyCoro_CheckExact(gen)) {