From 8c58fa41f54e42a759c0c4ed3d8d80b4aea70908 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 11 Dec 2010 02:12:14 +0100 Subject: [PATCH] split refnanny setup macro in declaration and setup part --- Cython/Compiler/Code.py | 4 ++++ Cython/Compiler/ModuleNode.py | 4 +++- Cython/Compiler/Nodes.py | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 6ebe5b19..58c0599d 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -475,6 +475,7 @@ class GlobalState(object): w.enter_cfunc_scope() w.putln("") w.putln("static int __Pyx_InitCachedConstants(void) {") + w.put_declare_refcount_context() w.put_setup_refcount_context("__Pyx_InitCachedConstants") w = self.parts['init_globals'] @@ -1344,6 +1345,9 @@ class CCodeWriter(object): def lookup_filename(self, filename): return self.globalstate.lookup_filename(filename) + def put_declare_refcount_context(self): + self.putln('__Pyx_RefNannyDeclareContext') + def put_setup_refcount_context(self, name): self.putln('__Pyx_RefNannySetupContext("%s");' % name) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index c39128fe..d46d605e 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2575,8 +2575,9 @@ refnanny_utility_code = UtilityCode(proto=""" Py_XDECREF(m); return (__Pyx_RefNannyAPIStruct *)r; } + #define __Pyx_RefNannyDeclareContext void *__pyx_refnanny; #define __Pyx_RefNannySetupContext(name) \ - void *__pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__) #define __Pyx_RefNannyFinishContext() \ __Pyx_RefNanny->FinishContext(&__pyx_refnanny) #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__) @@ -2585,6 +2586,7 @@ refnanny_utility_code = UtilityCode(proto=""" #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__) #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r);} } while(0) #else + #define __Pyx_RefNannyDeclareContext #define __Pyx_RefNannySetupContext(name) #define __Pyx_RefNannyFinishContext() #define __Pyx_INCREF(r) Py_INCREF(r) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index eaae0351..ebb25d14 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1296,6 +1296,7 @@ class FuncDefNode(StatNode, BlockNode): (self.return_type.declaration_code(Naming.retval_cname), init)) tempvardecl_code = code.insertion_point() + code.put_declare_refcount_context() if not self.is_generator: self.generate_keyword_list(code) if profile: @@ -1918,6 +1919,7 @@ class GeneratorWrapperNode(object): code.enter_cfunc_scope() code.putln() code.putln('%s {' % self.header) + code.put_declare_refcount_context() self.def_node.generate_keyword_list(code) code.put(lenv.scope_class.type.declaration_code(Naming.cur_scope_cname)) code.putln(";") -- 2.26.2