Commit 8fbf6b84 authored by Mark Florisson's avatar Mark Florisson

Fix cython scope caching (it breaks about half of the test suite, but it...

Fix cython scope caching (it breaks about half of the test suite, but it probably slow down cython.compile)
parent dc0e0254
......@@ -105,21 +105,16 @@ class CythonScope(ModuleScope):
view_utility_scope = MemoryView.view_utility_code.declare_in_scope(
viewscope, cython_scope=self)
# MemoryView.memview_fromslice_utility_code.from_scope = view_utility_scope
# MemoryView.memview_fromslice_utility_code.declare_in_scope(viewscope)
def create_cython_scope(context, create_testscope):
def create_cython_scope(context):
# One could in fact probably make it a singleton,
# but not sure yet whether any code mutates it (which would kill reusing
# it across different contexts)
scope = CythonScope(context)
if create_testscope:
scope.test_cythonscope()
return scope
return CythonScope(context)
# Load test utilities for the cython scope
......
......@@ -4238,7 +4238,7 @@ class AttributeNode(ExprNode):
self.type = self.obj.type
return
else:
obj_type.declare_attribute(self.attribute)
obj_type.declare_attribute(self.attribute, env)
entry = obj_type.scope.lookup_here(self.attribute)
if entry and entry.is_member:
entry = None
......@@ -6559,7 +6559,7 @@ class CythonArrayNode(ExprNode):
self.type = self.get_cython_array_type(env)
assert self.type
env.use_utility_code(MemoryView.cython_array_utility_code)
MemoryView.use_cython_array_utility_code(env)
env.use_utility_code(MemoryView.typeinfo_to_format_code)
def allocate_temp_result(self, code):
......
......@@ -65,9 +65,12 @@ class Context(object):
import Builtin, CythonScope
self.modules = {"__builtin__" : Builtin.builtin_scope}
if self.cython_scope is None:
Context.cython_scope = CythonScope.create_cython_scope(
self, create_testscope=create_testscope)
#if self.cython_scope is None:
self.cython_scope = CythonScope.create_cython_scope(self)
if create_testscope: # and not hasattr(self.cython_scope, 'viewscope'):
self.cython_scope.test_cythonscope()
self.modules["cython"] = self.cython_scope
self.include_directories = include_directories
self.future_directives = set()
......
......@@ -130,9 +130,6 @@ def get_buf_flags(specs):
return memview_strided_access
def use_cython_array(env):
env.use_utility_code(cython_array_utility_code)
def src_conforms_to_dst(src, dst):
'''
returns True if src conforms to dst, False otherwise.
......@@ -936,6 +933,10 @@ def load_memview_c_utility(util_code_name, context=None, **kwargs):
return UtilityCode.load(util_code_name, "MemoryView_C.c",
context=context, **kwargs)
def use_cython_array_utility_code(env):
env.global_scope().context.cython_scope.lookup('array_cwrapper').used = True
env.use_utility_code(cython_array_utility_code)
context = {
'memview_struct_name': memview_objstruct_cname,
'max_dims': Options.buffer_max_dims,
......
......@@ -62,14 +62,21 @@ def inject_pxd_code_stage_factory(context):
return module_node
return inject_pxd_code_stage
def use_utility_code_definitions(scope, target):
def use_utility_code_definitions(scope, target, seen=None):
if seen is None:
seen = set()
for entry in scope.entries.itervalues():
if entry in seen:
continue
seen.add(entry)
if entry.used and entry.utility_code_definition:
target.use_utility_code(entry.utility_code_definition)
for required_utility in entry.utility_code_definition.requires:
target.use_utility_code(required_utility)
elif entry.as_module:
use_utility_code_definitions(entry.as_module, target)
use_utility_code_definitions(entry.as_module, target, seen)
def inject_utility_code_stage_factory(context):
def inject_utility_code_stage(module_node):
......
......@@ -501,7 +501,7 @@ class MemoryViewSliceType(PyrexType):
return True
def declare_attribute(self, attribute):
def declare_attribute(self, attribute, env):
import MemoryView, Options
scope = self.scope
......@@ -561,6 +561,8 @@ class MemoryViewSliceType(PyrexType):
entry.utility_code_definition = \
MemoryView.CopyFuncUtilCode(self, to_memview)
MemoryView.use_cython_array_utility_code(env)
elif attribute in ("is_c_contig", "is_f_contig"):
# is_c_contig and is_f_contig functions
for (c_or_f, cython_name) in (('c', 'is_c_contig'), ('fortran', 'is_f_contig')):
......
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