summaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-05-30 13:52:27 +0200
committerArmin Rigo <arigo@tunes.org>2015-05-30 13:52:27 +0200
commit674377bab9c7263eef5774650ce8985aff97bd86 (patch)
tree8df0034154c3670b2ef3f4d9c50474a90d28947a /c
parent4991b58753c3e625d24f95039dce23f03d1b75d5 (diff)
downloadcffi-674377bab9c7263eef5774650ce8985aff97bd86.tar.gz
Tweaks and minor fixes
Diffstat (limited to 'c')
-rw-r--r--c/realize_c_type.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/c/realize_c_type.c b/c/realize_c_type.c
index 0514394..478bd0c 100644
--- a/c/realize_c_type.c
+++ b/c/realize_c_type.c
@@ -14,9 +14,10 @@ static CTypeDescrObject *g_ct_voidp, *g_ct_chararray;
static PyObject *build_primitive_type(int num); /* forward */
+#define primitive_in_range(num) ((num) >= 0 && (num) < _CFFI__NUM_PRIM)
#define get_primitive_type(num) \
- (all_primitives[num] != NULL ? all_primitives[num] \
- : build_primitive_type(num))
+ ((primitive_in_range(num) && all_primitives[num] != NULL) ? \
+ all_primitives[num] : build_primitive_type(num))
static int init_global_types_dict(PyObject *ffi_type_dict)
{
@@ -153,14 +154,18 @@ static PyObject *build_primitive_type(int num)
};
PyObject *x;
+ assert(sizeof(primitive_name) == sizeof(*primitive_name) * _CFFI__NUM_PRIM);
if (num == _CFFI_PRIM_VOID) {
x = new_void_type();
}
- else if (0 <= num &&
- num < sizeof(primitive_name) / sizeof(*primitive_name) &&
- primitive_name[num] != NULL) {
+ else if (primitive_in_range(num) && primitive_name[num] != NULL) {
x = new_primitive_type(primitive_name[num]);
}
+ else if (num == _CFFI__UNKNOWN_PRIM) {
+ PyErr_SetString(FFIError, "primitive integer type with an unexpected "
+ "size (or not an integer type at all)");
+ return NULL;
+ }
else {
PyErr_Format(PyExc_NotImplementedError, "prim=%d", num);
return NULL;