Commit f327c492 authored by Robert Bradshaw's avatar Robert Bradshaw

Use cython.view.array utility code on cimport.

Fixes #1502
parent c6dfb487
...@@ -1478,7 +1478,7 @@ class GlobalState(object): ...@@ -1478,7 +1478,7 @@ class GlobalState(object):
See UtilityCode. See UtilityCode.
""" """
if utility_code not in self.utility_codes: if utility_code and utility_code not in self.utility_codes:
self.utility_codes.add(utility_code) self.utility_codes.add(utility_code)
utility_code.put_code(self) utility_code.put_code(self)
......
...@@ -7312,14 +7312,19 @@ class EnsureGILNode(GILExitNode): ...@@ -7312,14 +7312,19 @@ class EnsureGILNode(GILExitNode):
code.put_ensure_gil(declare_gilstate=False) code.put_ensure_gil(declare_gilstate=False)
def cython_view_utility_code():
from . import MemoryView
return MemoryView.view_utility_code
utility_code_for_cimports = { utility_code_for_cimports = {
# utility code (or inlining c) in a pxd (or pyx) file. # utility code (or inlining c) in a pxd (or pyx) file.
# TODO: Consider a generic user-level mechanism for importing # TODO: Consider a generic user-level mechanism for importing
'cpython.array' : ("ArrayAPI", "arrayarray.h"), 'cpython.array' : lambda : UtilityCode.load_cached("ArrayAPI", "arrayarray.h"),
'cpython.array.array' : ("ArrayAPI", "arrayarray.h"), 'cpython.array.array' : lambda : UtilityCode.load_cached("ArrayAPI", "arrayarray.h"),
'cython.view' : cython_view_utility_code,
} }
utility_code_for_imports = { utility_code_for_imports = {
# utility code used when special modules are imported. # utility code used when special modules are imported.
# TODO: Consider a generic user-level mechanism for importing # TODO: Consider a generic user-level mechanism for importing
...@@ -7362,8 +7367,7 @@ class CImportStatNode(StatNode): ...@@ -7362,8 +7367,7 @@ class CImportStatNode(StatNode):
name = self.as_name or self.module_name name = self.as_name or self.module_name
env.declare_module(name, module_scope, self.pos) env.declare_module(name, module_scope, self.pos)
if self.module_name in utility_code_for_cimports: if self.module_name in utility_code_for_cimports:
env.use_utility_code(UtilityCode.load_cached( env.use_utility_code(utility_code_for_cimports[self.module_name]())
*utility_code_for_cimports[self.module_name]))
def analyse_expressions(self, env): def analyse_expressions(self, env):
return self return self
...@@ -7422,15 +7426,13 @@ class FromCImportStatNode(StatNode): ...@@ -7422,15 +7426,13 @@ class FromCImportStatNode(StatNode):
local_name = as_name or name local_name = as_name or name
env.add_imported_entry(local_name, entry, pos) env.add_imported_entry(local_name, entry, pos)
if module_name.startswith('cpython'): # enough for now if module_name.startswith('cpython') or module_name.startswith('cython'): # enough for now
if module_name in utility_code_for_cimports: if module_name in utility_code_for_cimports:
env.use_utility_code(UtilityCode.load_cached( env.use_utility_code(utility_code_for_cimports[module_name]())
*utility_code_for_cimports[module_name]))
for _, name, _, _ in self.imported_names: for _, name, _, _ in self.imported_names:
fqname = '%s.%s' % (module_name, name) fqname = '%s.%s' % (module_name, name)
if fqname in utility_code_for_cimports: if fqname in utility_code_for_cimports:
env.use_utility_code(UtilityCode.load_cached( env.use_utility_code(utility_code_for_cimports[fqname]())
*utility_code_for_cimports[fqname]))
def declaration_matches(self, entry, kind): def declaration_matches(self, entry, kind):
if not entry.is_type: if not entry.is_type:
......
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