Commits

Armin Rigo committed 89436c3

Accept "0x123" constants too.

Comments (0)

Files changed (2)

         # for now, limited to expressions that are an immediate number
         # or negative number
         if isinstance(exprnode, pycparser.c_ast.Constant):
-            return int(exprnode.value)
+            return int(exprnode.value, 0)
         #
         if (isinstance(exprnode, pycparser.c_ast.UnaryOp) and
                 exprnode.op == '-'):

testing/backend_tests.py

         assert ffi.cast("enum bar", "A") != ffi.cast("int", 0)
         assert repr(ffi.cast("enum bar", "CC")) == "<cdata 'enum bar' 'CC'>"
         py.test.raises(ValueError, ffi.cast, "enum bar", "UNKNOWN")
+        ffi.cdef("enum baz { A=0x1000, B=0x2000 };")
+        assert int(ffi.cast("enum baz", "A")) == 0x1000
+        assert int(ffi.cast("enum baz", "B")) == 0x2000
 
     def test_enum_in_struct(self):
         ffi = FFI(backend=self.Backend())