diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2015-05-21 21:52:21 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2015-05-22 07:49:59 +0200 |
commit | b070186e37f84d69dfef9b4e457fa30a000b9498 (patch) | |
tree | b17815cafe430deda8fa683f786fb1bd87834738 | |
parent | 711059f347d17198af7445f63ba29d7d5e89ab3a (diff) | |
download | cython-b070186e37f84d69dfef9b4e457fa30a000b9498.tar.gz |
fix error handling for closure creation in cdef void functions
-rw-r--r-- | Cython/Compiler/Nodes.py | 12 | ||||
-rw-r--r-- | tests/run/closure_inside_cdef_T554.pyx | 21 |
2 files changed, 30 insertions, 3 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 00269cf05..4d2f38249 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1829,7 +1829,17 @@ class FuncDefNode(StatNode, BlockNode): code.put_release_ensured_gil() # FIXME: what if the error return value is a Python value? - code.putln("return %s;" % self.error_value()) + err_val = self.error_value() + if err_val is None: + if not self.caller_will_check_exceptions(): + warning(self.entry.pos, + "Unraisable exception in function '%s'." % + self.entry.qualified_name, 0) + code.put_unraisable(self.entry.qualified_name, lenv.nogil) + #if self.return_type.is_void: + code.putln("return;") + else: + code.putln("return %s;" % err_val) code.putln("}") code.put_gotref(Naming.cur_scope_cname) # Note that it is unsafe to decref the scope at this point. diff --git a/tests/run/closure_inside_cdef_T554.pyx b/tests/run/closure_inside_cdef_T554.pyx index 494f17fac..5c84a447f 100644 --- a/tests/run/closure_inside_cdef_T554.pyx +++ b/tests/run/closure_inside_cdef_T554.pyx @@ -9,6 +9,23 @@ def call_f(x): """ return f(x) + cdef f(x): # def here => works fine - def g(y): return y*x # cdef here => compile error - return g(x) # faults@ INCREF(.*cur_scope->.*v_x + def g(y): return y*x # cdef here => compile error + return g(x) # faults@ INCREF(.*cur_scope->.*v_x + + +def closure_in_void(): + """ + >>> genex = closure_in_void() + >>> list(genex) + ['a', 'b', 'c'] + """ + l = [] + add_gen(l) + return l[0] + + +cdef void add_gen(l): + x = "abc" + l.append((c for c in x)) |