Commit b5bfda6d authored by Robert Bradshaw's avatar Robert Bradshaw

FIx #252, bad C struct identifiers

parent 621d7cdb
...@@ -23,6 +23,19 @@ except NameError: ...@@ -23,6 +23,19 @@ except NameError:
possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
nice_identifier = re.compile('^[a-zA-Z0-0_]+$').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): class BufferAux(object):
writable_needed = False writable_needed = False
...@@ -1252,6 +1265,8 @@ class StructOrUnionScope(Scope): ...@@ -1252,6 +1265,8 @@ class StructOrUnionScope(Scope):
# Add an entry for an attribute. # Add an entry for an attribute.
if not cname: if not cname:
cname = name cname = name
if visibility == 'private':
cname = c_safe_identifier(cname)
if type.is_cfunction: if type.is_cfunction:
type = PyrexTypes.CPtrType(type) type = PyrexTypes.CPtrType(type)
entry = self.declare(name, cname, type, pos, visibility) entry = self.declare(name, cname, type, pos, visibility)
...@@ -1387,6 +1402,8 @@ class CClassScope(ClassScope): ...@@ -1387,6 +1402,8 @@ class CClassScope(ClassScope):
% name) % name)
if not cname: if not cname:
cname = name cname = name
if visibility == 'private':
cname = c_safe_identifier(cname)
entry = self.declare(name, cname, type, pos, visibility) entry = self.declare(name, cname, type, pos, visibility)
entry.is_variable = 1 entry.is_variable = 1
self.var_entries.append(entry) self.var_entries.append(entry)
......
cdef f(void=None):
pass
cdef struct foo:
int void
cdef class Foo:
cdef int void
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment