[pypy-commit] cffi linux-only: Linux-only tweaks until the test passes.

arigo noreply at buildbot.pypy.org
Fri Jun 8 11:17:52 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: linux-only
Changeset: r277:06856574ecd7
Date: 2012-06-08 11:17 +0200
http://bitbucket.org/cffi/cffi/changeset/06856574ecd7/

Log:	Linux-only tweaks until the test passes.

diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -1,3 +1,4 @@
+import os
 
 
 class VerificationError(Exception):
@@ -9,11 +10,15 @@
     cdef, but no verification has been done
     """
 
-def _get_test_file():
-    tst_file = udir.join('test.c')
-    i = 0
-    # XXX we want to put typedefs here
-    while tst_file.check():
-        tst_file = udir.join('test%d.c' % i)
-        i += 1
-    return tst_file
+test_file_counter = 0
+
+def _get_test_file_base():
+    # for now, living in the __pycache__ subdirectory
+    global test_file_counter
+    try:
+        os.mkdir('__pycache__')
+    except OSError:
+        pass
+    tst_file_base = '__pycache__/test%d' % test_file_counter
+    test_file_counter += 1
+    return tst_file_base
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -26,7 +26,7 @@
         except KeyError:
             return self.new_backend_type(ffi, *args)
 
-    def verifier_declare(self, verifier, f):
+    def verifier_declare(self, verifier, kind, name, f):
         # nothing to see here
         pass
 
@@ -65,6 +65,7 @@
         reprargs = [arg.get_c_name() for arg in self.args]
         if self.ellipsis:
             reprargs.append('...')
+        reprargs = reprargs or ['void']
         replace_with = '(*%s)(%s)' % (replace_with, ', '.join(reprargs))
         return self.result.get_c_name(replace_with)
 
@@ -77,14 +78,9 @@
     def new_backend_type(self, ffi, result, *args):
         return ffi._backend.new_function_type(args, result, self.ellipsis)
 
-    def verifier_declare(self, verifier, f):
-        restype = self.result.name
-        args = []
-        for arg in self.args:
-            args.append(arg.name)
-        args = ', '.join(args)
-        f.write('  { %s(* result)(%s) = %s; }\n' % (restype,
-                                                    args, self.name))
+    def verifier_declare(self, verifier, kind, name, f):
+        if kind == 'function':
+            f.write('  { %s = %s; }\n' % (self.get_c_name('result'), name))
 
 class PointerType(BaseType):
     _attrs_ = ('totype',)
@@ -152,7 +148,7 @@
     def get_btype(self, ffi):
         return ffi._backend.new_struct_type(self.name)
 
-    def verifier_declare(self, verifier, f):
+    def verifier_declare(self, verifier, name, f):
         verifier._write_printf(f, 'BEGIN struct %s size(%%ld)' % self.name,
                       'sizeof(struct %s)' % self.name)
         for decl in decl.decls:
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -1,4 +1,4 @@
-
+import os
 from . import ffiplatform
 
 class Verifier(object):
@@ -10,18 +10,19 @@
             f.write('  printf("%s\\n", %s);\n' % (what, ', '.join(args)))
 
     def verify(self, ffi, preamble, **kwargs):
-        tst_file = ffiplatform._get_test_file()
-        with tst_file.open('w') as f:
+        tst_file_base = ffiplatform._get_test_file_base()
+        with open(tst_file_base + '.c', 'w') as f:
             f.write('#include <stdio.h>\n')
             f.write(preamble + "\n\n")
             f.write('int main() {\n')
             for name, tp in ffi._parser._declarations.iteritems():
-                tp.verifier_declare(self, f)
+                kind, realname = name.split(' ', 1)
+                tp.verifier_declare(self, kind, realname, f)
             f.write('  return 0;\n')
             f.write('}\n')
-        f.close()
-        exe_name = platform.compile([str(tst_file)],
-                                    ExternalCompilationInfo(**kwargs))
-        out = platform.execute(exe_name)
-        assert out.returncode == 0
-        outlines = out.out.splitlines()
+        err = os.system('gcc -Werror -c %s.c -o %s.o' %
+                        (tst_file_base, tst_file_base))
+        if err:
+            raise ffiplatform.VerificationError(
+                '%s.c: see compilation warnings and errors above' %
+                (tst_file_base,))
diff --git a/testing/test_parsing.py b/testing/test_parsing.py
--- a/testing/test_parsing.py
+++ b/testing/test_parsing.py
@@ -106,14 +106,14 @@
         typedef int array_t[5];
         """)
     type = ffi._parser.parse_type("array_t", force_pointer=True)
-    BType = type.get_backend_type(ffi)
+    BType = ffi._get_cached_btype(type)
     assert BType == '<array <pointer to <int>> x 5>'
 
 def test_typedef_array_convert_array_to_pointer():
     ffi = FFI(backend=FakeBackend())
     ffi.cdef("""
-        typedef int array_t[5];
+        typedef int (*fn_t)(int[5]);
         """)
-    type = ffi._parser.parse_type("array_t", convert_array_to_pointer=True)
-    BType = type.get_backend_type(ffi)
-    assert BType == '<pointer to <int>>'
+    type = ffi._parser.parse_type("fn_t")
+    BType = ffi._get_cached_btype(type)
+    assert BType == '<func (<pointer to <int>>), <int>, False>'


More information about the pypy-commit mailing list