Commit 3bfdb38f authored by Stefan Behnel's avatar Stefan Behnel

avoid "return"-ing from generator without NULL return value but no exception...

avoid "return"-ing from generator without NULL return value but no exception set (fails assertion in debug build)
parent 4af42443
......@@ -5501,13 +5501,11 @@ class ReturnStatNode(StatNode):
have_gil=self.in_nogil_context)
elif self.in_generator:
# return value == raise StopIteration(value), but uncatchable
code.putln("%s = NULL;" % Naming.retval_cname)
if not self.value.is_none:
# CPython 3.3+ crashes in yield-from when the StopIteration is not instantiated
code.globalstate.use_utility_code(
UtilityCode.load_cached("ReturnWithStopIteration", "Generator.c"))
code.putln("__Pyx_ReturnWithStopIteration(%s);" % (
self.value.py_result()))
code.globalstate.use_utility_code(
UtilityCode.load_cached("ReturnWithStopIteration", "Generator.c"))
code.putln("%s = NULL; __Pyx_ReturnWithStopIteration(%s);" % (
Naming.retval_cname,
self.value.py_result()))
self.value.generate_disposal_code(code)
else:
self.value.make_owned_reference(code)
......
......@@ -755,7 +755,8 @@ static int __pyx_Generator_init(void) {
#if CYTHON_COMPILING_IN_CPYTHON
// CPython 3.3+ crashes in yield-from when the StopIteration is not instantiated
#define __Pyx_ReturnWithStopIteration(value) if (value == Py_None); else __Pyx__ReturnWithStopIteration(value)
#define __Pyx_ReturnWithStopIteration(value) \
if (value == Py_None) PyErr_SetNone(PyExc_StopIteration); else __Pyx__ReturnWithStopIteration(value)
static void __Pyx__ReturnWithStopIteration(PyObject* value); /*proto*/
#else
#define __Pyx_ReturnWithStopIteration(value) PyErr_SetObject(PyExc_StopIteration, value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment