summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschwarz <schwarz@zib.de>2014-07-27 16:50:45 +0200
committerschwarz <schwarz@zib.de>2014-07-27 16:50:45 +0200
commit27788d02bdef260ebe66db151ad5ea79061decda (patch)
tree4662a44dc9c95d13dde3bdca118d95f709bc3058
parentcc0d84a0b1ad2b402ea889c2160e1056e04b3357 (diff)
downloadcffi-27788d02bdef260ebe66db151ad5ea79061decda.tar.gz
add parsing of constant with unary +
-rw-r--r--cffi/cparser.py6
-rw-r--r--testing/test_parsing.py11
2 files changed, 16 insertions, 1 deletions
diff --git a/cffi/cparser.py b/cffi/cparser.py
index a53d4c3..d699894 100644
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -532,11 +532,15 @@ class Parser(object):
def _parse_constant(self, exprnode, partial_length_ok=False):
# for now, limited to expressions that are an immediate number
- # or negative number
+ # or positive/negative number
if isinstance(exprnode, pycparser.c_ast.Constant):
return int(exprnode.value, 0)
#
if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and
+ exprnode.op == '+'):
+ return self._parse_constant(exprnode.expr)
+ #
+ if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and
exprnode.op == '-'):
return -self._parse_constant(exprnode.expr)
# load previously defined int constant
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
index 594796a..97a16f9 100644
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -288,3 +288,14 @@ def test__is_constant_globalvar():
decl = ast.children()[0][1]
node = decl.type
assert p._is_constant_globalvar(node) == expected_output
+
+def test_enum():
+ ffi = FFI()
+ ffi.cdef("""
+ enum Enum { POS = +1, TWO = 2, NIL = 0, NEG = -1};
+ """)
+ C = ffi.dlopen(None)
+ assert C.POS == 1
+ assert C.TWO == 2
+ assert C.NIL == 0
+ assert C.NEG == -1