Commit a55ce63c authored by Mark Florisson's avatar Mark Florisson

Use whitelist for declaring entries in a scope

parent d88146d0
......@@ -115,9 +115,10 @@ class CythonScope(ModuleScope):
viewscope, cython_scope=self)
view_utility_scope = MemoryView.view_utility_code.declare_in_scope(
self.viewscope, cython_scope=self)
self.viewscope, cython_scope=self,
whitelist=MemoryView.view_utility_whitelist)
self.entries["array"] = view_utility_scope.lookup("array")
self.entries["array"] = view_utility_scope.entries.pop("array")
def create_cython_scope(context):
......
......@@ -919,5 +919,8 @@ view_utility_code = load_memview_cy_utility(
overlapping_utility,
copy_contents_new_utility],
)
view_utility_whitelist = ('array', 'memoryview', 'array_cwrapper',
'generic', 'strided', 'indirect', 'contiguous',
'indirect_contiguous')
copy_contents_new_utility.requires.append(view_utility_code)
\ No newline at end of file
......@@ -290,11 +290,13 @@ class Scope(object):
def __deepcopy__(self, memo):
return self
def merge_in(self, other, merge_unused=True):
def merge_in(self, other, merge_unused=True, whitelist=None):
# Use with care...
entries = [(name, entry)
for name, entry in other.entries.iteritems()
if entry.used or merge_unused]
entries = []
for name, entry in other.entries.iteritems():
if not whitelist or name in whitelist:
if entry.used or merge_unused:
entries.append((name, entry))
self.entries.update(entries)
......
......@@ -138,7 +138,8 @@ class CythonUtilityCode(Code.UtilityCodeBase):
util = cls.load(util_code_name, from_file, **kwargs)
return util.proto, util.impl # keep line numbers => no lstrip()
def declare_in_scope(self, dest_scope, used=False, cython_scope=None):
def declare_in_scope(self, dest_scope, used=False, cython_scope=None,
whitelist=None):
"""
Declare all entries from the utility code in dest_scope. Code will only
be included for used entries. If module_name is given, declare the
......@@ -157,7 +158,8 @@ class CythonUtilityCode(Code.UtilityCodeBase):
entry.used = used
original_scope = tree.scope
dest_scope.merge_in(original_scope, merge_unused=True)
dest_scope.merge_in(original_scope, merge_unused=True,
whitelist=whitelist)
tree.scope = dest_scope
for dep in self.requires:
......
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