Commit af201548 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow closures in cdef functions.

parent 0369269d
...@@ -2388,8 +2388,8 @@ class CFuncDefNode(FuncDefNode): ...@@ -2388,8 +2388,8 @@ class CFuncDefNode(FuncDefNode):
def generate_argument_parsing_code(self, env, code): def generate_argument_parsing_code(self, env, code):
i = 0 i = 0
used = 0 used = 0
scope = self.local_scope
if self.type.optional_arg_count: if self.type.optional_arg_count:
scope = self.local_scope
code.putln('if (%s) {' % Naming.optional_args_cname) code.putln('if (%s) {' % Naming.optional_args_cname)
for arg in self.args: for arg in self.args:
if arg.default: if arg.default:
...@@ -2410,6 +2410,16 @@ class CFuncDefNode(FuncDefNode): ...@@ -2410,6 +2410,16 @@ class CFuncDefNode(FuncDefNode):
code.putln('}') code.putln('}')
code.putln('}') code.putln('}')
# Move arguments into closure if required
def put_into_closure(entry):
if entry.in_closure and not arg.default:
code.putln('%s = %s;' % (entry.cname, entry.original_cname))
code.put_var_incref(entry)
code.put_var_giveref(entry)
for arg in self.args:
put_into_closure(scope.lookup_here(arg.name))
def generate_argument_conversion_code(self, code): def generate_argument_conversion_code(self, code):
pass pass
......
...@@ -2261,8 +2261,8 @@ class MarkClosureVisitor(CythonTransform): ...@@ -2261,8 +2261,8 @@ class MarkClosureVisitor(CythonTransform):
def visit_CFuncDefNode(self, node): def visit_CFuncDefNode(self, node):
self.visit_FuncDefNode(node) self.visit_FuncDefNode(node)
if node.needs_closure: if node.needs_closure and node.overridable:
error(node.pos, "closures inside cdef functions not yet supported") error(node.pos, "closures inside cpdef functions not yet supported")
return node return node
def visit_LambdaNode(self, node): def visit_LambdaNode(self, node):
...@@ -2400,10 +2400,6 @@ class CreateClosureClasses(CythonTransform): ...@@ -2400,10 +2400,6 @@ class CreateClosureClasses(CythonTransform):
self.visitchildren(node) self.visitchildren(node)
return node return node
def visit_CFuncDefNode(self, node):
self.visitchildren(node)
return node
class GilCheck(VisitorTransform): class GilCheck(VisitorTransform):
""" """
......
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