Skip to content

Commit

Permalink
Issue python#112: Prepare Stackless 3.5, fix PEP479 for Stackless gen…
Browse files Browse the repository at this point in the history
…erators

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
  • Loading branch information
Anselm Kruis committed Dec 28, 2016
1 parent 5fc2346 commit d834451
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Stackless/core/stacklesseval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d834451

Please sign in to comment.