Author: Armin Rigo <[email protected]>
Branch: cpy-extension
Changeset: r305:10a353a730ac
Date: 2012-06-13 17:09 +0200
http://bitbucket.org/cffi/cffi/changeset/10a353a730ac/
Log: Tighter check, also crashing on warnings from the C compiler. More
tests.
diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -19,7 +19,7 @@
self.typesdict[BType] = num
return num
- def verify(self, preamble, **kwargs):
+ def verify(self, preamble, stop_on_warnings=True):
modname = ffiplatform.undercffi_module_name()
filebase = os.path.join(ffiplatform.tmpdir(), modname)
@@ -51,8 +51,11 @@
# XXX use more distutils?
import distutils.sysconfig
python_h = distutils.sysconfig.get_python_inc()
- err = os.system("gcc -I'%s' -O2 -shared -fPIC %s.c -o %s.so" %
- (python_h, filebase, filebase))
+ cmdline = "gcc -I'%s' -O2 -shared -fPIC %s.c -o %s.so" % (
+ python_h, filebase, filebase)
+ if stop_on_warnings:
+ cmdline += " -Werror"
+ err = os.system(cmdline)
if err:
raise ffiplatform.VerificationError(
'%s.c: see compilation errors above' % (filebase,))
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -174,15 +174,32 @@
assert ffi.sizeof('struct foo_s') == 3 * ffi.sizeof('int')
assert ffi.alignof('struct foo_s') == ffi.sizeof('int')
+def _check_field_match(typename, real, expect_mismatch):
+ ffi = FFI()
+ if expect_mismatch == 'by_size':
+ expect_mismatch = ffi.sizeof(typename) != ffi.sizeof(real)
+ ffi.cdef("struct foo_s { %s x; ...; };" % typename)
+ try:
+ ffi.verify("struct foo_s { %s x; };" % real)
+ except VerificationError:
+ if not expect_mismatch:
+ raise AssertionError("unexpected mismatch: %s should be accepted "
+ "as equal to %s" % (typename, real))
+ else:
+ if expect_mismatch:
+ raise AssertionError("mismatch not detected: "
+ "%s != %s" % (typename, real))
+
def test_struct_bad_sized_integer():
for typename in all_signed_integer_types:
for real in all_signed_integer_types:
- ffi = FFI()
- if ffi.sizeof(typename) != ffi.sizeof(real):
- ffi.cdef("struct foo_s { %s x; ...; };" % typename)
- try:
- ffi.verify("struct foo_s { %s x; };" % real)
- except VerificationError:
- pass
- else:
- raise AssertionError("%s != %s" % (typename, real))
+ _check_field_match(typename, real, "by_size")
+
+def test_struct_bad_sized_float():
+ for typename in all_float_types:
+ for real in all_float_types:
+ _check_field_match(typename, real, "by_size")
+
+def test_struct_signedness_ignored():
+ _check_field_match("int", "unsigned int", expect_mismatch=False)
+ _check_field_match("unsigned short", "signed short", expect_mismatch=False)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit