From fa08b5dbd4fe0f038855e9098623f7a6e6609c7b Mon Sep 17 00:00:00 2001 From: Craig Citro Date: Mon, 5 Oct 2009 16:36:27 -0700 Subject: [PATCH] Fix bug in Cython closures branch. --- Cython/Compiler/Nodes.py | 14 ++++++++------ tests/run/closures_T82.pyx | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 84c3cae9..5b4c8b5d 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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: diff --git a/tests/run/closures_T82.pyx b/tests/run/closures_T82.pyx index f6121580..12fc5108 100644 --- a/tests/run/closures_T82.pyx +++ b/tests/run/closures_T82.pyx @@ -3,6 +3,10 @@ __doc__ = u""" >>> f(2) 5 +>>> f = add_n(1000000) +>>> f(1000000), f(-1000000) +2000000, 0 + >>> a(5)() 8 -- 2.26.2