[pypy-commit] cffi default: Add all standard types from stdint.h. Note that it still fails with

arigo noreply at buildbot.pypy.org
Wed Dec 24 16:27:34 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r1598:ecf4fb44f740
Date: 2014-12-24 16:27 +0100
http://bitbucket.org/cffi/cffi/changeset/ecf4fb44f740/

Log:	Add all standard types from stdint.h. Note that it still fails with
	NotImplementedError if you try to use one of them that would be
	defined, on your platform, as an integer of size not in (1, 2, 4,
	8).

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -27,6 +27,24 @@
    typedef unsigned __int16 uint16_t;
    typedef unsigned __int32 uint32_t;
    typedef unsigned __int64 uint64_t;
+   typedef __int8 int_least8_t;
+   typedef __int16 int_least16_t;
+   typedef __int32 int_least32_t;
+   typedef __int64 int_least64_t;
+   typedef unsigned __int8 uint_least8_t;
+   typedef unsigned __int16 uint_least16_t;
+   typedef unsigned __int32 uint_least32_t;
+   typedef unsigned __int64 uint_least64_t;
+   typedef __int8 int_fast8_t;
+   typedef __int16 int_fast16_t;
+   typedef __int32 int_fast32_t;
+   typedef __int64 int_fast64_t;
+   typedef unsigned __int8 uint_fast8_t;
+   typedef unsigned __int16 uint_fast16_t;
+   typedef unsigned __int32 uint_fast32_t;
+   typedef unsigned __int64 uint_fast64_t;
+   typedef __int64 intmax_t;
+   typedef unsigned __int64 uintmax_t;
 # else
 #  include <stdint.h>
 # endif
@@ -3323,8 +3341,26 @@
        EPTYPE(u32, uint32_t, CT_PRIMITIVE_UNSIGNED)             \
        EPTYPE(i64, int64_t, CT_PRIMITIVE_SIGNED)                \
        EPTYPE(u64, uint64_t, CT_PRIMITIVE_UNSIGNED)             \
+       EPTYPE(il8, int_least8_t, CT_PRIMITIVE_SIGNED)           \
+       EPTYPE(ul8, uint_least8_t, CT_PRIMITIVE_UNSIGNED)        \
+       EPTYPE(il16, int_least16_t, CT_PRIMITIVE_SIGNED)         \
+       EPTYPE(ul16, uint_least16_t, CT_PRIMITIVE_UNSIGNED)      \
+       EPTYPE(il32, int_least32_t, CT_PRIMITIVE_SIGNED)         \
+       EPTYPE(ul32, uint_least32_t, CT_PRIMITIVE_UNSIGNED)      \
+       EPTYPE(il64, int_least64_t, CT_PRIMITIVE_SIGNED)         \
+       EPTYPE(ul64, uint_least64_t, CT_PRIMITIVE_UNSIGNED)      \
+       EPTYPE(if8, int_fast8_t, CT_PRIMITIVE_SIGNED)            \
+       EPTYPE(uf8, uint_fast8_t, CT_PRIMITIVE_UNSIGNED)         \
+       EPTYPE(if16, int_fast16_t, CT_PRIMITIVE_SIGNED)          \
+       EPTYPE(uf16, uint_fast16_t, CT_PRIMITIVE_UNSIGNED)       \
+       EPTYPE(if32, int_fast32_t, CT_PRIMITIVE_SIGNED)          \
+       EPTYPE(uf32, uint_fast32_t, CT_PRIMITIVE_UNSIGNED)       \
+       EPTYPE(if64, int_fast64_t, CT_PRIMITIVE_SIGNED)          \
+       EPTYPE(uf64, uint_fast64_t, CT_PRIMITIVE_UNSIGNED)       \
        EPTYPE(ip, intptr_t, CT_PRIMITIVE_SIGNED)                \
        EPTYPE(up, uintptr_t, CT_PRIMITIVE_UNSIGNED)             \
+       EPTYPE(im, intmax_t, CT_PRIMITIVE_SIGNED)                \
+       EPTYPE(um, uintmax_t, CT_PRIMITIVE_UNSIGNED)             \
        EPTYPE(pd, ptrdiff_t, CT_PRIMITIVE_SIGNED)               \
        EPTYPE(sz, size_t, CT_PRIMITIVE_UNSIGNED)                \
        EPTYPE(ssz, ssize_t, CT_PRIMITIVE_SIGNED)
@@ -3430,7 +3466,8 @@
 
  bad_ffi_type:
     PyErr_Format(PyExc_NotImplementedError,
-                 "primitive type '%s' with a non-standard size %d",
+                 "primitive type '%s' has size %d; "
+                 "the supported sizes are 1, 2, 4, 8",
                  name, (int)ptypes->size);
     return NULL;
 }
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2729,7 +2729,16 @@
 def test_nonstandard_integer_types():
     for typename in ['int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t',
                      'uint32_t', 'int64_t', 'uint64_t', 'intptr_t',
-                     'uintptr_t', 'ptrdiff_t', 'size_t', 'ssize_t']:
+                     'uintptr_t', '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']:
         new_primitive_type(typename)    # works
 
 def test_cannot_convert_unicode_to_charp():


More information about the pypy-commit mailing list