diff options
Diffstat (limited to 'ext/ffi/ffi.c')
-rw-r--r-- | ext/ffi/ffi.c | 66 |
1 files changed, 7 insertions, 59 deletions
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 2ca1cad90d..ff785065fd 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -295,56 +295,13 @@ static int zend_ffi_is_compatible_type(zend_ffi_type *dst_type, zend_ffi_type *s static ffi_type *zend_ffi_make_fake_struct_type(zend_ffi_type *type) /* {{{ */ { - ffi_type *t = emalloc(sizeof(ffi_type) + sizeof(ffi_type*) * (zend_hash_num_elements(&type->record.fields) + 1)); - int i; - zend_ffi_field *field; + ffi_type *t = emalloc(sizeof(ffi_type) + sizeof(ffi_type*)); t->size = type->size; t->alignment = type->align; t->type = FFI_TYPE_STRUCT; t->elements = (ffi_type**)(t + 1); - i = 0; - ZEND_HASH_FOREACH_PTR(&type->record.fields, field) { - switch (ZEND_FFI_TYPE(field->type)->kind) { - case ZEND_FFI_TYPE_FLOAT: - t->elements[i] = &ffi_type_float; - break; - case ZEND_FFI_TYPE_DOUBLE: - t->elements[i] = &ffi_type_double; - break; -#ifdef HAVE_LONG_DOUBLE - case ZEND_FFI_TYPE_LONGDOUBLE: - t->elements[i] = &ffi_type_longdouble; - break; -#endif - case ZEND_FFI_TYPE_SINT8: - case ZEND_FFI_TYPE_UINT8: - case ZEND_FFI_TYPE_BOOL: - case ZEND_FFI_TYPE_CHAR: - t->elements[i] = &ffi_type_uint8; - break; - case ZEND_FFI_TYPE_SINT16: - case ZEND_FFI_TYPE_UINT16: - t->elements[i] = &ffi_type_uint16; - break; - case ZEND_FFI_TYPE_SINT32: - case ZEND_FFI_TYPE_UINT32: - t->elements[i] = &ffi_type_uint32; - break; - case ZEND_FFI_TYPE_SINT64: - case ZEND_FFI_TYPE_UINT64: - t->elements[i] = &ffi_type_uint64; - break; - case ZEND_FFI_TYPE_POINTER: - t->elements[i] = &ffi_type_pointer; - break; - default: - efree(t); - return NULL; - } - i++; - } ZEND_HASH_FOREACH_END(); - t->elements[i] = NULL; + t->elements[0] = NULL; return t; } /* }}} */ @@ -391,11 +348,7 @@ again: kind = type->enumeration.kind; goto again; case ZEND_FFI_TYPE_STRUCT: - if (!(type->attr & ZEND_FFI_ATTR_UNION)) { - ffi_type *t = zend_ffi_make_fake_struct_type(type); - return t; - } - break; + return zend_ffi_make_fake_struct_type(type); default: break; } @@ -2534,18 +2487,13 @@ again: kind = type->enumeration.kind; goto again; case ZEND_FFI_TYPE_STRUCT: - if (!(type->attr & ZEND_FFI_ATTR_UNION) - && Z_TYPE_P(arg) == IS_OBJECT && Z_OBJCE_P(arg) == zend_ffi_cdata_ce) { + if (Z_TYPE_P(arg) == IS_OBJECT && Z_OBJCE_P(arg) == zend_ffi_cdata_ce) { zend_ffi_cdata *cdata = (zend_ffi_cdata*)Z_OBJ_P(arg); if (zend_ffi_is_compatible_type(type, ZEND_FFI_TYPE(cdata->type))) { - /* Create a fake structure type */ - ffi_type *t = zend_ffi_make_fake_struct_type(type); - if (t) { - *pass_type = t; - arg_values[n] = cdata->ptr; - break; - } + *pass_type = zend_ffi_make_fake_struct_type(type);; + arg_values[n] = cdata->ptr; + break; } } zend_ffi_pass_incompatible(arg, type, n, execute_data); |