[pypy-commit] cffi default: fix #407 add support for u/U suffix in integer constants (eg. 0xABu, or 0xCDU).
guil...@Guillaumes-MacBook-Pro.local
pypy.commits at gmail.com
Wed Mar 27 06:45:19 EDT 2019
Author: guillaumesottas at Guillaumes-MacBook-Pro.local
Branch:
Changeset: r3248:c0fbaf8dc825
Date: 2019-03-25 10:24 -0600
http://bitbucket.org/cffi/cffi/changeset/c0fbaf8dc825/
Log: fix #407 add support for u/U suffix in integer constants (eg. 0xABu,
or 0xCDU).
diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -819,6 +819,8 @@
s = exprnode.value
if s.startswith('0'):
if s.startswith('0x') or s.startswith('0X'):
+ if s.endswith('u') or s.endswith('U'):
+ s = s[:-1]
return int(s, 16)
return int(s, 8)
elif '1' <= s[0] <= '9':
diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
--- a/testing/cffi0/test_parsing.py
+++ b/testing/cffi0/test_parsing.py
@@ -466,3 +466,10 @@
e = py.test.raises(CDefError, ffi.cdef, 'void foo(void) {}')
assert str(e.value) == ('<cdef source string>:1: unexpected <FuncDef>: '
'this construct is valid C but not valid in cdef()')
+
+def test_unsigned_int_suffix_for_constant():
+ ffi = FFI()
+ ffi.cdef("""enum e {
+ enumerator_0=0x00,
+ enumerator_1=0x01u,
+ enumerator_1=0x01U};""")
More information about the pypy-commit
mailing list