[pypy-commit] cffi cffi-1.0: Add the 0.9.3 integer types

arigo noreply at buildbot.pypy.org
Tue Apr 28 02:15:05 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1868:2fa0c70b8db6
Date: 2015-04-28 02:15 +0200
http://bitbucket.org/cffi/cffi/changeset/2fa0c70b8db6/

Log:	Add the 0.9.3 integer types

diff --git a/_cffi1/cffi_opcode.py b/_cffi1/cffi_opcode.py
--- a/_cffi1/cffi_opcode.py
+++ b/_cffi1/cffi_opcode.py
@@ -62,8 +62,26 @@
 PRIM_PTRDIFF       = 27
 PRIM_SIZE          = 28
 PRIM_SSIZE         = 29
+PRIM_INT_LEAST8    = 30
+PRIM_UINT_LEAST8   = 31
+PRIM_INT_LEAST16   = 32
+PRIM_UINT_LEAST16  = 33
+PRIM_INT_LEAST32   = 34
+PRIM_UINT_LEAST32  = 35
+PRIM_INT_LEAST64   = 36
+PRIM_UINT_LEAST64  = 37
+PRIM_INT_FAST8     = 38
+PRIM_UINT_FAST8    = 39
+PRIM_INT_FAST16    = 40
+PRIM_UINT_FAST16   = 41
+PRIM_INT_FAST32    = 42
+PRIM_UINT_FAST32   = 43
+PRIM_INT_FAST64    = 44
+PRIM_UINT_FAST64   = 45
+PRIM_INTMAX        = 46
+PRIM_UINTMAX       = 47
 
-_NUM_PRIM          = 30
+_NUM_PRIM          = 48
 
 PRIMITIVE_TO_INDEX = {
     'char':               PRIM_CHAR,
@@ -95,6 +113,24 @@
     'ptrdiff_t':          PRIM_PTRDIFF,
     'size_t':             PRIM_SIZE,
     'ssize_t':            PRIM_SSIZE,
+    'int_least8_t':       PRIM_INT_LEAST8,
+    'uint_least8_t':      PRIM_UINT_LEAST8,
+    'int_least16_t':      PRIM_INT_LEAST16,
+    'uint_least16_t':     PRIM_UINT_LEAST16,
+    'int_least32_t':      PRIM_INT_LEAST32,
+    'uint_least32_t':     PRIM_UINT_LEAST32,
+    'int_least64_t':      PRIM_INT_LEAST64,
+    'uint_least64_t':     PRIM_UINT_LEAST64,
+    'int_fast8_t':        PRIM_INT_FAST8,
+    'uint_fast8_t':       PRIM_UINT_FAST8,
+    'int_fast16_t':       PRIM_INT_FAST16,
+    'uint_fast16_t':      PRIM_UINT_FAST16,
+    'int_fast32_t':       PRIM_INT_FAST32,
+    'uint_fast32_t':      PRIM_UINT_FAST32,
+    'int_fast64_t':       PRIM_INT_FAST64,
+    'uint_fast64_t':      PRIM_UINT_FAST64,
+    'intmax_t':           PRIM_INTMAX,
+    'uintmax_t':          PRIM_UINTMAX,
     }
 
 F_UNION         = 0x01
diff --git a/_cffi1/parse_c_type.c b/_cffi1/parse_c_type.c
--- a/_cffi1/parse_c_type.c
+++ b/_cffi1/parse_c_type.c
@@ -459,14 +459,36 @@
         if (size == 7 && !memcmp(p, "uint8", 5)) return _CFFI_PRIM_UINT8;
         break;
 
+    case 'a':
+        if (size == 8 && !memcmp(p, "intmax", 6)) return _CFFI_PRIM_INTMAX;
+        break;
+
     case 'e':
         if (size == 7 && !memcmp(p, "ssize", 5)) return _CFFI_PRIM_SSIZE;
         break;
 
+    case 'f':
+        if (size == 11 && !memcmp(p, "int_fast8",   9)) return _CFFI_PRIM_INT_FAST8;
+        if (size == 12 && !memcmp(p, "int_fast16", 10)) return _CFFI_PRIM_INT_FAST16;
+        if (size == 12 && !memcmp(p, "int_fast32", 10)) return _CFFI_PRIM_INT_FAST32;
+        if (size == 12 && !memcmp(p, "int_fast64", 10)) return _CFFI_PRIM_INT_FAST64;
+        break;
+
     case 'i':
         if (size == 9 && !memcmp(p, "ptrdiff", 7)) return _CFFI_PRIM_PTRDIFF;
         break;
 
