Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Populate the cython.view module with some Python objects

  • Loading branch information...
commit 83b48537129fc9b47c44f868c19eac80f286ca94 1 parent e8527c5
@dagss dagss authored committed
View
21 Cython/Compiler/CythonScope.py
@@ -82,6 +82,11 @@ def test_cythonscope(self):
cythonview_testscope_utility_code.declare_in_scope(viewscope)
+ for x in ('strided', 'contig', 'follow', 'direct', 'ptr', 'full'):
+ entry = viewscope.declare_var(x, py_object_type, None,
+ cname='__pyx_viewaxis_%s' % x,
+ is_cdef=True)
+ entry.utility_code_definition = view_utility_code
def create_cython_scope(context, create_testscope):
# One could in fact probably make it a singleton,
@@ -172,3 +177,19 @@ def def_cname_method(self, int value):
cdef object _testscope(int value):
return "hello from cython.view scope, value=%d" % value
""")
+
+view_utility_code = CythonUtilityCode(u"""
+cdef class Enum:
+ cdef object name
+ def __init__(self, name):
+ self.name = name
+ def __repr__(self):
+ return self.name
+
+cdef strided = Enum("<strided axis packing mode>")
+cdef contig = Enum("<contig axis packing mode>")
+cdef follow = Enum("<follow axis packing mode>")
+cdef direct = Enum("<direct axis access mode>")
+cdef ptr = Enum("<ptr axis access mode>")
+cdef full = Enum("<full axis access mode>")
+""", prefix="__pyx_viewaxis_")
View
1  Cython/Compiler/ExprNodes.py
@@ -3683,6 +3683,7 @@ def analyse_as_cimported_attribute(self, env, target):
entry.is_cglobal or entry.is_cfunction
or entry.is_type or entry.is_const):
self.mutate_into_name_node(env, entry, target)
+ entry.used = 1
return 1
return 0
View
19 Cython/Compiler/UtilityCode.py
@@ -6,20 +6,24 @@
class NonManglingModuleScope(Symtab.ModuleScope):
+ def __init__(self, prefix, *args, **kw):
+ self.prefix = prefix
+ Symtab.ModuleScope.__init__(self, *args, **kw)
+
def add_imported_entry(self, name, entry, pos):
entry.used = True
return super(NonManglingModuleScope, self).add_imported_entry(
name, entry, pos)
-
+
def mangle(self, prefix, name=None):
if name:
- if prefix in (Naming.typeobj_prefix, Naming.func_prefix):
+ if prefix in (Naming.typeobj_prefix, Naming.func_prefix, Naming.var_prefix):
# Functions, classes etc. gets a manually defined prefix easily
# manually callable instead (the one passed to CythonUtilityCode)
prefix = self.prefix
return "%s%s" % (prefix, name)
else:
- return self.base.name
+ return Symtab.ModuleScope.mangle(self, prefix)
class CythonUtilityCodeContext(StringParseContext):
scope = None
@@ -31,9 +35,10 @@ def find_module(self, module_name, relative_to = None, pos = None,
"from string code snippets")
if self.scope is None:
- self.scope = NonManglingModuleScope(
- module_name, parent_module=None, context=self)
- self.scope.prefix = self.prefix
+ self.scope = NonManglingModuleScope(self.prefix,
+ module_name,
+ parent_module=None,
+ context=self)
return self.scope
@@ -57,7 +62,7 @@ class CythonUtilityCode(object):
is_cython_utility = True
- def __init__(self, impl, name="CythonUtilityCode", prefix="", requires=None):
+ def __init__(self, impl, name="__pyxutil", prefix="", requires=None):
# 1) We need to delay the parsing/processing, so that all modules can be
# imported without import loops
# 2) The same utility code object can be used for multiple source files;
Please sign in to comment.
Something went wrong with that request. Please try again.