Fix bug in Cython closures branch.
authorCraig Citro <craigcitro@gmail.com>
Mon, 5 Oct 2009 23:36:27 +0000 (16:36 -0700)
committerCraig Citro <craigcitro@gmail.com>
Mon, 5 Oct 2009 23:36:27 +0000 (16:36 -0700)
Cython/Compiler/Nodes.py
tests/run/closures_T82.pyx

index 84c3cae9de73dad5daac463a491023283ba0abf4..5b4c8b5d45ca12addad87ca4953f1afe2eeb7fb2 100644 (file)
@@ -1181,7 +1181,7 @@ class FuncDefNode(StatNode, BlockNode):
             for entry in lenv.var_entries:
                 if lenv.control_flow.get_state((entry.name, 'initalized')) is not True:
                     entry.xdecref_cleanup = 1
-
+        
         if self.needs_closure:
             code.put_decref(Naming.cur_scope_cname, lenv.scope_class.type)
         for entry in lenv.var_entries:
@@ -1189,11 +1189,13 @@ class FuncDefNode(StatNode, BlockNode):
                 code.put_var_decref(entry)
         # Decref any increfed args
         for entry in lenv.arg_entries:
-            if (entry.type.is_pyobject 
-                    and not entry.in_closure
-                    and lenv.control_flow.get_state((entry.name, 'source')) != 'arg'):
-                code.put_var_decref(entry)
-
+            if entry.type.is_pyobject:
+                src = lenv.control_flow.get_state((entry.name, 'source'))
+                if entry.in_closure and src == 'arg':
+                    code.put_var_incref(entry)
+                elif not entry.in_closure and src != 'arg':
+                    code.put_var_decref(entry)
+                
         # ----- Return
         # This code is duplicated in ModuleNode.generate_module_init_func
         if not lenv.nogil:
index f6121580e6ad472fd29c46ee4b7ffa76f8fa9456..12fc510864e70997e2b48ea87287bf7c3961adc2 100644 (file)
@@ -3,6 +3,10 @@ __doc__ = u"""
 >>> f(2)
 5
 
+>>> f = add_n(1000000)
+>>> f(1000000), f(-1000000)
+2000000, 0
+
 >>> a(5)()
 8