From f0efaf57ccd9980b7422c1965d0f227453cfa259 Mon Sep 17 00:00:00 2001 From: Haoyu Bai Date: Thu, 31 Mar 2011 04:34:01 +0800 Subject: [PATCH] prevent the directive dicts from being shared among nodes and compilations --- Cython/Compiler/Nodes.py | 10 +++++++--- Cython/Compiler/ParseTreeTransforms.py | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 476a8922..3ba792f0 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -925,9 +925,11 @@ class CVarDefNode(StatNode): child_attrs = ["base_type", "declarators"] decorators = None - directive_locals = {} + directive_locals = None def analyse_declarations(self, env, dest_scope = None): + if self.directive_locals is None: + self.directive_locals = {} if not dest_scope: dest_scope = env self.dest_scope = dest_scope @@ -962,7 +964,7 @@ class CVarDefNode(StatNode): cname = cname, visibility = self.visibility, in_pxd = self.in_pxd, api = self.api) if entry is not None: - entry.directive_locals = self.directive_locals + entry.directive_locals = copy.copy(self.directive_locals) else: if self.directive_locals: error(self.pos, "Decorators can only be followed by functions") @@ -1638,12 +1640,14 @@ class CFuncDefNode(FuncDefNode): inline_in_pxd = False decorators = None - directive_locals = {} + directive_locals = None def unqualified_name(self): return self.entry.name def analyse_declarations(self, env): + if self.directive_locals is None: + self.directive_locals = {} self.directive_locals.update(env.directives['locals']) base_type = self.base_type.analyse(env) # The 2 here is because we need both function and argument names. diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 11a2baee..8c354c66 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -584,7 +584,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): super(InterpretCompilerDirectives, self).__init__(context) self.compilation_directive_defaults = {} for key, value in compilation_directive_defaults.items(): - self.compilation_directive_defaults[unicode(key)] = value + self.compilation_directive_defaults[unicode(key)] = copy.deepcopy(value) self.cython_module_names = cython.set() self.directive_names = {} @@ -604,8 +604,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): self.wrong_scope_error(node.pos, key, 'module') del node.directive_comments[key] - directives = copy.copy(Options.directive_defaults) - directives.update(self.compilation_directive_defaults) + directives = copy.deepcopy(Options.directive_defaults) + directives.update(copy.deepcopy(self.compilation_directive_defaults)) directives.update(node.directive_comments) self.directives = directives node.directives = directives -- 2.26.2