[pypy-commit] cffi default: - Fixes to silence all -Wall warnings that now show up.

arigo noreply at buildbot.pypy.org
Fri Jun 15 11:21:06 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r364:69aa45b4ec38
Date: 2012-06-15 11:20 +0200
http://bitbucket.org/cffi/cffi/changeset/69aa45b4ec38/

Log:	- Fixes to silence all -Wall warnings that now show up.
	- Fixes to the tests to crash upon warnings too.

diff --git a/c/_ffi_backend.c b/c/_ffi_backend.c
--- a/c/_ffi_backend.c
+++ b/c/_ffi_backend.c
@@ -3369,16 +3369,18 @@
     return result;
 }
 
-void _cffi_restore_errno(void)
-{
+static void _cffi_restore_errno(void) {
     errno = saved_errno;
 }
 
-void _cffi_save_errno(void)
-{
+static void _cffi_save_errno(void) {
     saved_errno = errno;
 }
 
+static PyObject *_cffi_from_c_char(char x) {
+    return PyString_FromStringAndSize(&x, 1);
+}
+
 static void *cffi_exports[] = {
     _cffi_to_c_char_p,
     _cffi_to_c_signed_char,
@@ -3400,6 +3402,7 @@
     _cffi_get_struct_layout,
     _cffi_restore_errno,
     _cffi_save_errno,
+    _cffi_from_c_char,
 };
 
 /************************************************************/
diff --git a/cffi/ffiplatform.py b/cffi/ffiplatform.py
--- a/cffi/ffiplatform.py
+++ b/cffi/ffiplatform.py
@@ -52,12 +52,18 @@
 def _build(modname, kwds):
     # XXX compact but horrible :-(
     from distutils.core import Distribution, Extension
+    import distutils.errors
+    #
     ext = Extension(name=modname, sources=[modname + '.c'], **kwds)
     dist = Distribution({'ext_modules': [ext]})
     options = dist.get_option_dict('build_ext')
     options['force'] = ('ffiplatform', True)
     #
-    dist.run_command('build_ext')
+    try:
+        dist.run_command('build_ext')
+    except (distutils.errors.CompileError,
+            distutils.errors.LinkError), e:
+        raise VerificationError(str(e))
     #
     cmd_obj = dist.get_command_obj('build_ext')
     [soname] = cmd_obj.get_outputs()
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -54,7 +54,8 @@
             self.prnt('};')
             self.prnt()
             #
-            self.prnt('void init%s()' % modname)
+            self.prnt('PyMODINIT_FUNC')
+            self.prnt('init%s(void)' % modname)
             self.prnt('{')
             self.prnt('  Py_InitModule("%s", _cffi_methods);' % modname)
             self.prnt('  _cffi_init();')
@@ -223,6 +224,24 @@
             return     # nothing to do with opaque structs
         assert name == tp.name
         prnt = self.prnt
+        checkfuncname = '_cffi_check_%s' % (name,)
+        prnt('static void %s(struct %s *p)' % (checkfuncname, name))
+        prnt('{')
+        prnt('  /* only to generate compile-time warnings or errors */')
+        for i in range(len(tp.fldnames)):
+            fname = tp.fldnames[i]
+            ftype = tp.fldtypes[i]
+            if (isinstance(ftype, model.PrimitiveType)
+                and ftype.is_integer_type()):
+                # accept all integers, but complain on float or double
+                prnt('  (void)((p->%s) << 1);' % fname)
+            else:
+                # only accept exactly the type declared.  Note the parentheses
+                # around the '*tmp' below.  In most cases they are not needed
+                # but don't hurt --- except test_struct_array_field.
+                prnt('  { %s = &p->%s; (void)tmp; }' % (
+                    ftype.get_c_name('(*tmp)'), fname))
+        prnt('}')
         prnt('static PyObject *')
         prnt('_cffi_struct_%s(PyObject *self, PyObject *noarg)' % name)
         prnt('{')
@@ -262,23 +281,8 @@
             prnt('    Py_INCREF(Py_True);')
             prnt('    return Py_True;')
             prnt('  }')
-        prnt('}')
-        prnt('static void _cffi_check_%s(struct %s *p)' % (name, name))
-        prnt('{')
-        prnt('  /* only to generate compile-time warnings or errors */')
-        for i in range(len(tp.fldnames)):
-            fname = tp.fldnames[i]
-            ftype = tp.fldtypes[i]
-            if (isinstance(ftype, model.PrimitiveType)
-                and ftype.is_integer_type()):
-                # accept all integers, but complain on float or double
-                prnt('  (p->%s) << 1;' % fname)
-            else:
-                # only accept exactly the type declared.  Note the parentheses
-                # around the '*tmp' below.  In most cases they are not needed
-                # but don't hurt --- except test_struct_array_field.
-                prnt('  { %s = &p->%s; }' % (
-                    ftype.get_c_name('(*tmp)'), fname))
+        prnt('  /* the next line is not executed, but compiled */')
+        prnt('  %s(0);' % (checkfuncname,))
         prnt('}')
         prnt()
 
@@ -424,10 +428,6 @@
 #  define _cffi_from_c_long_long PyInt_FromLong
 #endif
 
-static PyObject *_cffi_from_c_char(char x) {
-    return PyString_FromStringAndSize(&x, 1);
-}
-
 #define _cffi_to_c_long PyInt_AsLong
 #define _cffi_to_c_double PyFloat_AsDouble
 #define _cffi_to_c_float PyFloat_AsDouble
@@ -469,7 +469,9 @@
     ((void(*)(void))_cffi_exports[13])
 #define _cffi_save_errno                                                 \
     ((void(*)(void))_cffi_exports[14])
-#define _CFFI_NUM_EXPORTS 15
+#define _cffi_from_c_char                                                \
+    ((PyObject *(*)(char))_cffi_exports[15])
+#define _CFFI_NUM_EXPORTS 16
 
 #if SIZEOF_LONG < SIZEOF_LONG_LONG
 #  define _cffi_to_c_long_long PyLong_AsLongLong
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -3,6 +3,13 @@
 from cffi import FFI, VerificationError, VerificationMissing, model
 
 
+class FFI(FFI):
+    def verify(self, *args, **kwds):
+        # XXX a GCC-only way to say "crash upon warnings too"
+        return super(FFI, self).verify(*args, extra_compile_args=['-Werror'],
+                                       **kwds)
+
+
 def test_missing_function():
     ffi = FFI()
     ffi.cdef("void some_completely_unknown_function();")
@@ -93,7 +100,7 @@
 def test_no_argument():
     ffi = FFI()
     ffi.cdef("int foo(void);")
-    lib = ffi.verify("int foo() { return 42; }")
+    lib = ffi.verify("int foo(void) { return 42; }")
     assert lib.foo() == 42
 
 def test_two_arguments():


More information about the pypy-commit mailing list