summaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2014-12-24 16:27:54 +0100
committerArmin Rigo <arigo@tunes.org>2014-12-24 16:27:54 +0100
commit38f5eefbed785b6e612fdbadf2783fde7007c0ee (patch)
treeaf2a9625b7d08bc6f894623d30eb6e1855952a77 /c
parentc46d3a66e04c8c21cc01e3c2f611f474a1d9d837 (diff)
downloadcffi-38f5eefbed785b6e612fdbadf2783fde7007c0ee.tar.gz
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).
Diffstat (limited to 'c')
-rw-r--r--c/_cffi_backend.c39
-rw-r--r--c/test_c.py11
2 files changed, 48 insertions, 2 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
index acc6913..b2d46c7 100644
--- 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 @@ static PyObject *b_new_primitive_type(PyObject *self, PyObject *args)
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 @@ static PyObject *b_new_primitive_type(PyObject *self, PyObject *args)
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
index baca987..745558a 100644
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2729,7 +2729,16 @@ def test_GetLastError():
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():