Skip to content

Commit

Permalink
Issue python#112: Prepare Stackless 3.5, fix StopIteration from gener…
Browse files Browse the repository at this point in the history
…ators

Fix the handling of StopIteration raised from generators.
It was broken by commit 2771a0ac806b.

https://bitbucket.org/stackless-dev/stackless/issues/112
  • Loading branch information
Anselm Kruis committed Mar 18, 2017
1 parent fdcab56 commit 8243dfa
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Stackless/core/stacklesseval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,13 +1117,12 @@ gen_iternext_callback(PyFrameObject *f, int exc, PyObject *result)
}
Py_CLEAR(result);
}
else if (!result) {
else if (!result && PyErr_ExceptionMatches(PyExc_StopIteration)) {
/* Check for __future__ generator_stop and conditionally turn
* a leaking StopIteration into RuntimeError (with its cause
* set appropriately). */
if ((((PyCodeObject *)gen->gi_code)->co_flags &
if (((PyCodeObject *)gen->gi_code)->co_flags &
(CO_FUTURE_GENERATOR_STOP | CO_COROUTINE | CO_ITERABLE_COROUTINE))
&& PyErr_ExceptionMatches(PyExc_StopIteration))
{
PyObject *exc, *val, *val2, *tb;
PyErr_Fetch(&exc, &val, &tb);
Expand All @@ -1141,6 +1140,24 @@ gen_iternext_callback(PyFrameObject *f, int exc, PyObject *result)
Py_INCREF(val);
PyErr_Restore(exc, val2, tb);
}
else {
PyObject *exc, *val, *tb;

/* Pop the exception before issuing a warning. */
PyErr_Fetch(&exc, &val, &tb);

if (PyErr_WarnFormat(PyExc_PendingDeprecationWarning, 1,
"generator '%.50S' raised StopIteration",
gen->gi_qualname)) {
/* Warning was converted to an error. */
Py_XDECREF(exc);
Py_XDECREF(val);
Py_XDECREF(tb);
}
else {
PyErr_Restore(exc, val, tb);
}
}
}

gen->gi_running = 0;
Expand Down

0 comments on commit 8243dfa

Please sign in to comment.