summaryrefslogtreecommitdiff
path: root/Objects/genobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-09-05 10:14:54 -0700
committerBenjamin Peterson <benjamin@python.org>2016-09-05 10:14:54 -0700
commit2f40ed4b94ad48cca01a96620da8c3eb15493539 (patch)
tree108449a0c9a2e4e918da13abbad61d1fcc4456ae /Objects/genobject.c
parentfb5ce7eea18b287679f4a8b70c2391f6e9d71833 (diff)
downloadcpython-git-2f40ed4b94ad48cca01a96620da8c3eb15493539.tar.gz
do not allow _PyGen_Finalize to fail (closes #27811)
Patch from Armin Rigo.
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index b3e0a46e8b..a9ea5c2478 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -24,26 +24,27 @@ _PyGen_Finalize(PyObject *self)
PyObject *res;
PyObject *error_type, *error_value, *error_traceback;
+ if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL)
+ /* Generator isn't paused, so no need to close */
+ return;
+
+ /* Save the current exception, if any. */
+ PyErr_Fetch(&error_type, &error_value, &error_traceback);
+
/* If `gen` is a coroutine, and if it was never awaited on,
issue a RuntimeWarning. */
if (gen->gi_code != NULL
&& ((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE
- && gen->gi_frame != NULL
&& gen->gi_frame->f_lasti == -1
&& !PyErr_Occurred()
&& PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
"coroutine '%.50S' was never awaited",
- gen->gi_qualname))
- return;
-
- if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL)
- /* Generator isn't paused, so no need to close */
- return;
-
- /* Save the current exception, if any. */
- PyErr_Fetch(&error_type, &error_value, &error_traceback);
-
- res = gen_close(gen, NULL);
+ gen->gi_qualname)) {
+ res = NULL; /* oops, exception */
+ }
+ else {
+ res = gen_close(gen, NULL);
+ }
if (res == NULL)
PyErr_WriteUnraisable(self);