[pypy-commit] cffi cffi-1.0: merge heads

arigo noreply at buildbot.pypy.org
Mon Apr 27 23:48:58 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1867:292cb69ac76c
Date: 2015-04-27 23:49 +0200
http://bitbucket.org/cffi/cffi/changeset/292cb69ac76c/

Log:	merge heads

diff --git a/_cffi1/lib_obj.c b/_cffi1/lib_obj.c
--- a/_cffi1/lib_obj.c
+++ b/_cffi1/lib_obj.c
@@ -231,8 +231,7 @@
                             _CFFI_GETARG(g->type_op));
         if (ct == NULL)
             return NULL;
-        if (g->size != ct->ct_size &&
-                g->size != (size_t)-1 && ct->ct_size != -1) {
+        if (g->size != ct->ct_size && g->size != 0 && ct->ct_size > 0) {
             PyErr_Format(FFIError,
                          "global variable '%.200s' should be %zd bytes "
                          "according to the cdef, but is actually %zd",
diff --git a/_cffi1/parse_c_type.h b/_cffi1/parse_c_type.h
--- a/_cffi1/parse_c_type.h
+++ b/_cffi1/parse_c_type.h
@@ -63,8 +63,8 @@
 struct _cffi_global_s {
     const char *name;
     void *address;
-    size_t size;             // -1 if unknown
     _cffi_opcode_t type_op;
+    size_t size;             // 0 if unknown
 };
 
 struct _cffi_struct_union_s {
diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -434,8 +434,7 @@
         else:
             meth_kind = 'V'   # 'METH_VARARGS'
         self._lsts["global"].append(
-            '  { "%s", _cffi_f_%s, (size_t)-1, '
-            '_CFFI_OP(_CFFI_OP_CPYTHON_BLTN_%s, %d) },'
+            '  { "%s", _cffi_f_%s, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_%s, %d), 0 },'
             % (name, name, meth_kind, type_index))
 
     # ----------
@@ -654,8 +653,7 @@
             type_index = self._typesdict[tp]
             type_op = '_CFFI_OP(_CFFI_OP_CONSTANT, %d)' % type_index
         self._lsts["global"].append(
-            '  { "%s", _cffi_const_%s, (size_t)-1, %s },' % 
-            (name, name, type_op))
+            '  { "%s", _cffi_const_%s, %s, 0 },' % (name, name, type_op))
 
     # ----------
     # enums
@@ -672,7 +670,7 @@
         type_op = '_CFFI_OP(_CFFI_OP_ENUM, -1)'
         for enumerator in tp.enumerators:
             self._lsts["global"].append(
-                '  { "%s", _cffi_const_%s, (size_t)-1, %s },' %
+                '  { "%s", _cffi_const_%s, %s, 0 },' %
                 (enumerator, enumerator, type_op))
         #
         if cname is not None and '$' not in cname:
@@ -703,9 +701,8 @@
 
     def _generate_cpy_macro_ctx(self, tp, name):
         self._lsts["global"].append(
-            '  { "%s", _cffi_const_%s, (size_t)-1,'
-            ' _CFFI_OP(_CFFI_OP_CONSTANT_INT, 0) },' %
-            (name, name))
+            '  { "%s", _cffi_const_%s,'
+            ' _CFFI_OP(_CFFI_OP_CONSTANT_INT, 0), 0 },' % (name, name))
 
     # ----------
     # global variables
@@ -728,10 +725,10 @@
         if tp.sizeof_enabled():
             size = "sizeof(%s)" % (name,)
         else:
-            size = "(size_t)-1"
+            size = "0"
         self._lsts["global"].append(
-            '  { "%s", &%s, %s, _CFFI_OP(_CFFI_OP_GLOBAL_VAR, %d)},'
-            % (name, name, size, type_index))
+            '  { "%s", &%s, _CFFI_OP(_CFFI_OP_GLOBAL_VAR, %d), %s },'
+            % (name, name, type_index, size))
 
     # ----------
     # emitting the opcodes for individual types
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -105,8 +105,26 @@
         'uint32_t':           'i',
         'int64_t':            'i',
         'uint64_t':           'i',
+        'int_least8_t':       'i',
+        'uint_least8_t':      'i',
+        'int_least16_t':      'i',
+        'uint_least16_t':     'i',
+        'int_least32_t':      'i',
+        'uint_least32_t':     'i',
+        'int_least64_t':      'i',
+        'uint_least64_t':     'i',
+        'int_fast8_t':        'i',
+        'uint_fast8_t':       'i',
+        'int_fast16_t':       'i',
+        'uint_fast16_t':      'i',
+        'int_fast32_t':       'i',
+        'uint_fast32_t':      'i',
+        'int_fast64_t':       'i',
+        'uint_fast64_t':      'i',
         'intptr_t':           'i',
         'uintptr_t':          'i',
+        'intmax_t':           'i',
+        'uintmax_t':          'i',
         'ptrdiff_t':          'i',
         'size_t':             'i',
         'ssize_t':            'i',
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -1703,5 +1703,3 @@
         assert lib.DOT_HEX == 0x100
         assert lib.DOT_HEX2 == 0x10
         assert lib.DOT_UL == 1000
-
-
diff --git a/testing/test_ffi_backend.py b/testing/test_ffi_backend.py
--- a/testing/test_ffi_backend.py
+++ b/testing/test_ffi_backend.py
@@ -222,3 +222,57 @@
         assert ffi.typeof(c) is ffi.typeof("char[]")
         ffi.cast("unsigned short *", c)[1] += 500
         assert list(a) == [10000, 20500, 30000]
+
+    def test_all_primitives(self):
+        ffi = FFI()
+        for name in [
+            "char",
+            "short",
+            "int",
+            "long",
+            "long long",
+            "signed char",
+            "unsigned char",
+            "unsigned short",
+            "unsigned int",
+            "unsigned long",
+            "unsigned long long",
+            "float",
+            "double",
+            "long double",
+            "wchar_t",
+            "_Bool",
+            "int8_t",
+            "uint8_t",
+            "int16_t",
+            "uint16_t",
+            "int32_t",
+            "uint32_t",
+            "int64_t",
+            "uint64_t",
+            "int_least8_t",
+            "uint_least8_t",
+            "int_least16_t",
+            "uint_least16_t",
+            "int_least32_t",
+            "uint_least32_t",
+            "int_least64_t",
+            "uint_least64_t",
+            "int_fast8_t",
+            "uint_fast8_t",
+            "int_fast16_t",
+            "uint_fast16_t",
+            "int_fast32_t",
+            "uint_fast32_t",
+            "int_fast64_t",
+            "uint_fast64_t",
+            "intptr_t",
+            "uintptr_t",
+            "intmax_t",
+            "uintmax_t",
+            "ptrdiff_t",
+            "size_t",
+            "ssize_t",
+            ]:
+            x = ffi.sizeof(name)
+            assert 1 <= x <= 16


More information about the pypy-commit mailing list