Skip to content

Commit d834451

Browse files
author
Anselm Kruis
committed
Issue python#112: Prepare Stackless 3.5, fix PEP479 for Stackless generators
Stackless has its own copy of the gen_send_ex function: slp_gen_send_ex() and gen_iternext_callback(). I added the PEP479 code to gen_iternext_callback(). https://bitbucket.org/stackless-dev/stackless/issues/112
1 parent 5fc2346 commit d834451

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Stackless/core/stacklesseval.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,31 @@ gen_iternext_callback(PyFrameObject *f, int exc, PyObject *result)
967967
}
968968
Py_CLEAR(result);
969969
}
970+
else if (!result) {
971+
/* Check for __future__ generator_stop and conditionally turn
972+
* a leaking StopIteration into RuntimeError (with its cause
973+
* set appropriately). */
974+
if ((((PyCodeObject *)gen->gi_code)->co_flags &
975+
CO_FUTURE_GENERATOR_STOP)
976+
&& PyErr_ExceptionMatches(PyExc_StopIteration))
977+
{
978+
PyObject *exc, *val, *val2, *tb;
979+
PyErr_Fetch(&exc, &val, &tb);
980+
PyErr_NormalizeException(&exc, &val, &tb);
981+
if (tb != NULL)
982+
PyException_SetTraceback(val, tb);
983+
Py_DECREF(exc);
984+
Py_XDECREF(tb);
985+
PyErr_SetString(PyExc_RuntimeError,
986+
"generator raised StopIteration");
987+
PyErr_Fetch(&exc, &val2, &tb);
988+
PyErr_NormalizeException(&exc, &val2, &tb);
989+
PyException_SetCause(val2, val);
990+
PyException_SetContext(val2, val);
991+
Py_INCREF(val);
992+
PyErr_Restore(exc, val2, tb);
993+
}
994+
}
970995

971996
/* We hold references to things in the cframe, if we release it
972997
before we clear the references, they get incorrectly and

0 commit comments

Comments
 (0)