Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d8a312b2
Commit
d8a312b2
authored
Jun 17, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Derive unique name for synthesized 'cimport cython'
parent
bb9056b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+18
-11
No files found.
Cython/Compiler/CypclassWrapper.py
View file @
d8a312b2
...
@@ -155,13 +155,17 @@ class CypclassWrapperInjection(CythonTransform):
...
@@ -155,13 +155,17 @@ class CypclassWrapperInjection(CythonTransform):
self
.
derive_names
(
node
)
self
.
derive_names
(
node
)
self
.
collected_cypclasses
.
append
(
node
)
self
.
collected_cypclasses
.
append
(
node
)
def
create_unique_name
(
self
,
nested_name
,
suffix
):
def
create_unique_name
(
self
,
name
):
wrapper_name
=
"%s%s"
%
(
nested_name
,
suffix
)
# output: name(_u_*)?
while
wrapper_name
in
self
.
module_scope
.
entries
:
# guarantees:
# the end of the suffix must be modified to avoid collisions
# - different inputs always result in different outputs
# between cypclasses having the same prefix, e.g. 'A' and 'A_'.
# - the output is not in the module scope dictionary
wrapper_name
=
"%s_"
%
(
wrapper_name
,
suffix
)
unique_name
=
name
return
EncodedString
(
wrapper_name
)
if
unique_name
in
self
.
module_scope
.
entries
:
unique_name
=
"%s_u"
%
unique_name
while
unique_name
in
self
.
module_scope
.
entries
:
unique_name
=
"%s_"
%
unique_name
return
EncodedString
(
unique_name
)
def
derive_names
(
self
,
node
):
def
derive_names
(
self
,
node
):
nested_names
=
[
node
.
name
for
node
in
self
.
nesting_stack
]
nested_names
=
[
node
.
name
for
node
in
self
.
nesting_stack
]
...
@@ -172,18 +176,21 @@ class CypclassWrapperInjection(CythonTransform):
...
@@ -172,18 +176,21 @@ class CypclassWrapperInjection(CythonTransform):
nested_name
=
"_"
.
join
(
nested_names
)
nested_name
=
"_"
.
join
(
nested_names
)
cclass_name
=
self
.
create_unique_name
(
nested_name
,
"__cyp_cclass_wrapper"
)
cclass_name
=
self
.
create_unique_name
(
"%s_cyp_cclass_wrapper"
%
nested_name
)
pyclass_name
=
self
.
create_unique_name
(
nested_name
,
"__cyp_pyclass_wrapper"
)
pyclass_name
=
self
.
create_unique_name
(
"%s_cyp_pyclass_wrapper"
%
nested_name
)
self
.
type_to_names
[
node
.
entry
.
type
]
=
qualified_name
,
cclass_name
,
pyclass_name
self
.
type_to_names
[
node
.
entry
.
type
]
=
qualified_name
,
cclass_name
,
pyclass_name
def
inject_cypclass_wrappers
(
self
,
module_node
):
def
inject_cypclass_wrappers
(
self
,
module_node
):
if
self
.
cimport_cython
:
if
self
.
cimport_cython
:
# cimport cython to access the @cython.binding decorator
# cimport cython to access the @cython.binding decorator
# use a unique name for "cimport cython as <name>" if necessary
as_name
=
self
.
create_unique_name
(
"cython"
)
self
.
cython_as_name
=
as_name
cimport_stmt
=
Nodes
.
CImportStatNode
(
cimport_stmt
=
Nodes
.
CImportStatNode
(
module_node
.
pos
,
module_node
.
pos
,
module_name
=
EncodedString
(
"cython"
),
module_name
=
EncodedString
(
"cython"
),
as_name
=
None
,
as_name
=
None
if
as_name
==
"cython"
else
as_name
,
is_absolute
=
True
is_absolute
=
True
)
)
self
.
wrappers
.
append
(
cimport_stmt
)
self
.
wrappers
.
append
(
cimport_stmt
)
...
@@ -235,7 +242,7 @@ class CypclassWrapperInjection(CythonTransform):
...
@@ -235,7 +242,7 @@ class CypclassWrapperInjection(CythonTransform):
function
=
AttributeNode
(
function
=
AttributeNode
(
node
.
pos
,
node
.
pos
,
attribute
=
EncodedString
(
"binding"
),
attribute
=
EncodedString
(
"binding"
),
obj
=
NameNode
(
node
.
pos
,
name
=
EncodedString
(
"cython"
)
)
obj
=
NameNode
(
node
.
pos
,
name
=
self
.
cython_as_name
)
),
),
args
=
[
BoolNode
(
node
.
pos
,
value
=
True
)]
args
=
[
BoolNode
(
node
.
pos
,
value
=
True
)]
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment