Commit 6313c867 authored by da-woods's avatar da-woods Committed by GitHub

Ensure utility code keeps the directives that it was compiled with (GH-3615)

When it's merged into the main module, wrap it in a CompilerDirectivesNode.
parent 83ac1a27
......@@ -87,7 +87,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
child_attrs = ["body"]
directives = None
def merge_in(self, tree, scope, merge_scope=False):
# Merges in the contents of another tree, and possibly scope. With the
# current implementation below, this must be done right prior
......@@ -123,6 +122,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.scope.merge_in(scope)
def with_compiler_directives(self):
# When merging a utility code module into the user code we need to preserve
# the original compiler directives. This returns the body of the module node,
# wrapped in its set of directives.
body = Nodes.CompilerDirectivesNode(self.pos, directives=self.directives, body=self.body)
return body
def analyse_declarations(self, env):
if has_np_pythran(env):
Pythran.include_pythran_generic(env)
......
......@@ -128,7 +128,8 @@ def inject_utility_code_stage_factory(context):
module_node.scope.utility_code_list.append(dep)
tree = utilcode.get_tree(cython_scope=context.cython_scope)
if tree:
module_node.merge_in(tree.body, tree.scope, merge_scope=True)
module_node.merge_in(tree.with_compiler_directives(),
tree.scope, merge_scope=True)
return module_node
return inject_utility_code_stage
......
# mode: compile
# tag: memoryview
# cython: binding=False
# See GH 3613 - when memoryviews were compiled with binding off they ended up in an
# inconsistent state where different directives were applied at different stages
# of the pipeline
import cython
def f(double[:] a):
pass
@cython.binding(False)
def g(double[:] a):
pass
@cython.binding(True)
def h(double[:] a):
pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment