Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r892:89436c37cc2f
Date: 2012-08-24 19:03 +0200
http://bitbucket.org/cffi/cffi/changeset/89436c37cc2f/

Log:    Accept "0x123" constants too.

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -417,7 +417,7 @@
         # 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 == '-'):
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -880,6 +880,9 @@
         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())
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to