[pypy-commit] cffi cpy-extension: Better tests. Fixes.

arigo noreply at buildbot.pypy.org
Thu Jun 14 10:04:18 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: cpy-extension
Changeset: r318:9c76371c844c
Date: 2012-06-14 10:04 +0200
http://bitbucket.org/cffi/cffi/changeset/9c76371c844c/

Log:	Better tests. Fixes.

diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -330,12 +330,13 @@
             prnt('  i = (%s);' % (name,))
             prnt('  o = %s;' % (self.convert_expr_from_c(tp, 'i'),))
         else:
-            prnt('  if ((%s) == (long)(%s))' % (name, name))
+            prnt('  if (LONG_MIN <= (%s) && (%s) <= LONG_MAX)' % (name, name))
             prnt('    o = PyInt_FromLong((long)(%s));' % (name,))
-            prnt('  else if ((%s) == (long long)(%s))' % (name, name))
+            prnt('  else if ((%s) < 0)' % (name,))
             prnt('    o = PyLong_FromLongLong((long long)(%s));' % (name,))
             prnt('  else')
-            prnt('    o = PyLong_FromUnsignedLongLong(%s);' % (name,))
+            prnt('    o = PyLong_FromUnsignedLongLong((unsigned long long)%s);'
+                 % (name,))
         prnt('  if (o == NULL)')
         prnt('    return -1;')
         prnt('  res = PyDict_SetItemString(dct, "%s", o);' % name)
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -252,15 +252,19 @@
 
 def test_global_const_int_size():
     # integer constants: ignore the declared type, always just use the value
-    for value in [-2**80, -2**40, -2**20, -2**10, -2**5, -1,
-                  2**5, 2**10, 2**20, 2**40, 2**80]:
+    for value in [-2**63, -2**31, -2**15,
+                  2**15-1, 2**15, 2**31-1, 2**31, 2**32-1, 2**32,
+                  2**63-1, 2**63, 2**64-1]:
         ffi = FFI()
         if value == int(ffi.cast("long long", value)):
-            vstr = '%dLL' % value
+            if value < 0:
+                vstr = '(-%dLL-1)' % (~value,)
+            else:
+                vstr = '%dLL' % value
         elif value == int(ffi.cast("unsigned long long", value)):
             vstr = '%dULL' % value
         else:
-            continue
+            raise AssertionError(value)
         ffi.cdef("static const unsigned short AA;")
         lib = ffi.verify("#define AA %s\n" % vstr)
         assert lib.AA == value


More information about the pypy-commit mailing list