diff --git a/Stackless/core/stacklesseval.c b/Stackless/core/stacklesseval.c index 3acd4c0a77378d..b0783745fff92b 100644 --- a/Stackless/core/stacklesseval.c +++ b/Stackless/core/stacklesseval.c @@ -967,6 +967,31 @@ gen_iternext_callback(PyFrameObject *f, int exc, PyObject *result) } Py_CLEAR(result); } + else if (!result) { + /* 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 & + CO_FUTURE_GENERATOR_STOP) + && PyErr_ExceptionMatches(PyExc_StopIteration)) + { + PyObject *exc, *val, *val2, *tb; + PyErr_Fetch(&exc, &val, &tb); + PyErr_NormalizeException(&exc, &val, &tb); + if (tb != NULL) + PyException_SetTraceback(val, tb); + Py_DECREF(exc); + Py_XDECREF(tb); + PyErr_SetString(PyExc_RuntimeError, + "generator raised StopIteration"); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + PyException_SetCause(val2, val); + PyException_SetContext(val2, val); + Py_INCREF(val); + PyErr_Restore(exc, val2, tb); + } + } /* We hold references to things in the cframe, if we release it before we clear the references, they get incorrectly and