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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
77196736
Commit
77196736
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
1309790e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
Cython/Compiler/CypclassWrapper.py
Cython/Compiler/CypclassWrapper.py
+16
-10
No files found.
Cython/Compiler/CypclassWrapper.py
View file @
77196736
...
@@ -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,20 @@ class CypclassWrapperInjection(CythonTransform):
...
@@ -172,18 +176,20 @@ 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"
)
cimport_stmt
=
Nodes
.
CImportStatNode
(
cimport_stmt
=
Nodes
.
CImportStatNode
(
module_node
.
pos
,
module_node
.
pos
,
module_name
=
"cython"
,
module_name
=
"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
)
...
...
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