summaryrefslogtreecommitdiff
path: root/cffi
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2014-12-31 18:48:36 +0100
committerArmin Rigo <arigo@tunes.org>2014-12-31 18:48:36 +0100
commitb477bc706a03603cd1a17968d580cfaf6c8ff1d9 (patch)
tree6fe328f73838c8e3bdba0a99671c7baa8d113845 /cffi
parentf3d5b6b2d8fbb92f44668d06b6c843e6e7af870f (diff)
downloadcffi-b477bc706a03603cd1a17968d580cfaf6c8ff1d9.tar.gz
Recognize more literal constants, notably octals and chars
Diffstat (limited to 'cffi')
-rw-r--r--cffi/cparser.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py
index 1de086a..5375242 100644
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -537,7 +537,18 @@ class Parser(object):
# for now, limited to expressions that are an immediate number
# or positive/negative number
if isinstance(exprnode, pycparser.c_ast.Constant):
- return int(exprnode.value, 0)
+ s = exprnode.value
+ if s.startswith('0'):
+ if s.startswith('0x') or s.startswith('0X'):
+ return int(s, 16)
+ return int(s, 8)
+ elif '1' <= s[0] <= '9':
+ return int(s, 10)
+ elif s[0] == "'" and s[-1] == "'" and (
+ len(s) == 3 or (len(s) == 4 and s[1] == "\\")):
+ return ord(s[-2])
+ else:
+ raise api.CDefError("invalid constant %r" % (s,))
#
if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and
exprnode.op == '+'):