+    case 'l':
+        if (size == 12 && !memcmp(p, "int_least8",  10)) return _CFFI_PRIM_INT_LEAST8;
+        if (size == 13 && !memcmp(p, "int_least16", 11)) return _CFFI_PRIM_INT_LEAST16;
+        if (size == 13 && !memcmp(p, "int_least32", 11)) return _CFFI_PRIM_INT_LEAST32;
+        if (size == 13 && !memcmp(p, "int_least64", 11)) return _CFFI_PRIM_INT_LEAST64;
+        break;
+
+    case 'm':
+        if (size == 9 && !memcmp(p, "uintmax", 7)) return _CFFI_PRIM_UINTMAX;
+        break;
+
     case 'p':
         if (size == 9 && !memcmp(p, "uintptr", 7)) return _CFFI_PRIM_UINTPTR;
         break;
@@ -482,6 +504,34 @@
     case '_':
         if (size == 6 && !memcmp(p, "size", 4)) return _CFFI_PRIM_SIZE;
         if (size == 6 && !memcmp(p, "int8", 4)) return _CFFI_PRIM_INT8;
+        if (size >= 12) {
+            switch (p[10]) {
+            case '1':
+                if (size == 14 && !memcmp(p, "uint_least16", 12)) return _CFFI_PRIM_UINT_LEAST16;
+                break;
+            case '2':
+                if (size == 13 && !memcmp(p, "uint_fast32", 11)) return _CFFI_PRIM_UINT_FAST32;
+                break;
+            case '3':
+                if (size == 14 && !memcmp(p, "uint_least32", 12)) return _CFFI_PRIM_UINT_LEAST32;
+                break;
+            case '4':
+                if (size == 13 && !memcmp(p, "uint_fast64", 11)) return _CFFI_PRIM_UINT_FAST64;
+                break;
+            case '6':
+                if (size == 14 && !memcmp(p, "uint_least64", 12)) return _CFFI_PRIM_UINT_LEAST64;
+                if (size == 13 && !memcmp(p, "uint_fast16", 11)) return _CFFI_PRIM_UINT_FAST16;
+                break;
+            case '8':
+                if (size == 13 && !memcmp(p, "uint_least8", 11)) return _CFFI_PRIM_UINT_LEAST8;
+                break;
+            case '_':
+                if (size == 12 && !memcmp(p, "uint_fast8", 10)) return _CFFI_PRIM_UINT_FAST8;
+                break;
+            default:
+                break;
+            }
+        }
         break;
 
     default:
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
@@ -56,8 +56,26 @@
 #define _CFFI_PRIM_PTRDIFF      27
 #define _CFFI_PRIM_SIZE         28
 #define _CFFI_PRIM_SSIZE        29
+#define _CFFI_PRIM_INT_LEAST8   30
+#define _CFFI_PRIM_UINT_LEAST8  31
+#define _CFFI_PRIM_INT_LEAST16  32
+#define _CFFI_PRIM_UINT_LEAST16 33
+#define _CFFI_PRIM_INT_LEAST32  34
+#define _CFFI_PRIM_UINT_LEAST32 35
+#define _CFFI_PRIM_INT_LEAST64  36
+#define _CFFI_PRIM_UINT_LEAST64 37
+#define _CFFI_PRIM_INT_FAST8    38
+#define _CFFI_PRIM_UINT_FAST8   39
+#define _CFFI_PRIM_INT_FAST16   40
+#define _CFFI_PRIM_UINT_FAST16  41
+#define _CFFI_PRIM_INT_FAST32   42
+#define _CFFI_PRIM_UINT_FAST32  43
+#define _CFFI_PRIM_INT_FAST64   44
+#define _CFFI_PRIM_UINT_FAST64  45
+#define _CFFI_PRIM_INTMAX       46
+#define _CFFI_PRIM_UINTMAX      47
 
-#define _CFFI__NUM_PRIM         30
+#define _CFFI__NUM_PRIM         48
 
 
 struct _cffi_global_s {
diff --git a/_cffi1/realize_c_type.c b/_cffi1/realize_c_type.c
--- a/_cffi1/realize_c_type.c
+++ b/_cffi1/realize_c_type.c
@@ -146,6 +146,24 @@
         "ptrdiff_t",
         "size_t",
         "ssize_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",
+        "intmax_t",
+        "uintmax_t",
     };
     PyObject *x;
 
diff --git a/_cffi1/test_new_ffi_1.py b/_cffi1/test_new_ffi_1.py
--- a/_cffi1/test_new_ffi_1.py
+++ b/_cffi1/test_new_ffi_1.py
@@ -1613,3 +1613,58 @@
         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):
+        from .cffi_opcode import PRIMITIVE_TO_INDEX
+        assert set(PRIMITIVE_TO_INDEX) == set([
+            "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",
+            ])
+        for name in PRIMITIVE_TO_INDEX:
+            x = ffi.sizeof(name)
+            assert 1 <= x <= 16


More information about the pypy-commit mailing list