[pypy-commit] cffi linux-only: Minimal fix for test_verify: track just "const pointers".

arigo noreply at buildbot.pypy.org
Fri Jun 8 14:25:51 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: linux-only
Changeset: r279:223ee076df94
Date: 2012-06-08 14:25 +0200
http://bitbucket.org/cffi/cffi/changeset/223ee076df94/

Log:	Minimal fix for test_verify: track just "const pointers".

diff --git a/cffi/cparser.py b/cffi/cparser.py
--- a/cffi/cparser.py
+++ b/cffi/cparser.py
@@ -85,9 +85,11 @@
             raise api.FFIError("multiple declarations of %s" % (name,))
         self._declarations[name] = obj
 
-    def _get_type_pointer(self, type):
+    def _get_type_pointer(self, type, const=False):
         if isinstance(type, model.FunctionType):
             return type # "pointer-to-function" ~== "function"
+        if const:
+            return model.ConstPointerType(type)
         return model.PointerType(type)
 
     def _get_type(self, typenode, convert_array_to_pointer=False,
@@ -121,7 +123,10 @@
         #
         if isinstance(typenode, pycparser.c_ast.PtrDecl):
             # pointer type
-            return self._get_type_pointer(self._get_type(typenode.type))
+            const = (isinstance(typenode.type, pycparser.c_ast.TypeDecl)
+                     and 'const' in typenode.type.quals)
+            return self._get_type_pointer(self._get_type(typenode.type), const)
+                                          
         #
         if isinstance(typenode, pycparser.c_ast.TypeDecl):
             type = typenode.type
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -82,6 +82,7 @@
         if kind == 'function':
             f.write('  { %s = %s; }\n' % (self.get_c_name('result'), name))
 
+
 class PointerType(BaseType):
     _attrs_ = ('totype',)
     
@@ -97,6 +98,18 @@
     def new_backend_type(self, ffi, BItem):
         return ffi._backend.new_pointer_type(BItem)
 
+class ConstPointerType(PointerType):
+
+    def get_c_name(self, replace_with=''):
+        return self.totype.get_c_name(' const * ' + replace_with)
+
+    def prepare_backend_type(self, ffi):
+        return (ffi._get_cached_btype(PointerType(self.totype)),)
+
+    def new_backend_type(self, ffi, BPtr):
+        return BPtr
+
+
 class ArrayType(BaseType):
     _attrs_ = ('item', 'length')
 


More information about the pypy-commit mailing list