From 6de32fb142b672a7cc4af3334f9f6c6950ed6b01 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 3 May 2009 13:33:41 +0200 Subject: [PATCH] fix ref-counting for recursive closures: outer scope ref is initialised exactly once on creation and decref-cleared only by scope cleanup (i.e. the inner closure owns the parent reference) --- Cython/Compiler/Nodes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index e27e41d5..c0310320 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1073,8 +1073,10 @@ class FuncDefNode(StatNode, BlockNode): outer_scope_cname, env.scope_class.type.declaration_code(''), Naming.self_cname)) - code.put_incref(outer_scope_cname, env.scope_class.type) - code.put_giveref(outer_scope_cname) + if self.needs_closure: + # inner closures own a reference to their outer parent + code.put_incref(outer_scope_cname, env.scope_class.type) + code.put_giveref(outer_scope_cname) # ----- Fetch arguments self.generate_argument_parsing_code(env, code) # If an argument is assigned to in the body, we must -- 2.26.2