From 9ea6a3982c322af5f7a542291d5b442b0f6f1823 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 6 Jan 2010 11:05:39 -0800 Subject: [PATCH] Use assignments, not (buggy) control flow, for arg incref decision. --- Cython/Compiler/Nodes.py | 7 +++---- tests/run/arg_incref.pyx | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 644ab12d..13a1fede 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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) diff --git a/tests/run/arg_incref.pyx b/tests/run/arg_incref.pyx index cabc0b86..66b045ea 100644 --- a/tests/run/arg_incref.pyx +++ b/tests/run/arg_incref.pyx @@ -1,4 +1,4 @@ -def f(dict d): +def f(dict d, x=4): """ >>> f({1:1, 2:2}) [1, 2] -- 2.26.2