summaryrefslogtreecommitdiffstats
path: root/Objects/genobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-09-07 15:47:18 (GMT)
committerBenjamin Peterson <benjamin@python.org>2016-09-07 15:47:18 (GMT)
commit9d2617bec001250781d26625f73907372832b8a7 (patch)
tree2090cde62bc4742885f54161b2bde038a8ecabc6 /Objects/genobject.c
parent6a137e8d503f24ab352a85c0cffff5aa16a670e0 (diff)
parentb88db8745b4f3e20471f729e34c941344a9d8b34 (diff)
downloadcpython-9d2617bec001250781d26625f73907372832b8a7.zip
cpython-9d2617bec001250781d26625f73907372832b8a7.tar.gz
cpython-9d2617bec001250781d26625f73907372832b8a7.tar.bz2
merge 3.5 (#27968)
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r--Objects/genobject.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c
index 104d90b..562d41d 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -21,7 +21,7 @@ void
_PyGen_Finalize(PyObject *self)
{
PyGenObject *gen = (PyGenObject *)self;
- PyObject *res;
+ PyObject *res = NULL;
PyObject *error_type, *error_value, *error_traceback;
if (gen->gi_frame == NULL || gen->gi_frame->f_stacktop == NULL)
@@ -33,23 +33,26 @@ _PyGen_Finalize(PyObject *self)
/* 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->f_lasti == -1
- && !PyErr_Occurred()
- && PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
- "coroutine '%.50S' was never awaited",
- gen->gi_qualname)) {
- res = NULL; /* oops, exception */
+ if (gen->gi_code != NULL &&
+ ((PyCodeObject *)gen->gi_code)->co_flags & CO_COROUTINE &&
+ gen->gi_frame->f_lasti == -1) {
+ if (!error_value) {
+ PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
+ "coroutine '%.50S' was never awaited",
+ gen->gi_qualname);
+ }
}
else {
res = gen_close(gen, NULL);
}
- if (res == NULL)
- PyErr_WriteUnraisable(self);
- else
+ if (res == NULL) {
+ if (PyErr_Occurred())
+ PyErr_WriteUnraisable(self);
+ }
+ else {
Py_DECREF(res);
+ }
/* Restore the saved exception. */
PyErr_Restore(error_type, error_value, error_traceback);