Commits

Armin Rigo committed 0685657

Linux-only tweaks until the test passes.

  • Participants
  • Parent commits fa4cf4d
  • Branches linux-only

Comments (0)

Files changed (4)

cffi/ffiplatform.py

+import os
 
 
 class VerificationError(Exception):
     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
         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
 
         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)
 
     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',)
     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:
-
+import os
 from . import ffiplatform
 
 class Verifier(object):
             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,))

testing/test_parsing.py

         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>'