Commit 52af0421 authored by Stefan Behnel's avatar Stefan Behnel

support 'from cpython.array cimport array' in addition to existing cimport forms

parent b7be9d74
...@@ -6358,6 +6358,12 @@ class EnsureGILNode(GILExitNode): ...@@ -6358,6 +6358,12 @@ class EnsureGILNode(GILExitNode):
def generate_execution_code(self, code): def generate_execution_code(self, code):
code.put_ensure_gil(declare_gilstate=False) code.put_ensure_gil(declare_gilstate=False)
utility_code_for_cimports = {
# utility code (or inlining c) in a pxd (or pyx) file.
# TODO: Consider a generic user-level mechanism for importing
'cpython.array' : ("ArrayAPI", "arrayarray.h"),
'cpython.array.array' : ("ArrayAPI", "arrayarray.h"),
}
class CImportStatNode(StatNode): class CImportStatNode(StatNode):
# cimport statement # cimport statement
...@@ -6389,10 +6395,9 @@ class CImportStatNode(StatNode): ...@@ -6389,10 +6395,9 @@ class CImportStatNode(StatNode):
else: else:
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 == "cpython.array": if self.module_name in utility_code_for_cimports:
# TODO: Consider a generic user-level mechanism for importing env.use_utility_code(UtilityCode.load_cached(
# utility code (or inlining c) in a pxd (or pyx) file. *utility_code_for_cimports[self.module_name]))
env.use_utility_code(UtilityCode.load("ArrayAPI", "arrayarray.h"))
def analyse_expressions(self, env): def analyse_expressions(self, env):
pass pass
...@@ -6443,12 +6448,16 @@ class FromCImportStatNode(StatNode): ...@@ -6443,12 +6448,16 @@ class FromCImportStatNode(StatNode):
if entry: if entry:
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 self.module_name == "cpython":
# TODO: Consider a generic user-level mechanism for importing if self.module_name.startswith('cpython'): # enough for now
# utility code (or inlining c) in a pxd (or pyx) file. if self.module_name in utility_code_for_cimports:
env.use_utility_code(UtilityCode.load_cached(
*utility_code_for_cimports[self.module_name]))
for _, name, _, _ in self.imported_names: for _, name, _, _ in self.imported_names:
if name == "array": fqname = '%s.%s' % (self.module_name, name)
env.use_utility_code(UtilityCode.load("ArrayAPI", "arrayarray.h")) if fqname in utility_code_for_cimports:
env.use_utility_code(UtilityCode.load_cached(
*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