Use assignments, not (buggy) control flow, for arg incref decision.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 6 Jan 2010 19:05:39 +0000 (11:05 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 6 Jan 2010 19:05:39 +0000 (11:05 -0800)
Cython/Compiler/Nodes.py
tests/run/arg_incref.pyx

index 644ab12d45fb4c0fbdf9f91304513c03ac726b23..13a1fedea6d89f0e0a90756658475ba8e81020c2 100644 (file)
@@ -1135,7 +1135,7 @@ class FuncDefNode(StatNode, BlockNode):
         # If an argument is assigned to in the body, we must 
         # incref it to properly keep track of refcounts.
         for entry in lenv.arg_entries:
-            if entry.type.is_pyobject and lenv.control_flow.get_state((entry.name, 'source')) != 'arg':
+            if entry.type.is_pyobject and entry.assignments:
                 code.put_var_incref(entry)
         # ----- Initialise local variables 
         for entry in lenv.var_entries:
@@ -1238,11 +1238,10 @@ class FuncDefNode(StatNode, BlockNode):
         # Decref any increfed args
         for entry in lenv.arg_entries:
             if entry.type.is_pyobject:
-                src = lenv.control_flow.get_state((entry.name, 'source'))
-                if entry.in_closure and src == 'arg':
+                if entry.in_closure and not entry.assignments:
                     code.put_var_incref(entry)
                     code.put_var_giveref(entry)
-                elif not entry.in_closure and src != 'arg':
+                elif not entry.in_closure and entry.assignments:
                     code.put_var_decref(entry)
         if self.needs_closure:
             code.put_decref(Naming.cur_scope_cname, lenv.scope_class.type)
index cabc0b86c4410e24b1fe89599a7d30eea739f108..66b045ea10a9e324da28fbfb2e9a9798cc7cf573 100644 (file)
@@ -1,4 +1,4 @@
-def f(dict d):
+def f(dict d, x=4):
     """
     >>> f({1:1, 2:2})
     [1, 2]