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
Gwenaël Samain
cython
Commits
94a59af4
Commit
94a59af4
authored
Sep 14, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix cname uniquification for string constants
parent
39e5e254
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+10
-8
tests/run/strliterals.pyx
tests/run/strliterals.pyx
+6
-1
No files found.
Cython/Compiler/Code.py
View file @
94a59af4
...
...
@@ -847,7 +847,7 @@ class GlobalState(object):
# In time, hopefully the literals etc. will be
# supplied directly instead.
#
# const_cname
_counters dict global counters for
constant identifiers
# const_cname
s_used set global index of unique
constant identifiers
#
# parts {string:CCodeWriter}
...
...
@@ -903,7 +903,7 @@ class GlobalState(object):
self.module_node = module_node # because some utility code generation needs it
# (generating backwards-compatible Get/ReleaseBuffer
self.const_cname
_counters = {}
self.const_cname
s_used = set()
self.string_const_index = {}
self.pyunicode_ptr_const_index = {}
self.int_const_index = {}
...
...
@@ -1109,12 +1109,14 @@ class GlobalState(object):
if
hasattr
(
value
,
'decode'
):
value
=
value
.
decode
(
'ASCII'
,
'ignore'
)
value
=
replace_identifier
(
'_'
,
value
)[:
32
].
strip
(
'_'
)
c
=
self
.
const_cname_counters
c
[
value
]
=
c
.
get
(
value
,
0
)
+
1
if
c
[
value
]
==
1
:
return
"%s%s%s"
%
(
Naming
.
const_prefix
,
prefix
,
value
)
else
:
return
"%s%s%s_%d"
%
(
Naming
.
const_prefix
,
prefix
,
value
,
c
[
value
])
used
=
self
.
const_cnames_used
counter
=
1
name_suffix
=
value
while
name_suffix
in
used
:
counter
+=
1
name_suffix
=
'%s_%d'
%
(
value
,
counter
)
used
.
add
(
name_suffix
)
return
"%s%s%s"
%
(
Naming
.
const_prefix
,
prefix
,
name_suffix
)
def
add_cached_builtin_decl
(
self
,
entry
):
if
entry
.
is_builtin
and
entry
.
is_const
:
...
...
tests/run/strliterals.pyx
View file @
94a59af4
...
...
@@ -148,6 +148,9 @@ __doc__ = ur"""
... sys.version_info[0] >= 3 and ord(str_uescape[-2]) or str_uescape[-12:-1])
True
>>> same_cname
[b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
>>> newlines
'Aaa\n'
...
...
@@ -165,7 +168,7 @@ import sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u" u'"
,
u" '"
).
replace
(
u" U'"
,
u" '"
).
replace
(
u" ur'"
,
u" r'"
).
replace
(
u" uR'"
,
u" R'"
).
replace
(
u" Ur'"
,
u" r'"
).
replace
(
u" UR'"
,
u" R'"
)
else
:
__doc__
=
__doc__
.
replace
(
u" b'"
,
u" '"
).
replace
(
u" B'"
,
u" '"
).
replace
(
u" br'"
,
u" r'"
).
replace
(
u" bR'"
,
u" R'"
).
replace
(
u" Br'"
,
u" r'"
).
replace
(
u" BR'"
,
u" R'"
)
__doc__
=
__doc__
.
replace
(
u" b'"
,
u" '"
).
replace
(
u" B'"
,
u" '"
).
replace
(
u" br'"
,
u" r'"
).
replace
(
u" bR'"
,
u" R'"
).
replace
(
u" Br'"
,
u" r'"
).
replace
(
u" BR'"
,
u" R'"
)
.
replace
(
u"[b'"
,
u"['"
)
s1
=
"abc
\
x11
"
s2
=
r"abc\x11"
...
...
@@ -191,6 +194,8 @@ uresc = ur'\12\'\"\\'
bytes_uescape
=
b'
\
u1234
\
U12345678
\
u
\
u1
\
u
12
\
uX
'
str_uescape = '
\
u0063
\
U00012345
\
N
{
SNOWMAN
}
\
x42
'
same_cname = [b'
abc
\
xf0
', b'
abc
\
xf1
', b'
abc
\
xf2
', b'
abc
\
xf3
', b'
abc_2
', b'
abc_3
']
newlines = "Aaa
\
n
"
# T640, long literals with escapes
...
...
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