diff options
Diffstat (limited to 'cffi')
-rw-r--r-- | cffi/cparser.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py index d794139..262fd76 100644 --- a/cffi/cparser.py +++ b/cffi/cparser.py @@ -818,15 +818,13 @@ class Parser(object): if isinstance(exprnode, pycparser.c_ast.Constant): s = exprnode.value if '0' <= s[0] <= '9': - s = s.rstrip('uUlL') # remove integer constant suffix if any. this will remove pattern such as lL, but - # it is the responsibility of the C parser to perform this check. - try: # first we try to convert to base 8/10, as it will fail if the string contains base 2/16 C prefix. + s = s.rstrip('uUlL') + try: if s.startswith('0'): return int(s, 8) else: return int(s, 10) - except ValueError: # then it should be a base 2 or a base 16. it is necessary to explicitly check the - # prefix, as python's int() function will be able to convert both (0b01 and 0x0b01) into base 16. + except ValueError: if len(s) > 1: if s.lower()[0:2] == '0x': return int(s, 16) |