[pypy-commit] cffi default: Propagate "volatile" in addition to "const" and "restrict"

arigo noreply at buildbot.pypy.org
Mon Nov 2 16:55:11 EST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r2364:996827b4ddcd
Date: 2015-11-02 21:27 +0100
http://bitbucket.org/cffi/cffi/changeset/996827b4ddcd/

Log:	Propagate "volatile" in addition to "const" and "restrict"

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -348,6 +348,8 @@
                              pycparser.c_ast.PtrDecl)):
             if 'const' in type.quals:
                 quals |= model.Q_CONST
+            if 'volatile' in type.quals:
+                quals |= model.Q_VOLATILE
             if 'restrict' in type.quals:
                 quals |= model.Q_RESTRICT
         return quals
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -7,10 +7,13 @@
 # type qualifiers
 Q_CONST    = 0x01
 Q_RESTRICT = 0x02
+Q_VOLATILE = 0x04
 
 def qualify(quals, replace_with):
     if quals & Q_CONST:
         replace_with = ' const ' + replace_with.lstrip()
+    if quals & Q_VOLATILE:
+        replace_with = ' volatile ' + replace_with.lstrip()
     if quals & Q_RESTRICT:
         # It seems that __restrict is supported by gcc and msvc.
         # If you hit some different compiler, add a #define in
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -1204,12 +1204,19 @@
     assert foo_s.fields[1][1].type is ffi.typeof("void *")
 
 def test_restrict_fields():
-    if sys.platform == 'win32':
-        py.test.skip("'__restrict__' probably not recognized")
     ffi = FFI()
     ffi.cdef("""struct foo_s { void * restrict b; };""")
     lib = verify(ffi, 'test_restrict_fields', """
-        struct foo_s { void * __restrict__ b; };""")
+        struct foo_s { void * __restrict b; };""")
+    foo_s = ffi.typeof("struct foo_s")
+    assert foo_s.fields[0][0] == 'b'
+    assert foo_s.fields[0][1].type is ffi.typeof("void *")
+
+def test_volatile_fields():
+    ffi = FFI()
+    ffi.cdef("""struct foo_s { void * volatile b; };""")
+    lib = verify(ffi, 'test_volatile_fields', """
+        struct foo_s { void * volatile b; };""")
     foo_s = ffi.typeof("struct foo_s")
     assert foo_s.fields[0][0] == 'b'
     assert foo_s.fields[0][1].type is ffi.typeof("void *")


More information about the pypy-commit mailing list