Commits

Armin Rigo  committed 9c76371

Better tests. Fixes.

  • Participants
  • Parent commits 68c0d7f
  • Branches cpy-extension

Comments (0)

Files changed (2)

File cffi/verifier.py

             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)

File testing/test_verify.py

 
 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