summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-10-20 19:54:20 (GMT)
committerYury Selivanov <yury@magic.io>2016-10-20 19:54:20 (GMT)
commita4b884f9009e9797e8bb7f8c9e797b4f033dd37e (patch)
tree2fde8b0eb3839d17740aa05f0d8cc5e86c9aec83 /Modules
parent82919ec44ff49aa2343ed433705efdc76b24b5c5 (diff)
downloadcpython-a4b884f9009e9797e8bb7f8c9e797b4f033dd37e.zip
cpython-a4b884f9009e9797e8bb7f8c9e797b4f033dd37e.tar.gz
cpython-a4b884f9009e9797e8bb7f8c9e797b4f033dd37e.tar.bz2
Issue #28492: Fix how StopIteration is raised in _asyncio.Future
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_asynciomodule.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index d1d9c54..d9fe63d 100644
--- a/Modules/_asynciomodule.c
+++ b/Modules/_asynciomodule.c
@@ -787,9 +787,26 @@ FutureIter_iternext(futureiterobject *it)
res = FutureObj_result(fut, NULL);
if (res != NULL) {
- // normal result
- PyErr_SetObject(PyExc_StopIteration, res);
+ /* The result of the Future is not an exception.
+
+ We cunstruct an exception instance manually with
+ PyObject_CallFunctionObjArgs and pass it to PyErr_SetObject
+ (similarly to what genobject.c does).
+
+ This is to handle a situation when "res" is a tuple, in which
+ case PyErr_SetObject would set the value of StopIteration to
+ the first element of the tuple.
+
+ (See PyErr_SetObject/_PyErr_CreateException code for details.)
+ */
+ PyObject *e = PyObject_CallFunctionObjArgs(
+ PyExc_StopIteration, res, NULL);
Py_DECREF(res);
+ if (e == NULL) {
+ return NULL;
+ }
+ PyErr_SetObject(PyExc_StopIteration, e);
+ Py_DECREF(e);
}
it->future = NULL;