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
Kirill Smelkov
cython
Commits
9309fe02
Commit
9309fe02
authored
Oct 14, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
safer way to initialise string constants: keep bytes/str/unicode separated also in corner cases
parent
5a8e4501
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
5 deletions
+16
-5
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+16
-5
No files found.
Cython/Compiler/Code.py
View file @
9309fe02
...
...
@@ -290,6 +290,7 @@ class PyObjectConst(object):
possible_unicode_identifier
=
re
.
compile
(
ur"(?![0-9])\
w+$
", re.U).match
possible_bytes_identifier = re.compile(r"
(
?!
[
0
-
9
])
\
w
+
$
".encode('ASCII')).match
nice_identifier = re.compile('^[a-zA-Z0-9_]+$').match
find_alphanums = re.compile('([a-zA-Z0-9]+)').findall
class StringConst(object):
"""Global info about a C string constant held by GlobalState.
...
...
@@ -307,18 +308,28 @@ class StringConst(object):
def get_py_string_const(self, encoding, identifier=None, is_str=False):
py_strings = self.py_strings
text = self.text
if encoding is not None:
encoding = encoding.upper()
is_str = bool(identifier or is_str)
is_unicode = encoding is None and not is_str
key = (is_str, encoding)
if encoding is None:
# unicode string
encoding_key = None
else:
# bytes or str
encoding = encoding.lower()
if encoding in ('utf8', 'utf-8', 'ascii', 'usascii', 'us-ascii'):
encoding = None
encoding_key = None
else:
encoding_key = ''.join(find_alphanums(encoding))
key = (is_str, is_unicode, encoding_key)
if py_strings is not None and key in py_strings:
py_string = py_strings[key]
else:
if py_strings is None:
self.py_strings = {}
is_unicode = encoding is None and not is_str
if identifier:
intern = True
elif identifier is None:
...
...
@@ -588,7 +599,7 @@ class GlobalState(object):
return self.new_const_cname()
if len(value) < 20 and nice_identifier(value):
return "
%
s
%
s
" % (Naming.const_prefix, value)
return "
%
s
_
%
s
" % (Naming.const_prefix, value)
else:
return self.new_const_cname()
...
...
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