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
Boxiang Sun
cython
Commits
b5bfda6d
Commit
b5bfda6d
authored
Mar 25, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FIx #252, bad C struct identifiers
parent
621d7cdb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+17
-0
tests/compile/bad_c_struct_T252.pyx
tests/compile/bad_c_struct_T252.pyx
+8
-0
No files found.
Cython/Compiler/Symtab.py
View file @
b5bfda6d
...
...
@@ -23,6 +23,19 @@ except NameError:
possible_identifier
=
re
.
compile
(
ur"(?![0-9])\
w+$
", re.U).match
nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match
ansi_c_keywords = set(
['auto', 'break', 'case', 'char', 'const', 'continue', 'default', 'do',
'double', 'else', 'enum', 'extern', 'float', 'for', 'goto', 'if',
'int', 'long', 'register', 'return', 'short', 'signed', 'sizeof',
'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'void',
'volatile', 'while'])
def c_safe_identifier(cname):
# There are some C limitations on struct entry names.
if cname[:2] == '__' or cname in ansi_c_keywords:
cname = Naming.pyrex_prefix + cname
return cname
class BufferAux(object):
writable_needed = False
...
...
@@ -1252,6 +1265,8 @@ class StructOrUnionScope(Scope):
# Add an entry for an attribute.
if not cname:
cname = name
if visibility == '
private
':
cname = c_safe_identifier(cname)
if type.is_cfunction:
type = PyrexTypes.CPtrType(type)
entry = self.declare(name, cname, type, pos, visibility)
...
...
@@ -1387,6 +1402,8 @@ class CClassScope(ClassScope):
%
name
)
if
not
cname
:
cname
=
name
if
visibility
==
'private'
:
cname
=
c_safe_identifier
(
cname
)
entry
=
self
.
declare
(
name
,
cname
,
type
,
pos
,
visibility
)
entry
.
is_variable
=
1
self
.
var_entries
.
append
(
entry
)
...
...
tests/compile/bad_c_struct_T252.pyx
0 → 100644
View file @
b5bfda6d
cdef
f
(
void
=
None
):
pass
cdef
struct
foo
:
int
void
cdef
class
Foo
:
cdef
int
void
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