Lines Matching refs:type

64 	zend_ffi_type         *type;  member
108 zend_ffi_type *type; member
112 zend_ffi_type *type; member
132 zend_ffi_type *type; member
145 zend_ffi_type *type; member
181 zend_ffi_type *type; member
189 zend_ffi_type *type; member
209 static void _zend_ffi_type_dtor(zend_ffi_type *type);
212 static zend_ffi_type *zend_ffi_remember_type(zend_ffi_type *type);
215 static ZEND_COLD void zend_ffi_return_unsupported(zend_ffi_type *type);
216 static ZEND_COLD void zend_ffi_pass_unsupported(zend_ffi_type *type);
217 static ZEND_COLD void zend_ffi_assign_incompatible(zval *arg, zend_ffi_type *type);
220 static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value);
223 static zend_always_inline void zend_ffi_type_dtor(zend_ffi_type *type) /* {{{ */ in zend_ffi_type_dtor() argument
225 if (UNEXPECTED(ZEND_FFI_TYPE_IS_OWNED(type))) { in zend_ffi_type_dtor()
226 _zend_ffi_type_dtor(type); in zend_ffi_type_dtor()
251 cdata->type = NULL; in zend_ffi_cdata_new()
268 dst_type = ZEND_FFI_TYPE(dst_type->pointer.type); in zend_ffi_is_compatible_type()
269 src_type = ZEND_FFI_TYPE(src_type->pointer.type); in zend_ffi_is_compatible_type()
277 dst_type = ZEND_FFI_TYPE(dst_type->array.type); in zend_ffi_is_compatible_type()
278 src_type = ZEND_FFI_TYPE(src_type->array.type); in zend_ffi_is_compatible_type()
284 dst_type = ZEND_FFI_TYPE(dst_type->pointer.type); in zend_ffi_is_compatible_type()
285 src_type = ZEND_FFI_TYPE(src_type->array.type); in zend_ffi_is_compatible_type()
297 static ffi_type *zend_ffi_make_fake_struct_type(zend_ffi_type *type) /* {{{ */ in zend_ffi_make_fake_struct_type() argument
299 …ffi_type *t = emalloc(sizeof(ffi_type) + sizeof(ffi_type*) * (zend_hash_num_elements(&type->record… in zend_ffi_make_fake_struct_type()
303 t->size = type->size; in zend_ffi_make_fake_struct_type()
304 t->alignment = type->align; in zend_ffi_make_fake_struct_type()
305 t->type = FFI_TYPE_STRUCT; in zend_ffi_make_fake_struct_type()
308 ZEND_HASH_FOREACH_PTR(&type->record.fields, field) { in zend_ffi_make_fake_struct_type()
309 switch (ZEND_FFI_TYPE(field->type)->kind) { in zend_ffi_make_fake_struct_type()
353 static ffi_type *zend_ffi_get_type(zend_ffi_type *type) /* {{{ */ in zend_ffi_get_type() argument
355 zend_ffi_type_kind kind = type->kind; in zend_ffi_get_type()
392 kind = type->enumeration.kind; in zend_ffi_get_type()
395 if (!(type->attr & ZEND_FFI_ATTR_UNION)) { in zend_ffi_get_type()
396 ffi_type *t = zend_ffi_make_fake_struct_type(type); in zend_ffi_get_type()
407 static zend_never_inline zend_ffi_cdata *zend_ffi_cdata_to_zval_slow(void *ptr, zend_ffi_type *type in zend_ffi_cdata_to_zval_slow() argument
413 (type->kind < ZEND_FFI_TYPE_POINTER) ? in zend_ffi_cdata_to_zval_slow()
416 cdata->type = type; in zend_ffi_cdata_to_zval_slow()
423 …zend_ffi_cdata *zend_ffi_cdata_to_zval_slow_ptr(void *ptr, zend_ffi_type *type, zend_ffi_flags fla… in zend_ffi_cdata_to_zval_slow_ptr() argument
429 cdata->type = type; in zend_ffi_cdata_to_zval_slow_ptr()
437 …zend_ffi_cdata *zend_ffi_cdata_to_zval_slow_ret(void *ptr, zend_ffi_type *type, zend_ffi_flags fla… in zend_ffi_cdata_to_zval_slow_ret() argument
443 (type->kind < ZEND_FFI_TYPE_POINTER) ? in zend_ffi_cdata_to_zval_slow_ret()
446 cdata->type = type; in zend_ffi_cdata_to_zval_slow_ret()
448 if (type->kind == ZEND_FFI_TYPE_POINTER) { in zend_ffi_cdata_to_zval_slow_ret()
451 } else if (type->kind == ZEND_FFI_TYPE_STRUCT) { in zend_ffi_cdata_to_zval_slow_ret()
452 cdata->ptr = emalloc(type->size); in zend_ffi_cdata_to_zval_slow_ret()
454 memcpy(cdata->ptr, ptr, type->size); in zend_ffi_cdata_to_zval_slow_ret()
462 …d zend_ffi_cdata_to_zval(zend_ffi_cdata *cdata, void *ptr, zend_ffi_type *type, int read_type, zva… in zend_ffi_cdata_to_zval() argument
465 zend_ffi_type_kind kind = type->kind; in zend_ffi_cdata_to_zval()
511 kind = type->enumeration.kind; in zend_ffi_cdata_to_zval()
520 …} else if ((type->attr & ZEND_FFI_ATTR_CONST) && ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_F… in zend_ffi_cdata_to_zval()
526 cdata = zend_ffi_cdata_to_zval_slow_ret(ptr, type, flags); in zend_ffi_cdata_to_zval()
528 cdata = zend_ffi_cdata_to_zval_slow_ptr(ptr, type, flags); in zend_ffi_cdata_to_zval()
542 cdata = zend_ffi_cdata_to_zval_slow_ret(ptr, type, flags); in zend_ffi_cdata_to_zval()
544 cdata = zend_ffi_cdata_to_zval_slow(ptr, type, flags); in zend_ffi_cdata_to_zval()
598 if (ZEND_FFI_TYPE(field->type)->kind == ZEND_FFI_TYPE_CHAR in zend_ffi_bit_field_to_zval()
599 || ZEND_FFI_TYPE(field->type)->kind == ZEND_FFI_TYPE_SINT8 in zend_ffi_bit_field_to_zval()
600 || ZEND_FFI_TYPE(field->type)->kind == ZEND_FFI_TYPE_SINT16 in zend_ffi_bit_field_to_zval()
601 || ZEND_FFI_TYPE(field->type)->kind == ZEND_FFI_TYPE_SINT32 in zend_ffi_bit_field_to_zval()
602 || ZEND_FFI_TYPE(field->type)->kind == ZEND_FFI_TYPE_SINT64) { in zend_ffi_bit_field_to_zval()
656 static zend_always_inline int zend_ffi_zval_to_cdata(void *ptr, zend_ffi_type *type, zval *value) /… in zend_ffi_zval_to_cdata() argument
662 zend_ffi_type_kind kind = type->kind; in zend_ffi_zval_to_cdata()
720 zend_ffi_assign_incompatible(value, type); in zend_ffi_zval_to_cdata()
726 kind = type->enumeration.kind; in zend_ffi_zval_to_cdata()
735 if (zend_ffi_is_compatible_type(type, ZEND_FFI_TYPE(cdata->type))) { in zend_ffi_zval_to_cdata()
736 if (ZEND_FFI_TYPE(cdata->type)->kind == ZEND_FFI_TYPE_POINTER) { in zend_ffi_zval_to_cdata()
747 } else if (ZEND_FFI_TYPE(cdata->type)->kind != ZEND_FFI_TYPE_POINTER in zend_ffi_zval_to_cdata()
748 … && zend_ffi_is_compatible_type(ZEND_FFI_TYPE(type->pointer.type), ZEND_FFI_TYPE(cdata->type))) { in zend_ffi_zval_to_cdata()
757 } else if (ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_FFI_TYPE_FUNC) { in zend_ffi_zval_to_cdata()
758 void *callback = zend_ffi_create_callback(ZEND_FFI_TYPE(type->pointer.type), value); in zend_ffi_zval_to_cdata()
768 zend_ffi_assign_incompatible(value, type); in zend_ffi_zval_to_cdata()
775 if (zend_ffi_is_compatible_type(type, ZEND_FFI_TYPE(cdata->type)) && in zend_ffi_zval_to_cdata()
776 type->size == ZEND_FFI_TYPE(cdata->type)->size) { in zend_ffi_zval_to_cdata()
777 memcpy(ptr, cdata->ptr, type->size); in zend_ffi_zval_to_cdata()
781 zend_ffi_assign_incompatible(value, type); in zend_ffi_zval_to_cdata()
789 static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */ in zend_ffi_arg_size() argument
794 ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { in zend_ffi_arg_size()
802 …ys_inline zend_string *zend_ffi_mangled_func_name(zend_string *name, zend_ffi_type *type) /* {{{ */ in zend_ffi_mangled_func_name() argument
805 switch (type->func.abi) { in zend_ffi_mangled_func_name()
808 return strpprintf(0, "@%s@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type)); in zend_ffi_mangled_func_name()
812 return strpprintf(0, "_%s@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type)); in zend_ffi_mangled_func_name()
816 return strpprintf(0, "%s@@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type)); in zend_ffi_mangled_func_name()
827 zend_ffi_type *type; member
864 if (callback_data->type->func.args) { in zend_ffi_callback_trampoline()
868 ZEND_HASH_FOREACH_PTR(callback_data->type->func.args, arg_type) { in zend_ffi_callback_trampoline()
893 ret_type = ZEND_FFI_TYPE(callback_data->type->func.ret_type); in zend_ffi_callback_trampoline()
900 static void *zend_ffi_create_callback(zend_ffi_type *type, zval *value) /* {{{ */ in zend_ffi_create_callback() argument
909 if (type->attr & ZEND_FFI_ATTR_VARIADIC) { in zend_ffi_create_callback()
919 arg_count = type->func.args ? zend_hash_num_elements(type->func.args) : 0; in zend_ffi_create_callback()
933 callback_data->type = type; in zend_ffi_create_callback()
938 if (type->func.args) { in zend_ffi_create_callback()
942 ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { in zend_ffi_create_callback()
954 callback_data->ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); in zend_ffi_create_callback()
956 zend_ffi_return_unsupported(type->func.ret_type); in zend_ffi_create_callback()
962 …if (ffi_prep_cif(&callback_data->cif, type->func.abi, callback_data->arg_count, callback_data->ret… in zend_ffi_create_callback()
994 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_get() local
1009 zend_ffi_cdata_to_zval(cdata, cdata->ptr, type, BP_VAR_R, rv, 0, 0, 0); in zend_ffi_cdata_get()
1017 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_set() local
1032 zend_ffi_zval_to_cdata(cdata->ptr, type, value); in zend_ffi_cdata_set()
1038 static int zend_ffi_cdata_cast_object(zval *readobj, zval *writeobj, int type) /* {{{ */ in zend_ffi_cdata_cast_object() argument
1040 if (type == IS_STRING) { in zend_ffi_cdata_cast_object()
1042 zend_ffi_type *ctype = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_cast_object()
1096 …} else if ((ctype->attr & ZEND_FFI_ATTR_CONST) && ZEND_FFI_TYPE(ctype->pointer.type)->kind == ZEND… in zend_ffi_cdata_cast_object()
1115 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_read_field() local
1119 if (cache_slot && *cache_slot == type) { in zend_ffi_cdata_read_field()
1125 if (UNEXPECTED(type->kind != ZEND_FFI_TYPE_STRUCT)) { in zend_ffi_cdata_read_field()
1126 if (type->kind == ZEND_FFI_TYPE_POINTER) { in zend_ffi_cdata_read_field()
1139 type = ZEND_FFI_TYPE(type->pointer.type); in zend_ffi_cdata_read_field()
1141 if (UNEXPECTED(type->kind != ZEND_FFI_TYPE_STRUCT)) { in zend_ffi_cdata_read_field()
1148 field = zend_hash_find_ptr(&type->record.fields, field_name); in zend_ffi_cdata_read_field()
1158 *cache_slot = type; in zend_ffi_cdata_read_field()
1171 zend_ffi_type *field_type = field->type; in zend_ffi_cdata_read_field()
1177 field->type = field_type = zend_ffi_remember_type(field_type); in zend_ffi_cdata_read_field()
1193 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_write_field() local
1197 if (cache_slot && *cache_slot == type) { in zend_ffi_cdata_write_field()
1203 if (UNEXPECTED(type->kind != ZEND_FFI_TYPE_STRUCT)) { in zend_ffi_cdata_write_field()
1204 if (type->kind == ZEND_FFI_TYPE_POINTER) { in zend_ffi_cdata_write_field()
1217 type = ZEND_FFI_TYPE(type->pointer.type); in zend_ffi_cdata_write_field()
1219 if (UNEXPECTED(type->kind != ZEND_FFI_TYPE_STRUCT)) { in zend_ffi_cdata_write_field()
1226 field = zend_hash_find_ptr(&type->record.fields, field_name); in zend_ffi_cdata_write_field()
1236 *cache_slot = type; in zend_ffi_cdata_write_field()
1261 zend_ffi_zval_to_cdata(ptr, ZEND_FFI_TYPE(field->type), value); in zend_ffi_cdata_write_field()
1272 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_read_dim() local
1278 if (EXPECTED(type->kind == ZEND_FFI_TYPE_ARRAY)) { in zend_ffi_cdata_read_dim()
1279 if (UNEXPECTED((zend_ulong)(dim) >= (zend_ulong)type->array.length) in zend_ffi_cdata_read_dim()
1280 && (UNEXPECTED(dim < 0) || UNEXPECTED(type->array.length != 0))) { in zend_ffi_cdata_read_dim()
1285 …is_const = (cdata->flags & ZEND_FFI_FLAG_CONST) | (zend_ffi_flags)(type->attr & ZEND_FFI_ATTR_CONS… in zend_ffi_cdata_read_dim()
1287 dim_type = type->array.type; in zend_ffi_cdata_read_dim()
1292 type->array.type = dim_type = zend_ffi_remember_type(dim_type); in zend_ffi_cdata_read_dim()
1302 } else if (EXPECTED(type->kind == ZEND_FFI_TYPE_POINTER)) { in zend_ffi_cdata_read_dim()
1303 …is_const = (cdata->flags & ZEND_FFI_FLAG_CONST) | (zend_ffi_flags)(type->attr & ZEND_FFI_ATTR_CONS… in zend_ffi_cdata_read_dim()
1304 dim_type = type->pointer.type; in zend_ffi_cdata_read_dim()
1309 type->pointer.type = dim_type = zend_ffi_remember_type(dim_type); in zend_ffi_cdata_read_dim()
1330 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_write_dim() local
1341 if (EXPECTED(type->kind == ZEND_FFI_TYPE_ARRAY)) { in zend_ffi_cdata_write_dim()
1342 if (UNEXPECTED((zend_ulong)(dim) >= (zend_ulong)type->array.length) in zend_ffi_cdata_write_dim()
1343 && (UNEXPECTED(dim < 0) || UNEXPECTED(type->array.length != 0))) { in zend_ffi_cdata_write_dim()
1348 …is_const = (cdata->flags & ZEND_FFI_FLAG_CONST) | (zend_ffi_flags)(type->attr & ZEND_FFI_ATTR_CONS… in zend_ffi_cdata_write_dim()
1349 type = ZEND_FFI_TYPE(type->array.type); in zend_ffi_cdata_write_dim()
1356 ptr = (void*)(((char*)cdata->ptr) + type->size * dim); in zend_ffi_cdata_write_dim()
1357 } else if (EXPECTED(type->kind == ZEND_FFI_TYPE_POINTER)) { in zend_ffi_cdata_write_dim()
1358 …is_const = (cdata->flags & ZEND_FFI_FLAG_CONST) | (zend_ffi_flags)(type->attr & ZEND_FFI_ATTR_CONS… in zend_ffi_cdata_write_dim()
1359 type = ZEND_FFI_TYPE(type->pointer.type); in zend_ffi_cdata_write_dim()
1364 ptr = (void*)((*(char**)cdata->ptr) + type->size * dim); in zend_ffi_cdata_write_dim()
1375 zend_ffi_zval_to_cdata(ptr, type, value); in zend_ffi_cdata_write_dim()
1409 static int zend_ffi_ctype_name(zend_ffi_ctype_name_buf *buf, const zend_ffi_type *type) /* {{{ */ in zend_ffi_ctype_name() argument
1415 switch (type->kind) { in zend_ffi_ctype_name()
1455 if (type->enumeration.tag_name) { in zend_ffi_ctype_name()
1456 …zend_ffi_ctype_name_prepend(buf, ZSTR_VAL(type->enumeration.tag_name), ZSTR_LEN(type->enumeration.… in zend_ffi_ctype_name()
1473 type = ZEND_FFI_TYPE(type->pointer.type); in zend_ffi_ctype_name()
1487 type = ZEND_FFI_TYPE(type->func.ret_type); in zend_ffi_ctype_name()
1500 if (type->attr & ZEND_FFI_ATTR_VLA) { in zend_ffi_ctype_name()
1504 } else if (!(type->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY)) { in zend_ffi_ctype_name()
1506 char *s = zend_print_long_to_buf(str + sizeof(str) - 1, type->array.length); in zend_ffi_ctype_name()
1515 type = ZEND_FFI_TYPE(type->array.type); in zend_ffi_ctype_name()
1518 if (type->attr & ZEND_FFI_ATTR_UNION) { in zend_ffi_ctype_name()
1519 if (type->record.tag_name) { in zend_ffi_ctype_name()
1520 …zend_ffi_ctype_name_prepend(buf, ZSTR_VAL(type->record.tag_name), ZSTR_LEN(type->record.tag_name)); in zend_ffi_ctype_name()
1526 if (type->record.tag_name) { in zend_ffi_ctype_name()
1527 …zend_ffi_ctype_name_prepend(buf, ZSTR_VAL(type->record.tag_name), ZSTR_LEN(type->record.tag_name)); in zend_ffi_ctype_name()
1551 static ZEND_COLD void zend_ffi_return_unsupported(zend_ffi_type *type) /* {{{ */ in zend_ffi_return_unsupported() argument
1553 type = ZEND_FFI_TYPE(type); in zend_ffi_return_unsupported()
1554 if (type->kind == ZEND_FFI_TYPE_STRUCT) { in zend_ffi_return_unsupported()
1556 } else if (type->kind == ZEND_FFI_TYPE_ARRAY) { in zend_ffi_return_unsupported()
1564 static ZEND_COLD void zend_ffi_pass_unsupported(zend_ffi_type *type) /* {{{ */ in zend_ffi_pass_unsupported() argument
1566 type = ZEND_FFI_TYPE(type); in zend_ffi_pass_unsupported()
1567 if (type->kind == ZEND_FFI_TYPE_STRUCT) { in zend_ffi_pass_unsupported()
1569 } else if (type->kind == ZEND_FFI_TYPE_ARRAY) { in zend_ffi_pass_unsupported()
1577 static ZEND_COLD void zend_ffi_pass_incompatible(zval *arg, zend_ffi_type *type, uint32_t n, zend_e… in zend_ffi_pass_incompatible() argument
1582 if (!zend_ffi_ctype_name(&buf1, type)) { in zend_ffi_pass_incompatible()
1589 type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_pass_incompatible()
1591 if (!zend_ffi_ctype_name(&buf2, type)) { in zend_ffi_pass_incompatible()
1604 static ZEND_COLD void zend_ffi_assign_incompatible(zval *arg, zend_ffi_type *type) /* {{{ */ in zend_ffi_assign_incompatible() argument
1609 if (!zend_ffi_ctype_name(&buf1, type)) { in zend_ffi_assign_incompatible()
1616 type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_assign_incompatible()
1618 if (!zend_ffi_ctype_name(&buf2, type)) { in zend_ffi_assign_incompatible()
1631 static zend_string *zend_ffi_get_class_name(zend_string *prefix, const zend_ffi_type *type) /* {{{ … in zend_ffi_get_class_name() argument
1636 if (!zend_ffi_ctype_name(&buf, type)) { in zend_ffi_get_class_name()
1653 return zend_ffi_get_class_name(zobj->ce->name, ZEND_FFI_TYPE(cdata->type)); in zend_ffi_cdata_get_class_name()
1663 zend_ffi_type *type1 = ZEND_FFI_TYPE(cdata1->type); in zend_ffi_cdata_compare_objects()
1664 zend_ffi_type *type2 = ZEND_FFI_TYPE(cdata2->type); in zend_ffi_cdata_compare_objects()
1685 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_count_elements() local
1687 if (type->kind != ZEND_FFI_TYPE_ARRAY) { in zend_ffi_cdata_count_elements()
1691 *count = type->array.length; in zend_ffi_cdata_count_elements()
1705 if (ZEND_FFI_TYPE_IS_OWNED(base_cdata->type)) { in zend_ffi_add()
1709 base_cdata->type = base_type; in zend_ffi_add()
1712 base_cdata->type = base_type = zend_ffi_remember_type(base_type); in zend_ffi_add()
1716 cdata->type = base_type; in zend_ffi_add()
1718 ptr_type = ZEND_FFI_TYPE(base_type)->pointer.type; in zend_ffi_add()
1727 ptr_type = base_type->array.type; in zend_ffi_add()
1733 base_type->array.type = ptr_type; in zend_ffi_add()
1736 base_type->array.type = ptr_type = zend_ffi_remember_type(ptr_type); in zend_ffi_add()
1740 new_type->pointer.type = ptr_type; in zend_ffi_add()
1742 cdata->type = ZEND_FFI_TYPE_MAKE_OWNED(new_type); in zend_ffi_add()
1761 zend_ffi_type *type1 = ZEND_FFI_TYPE(cdata1->type); in zend_ffi_cdata_do_operation()
1774 zend_ffi_type *type2 = ZEND_FFI_TYPE(cdata2->type); in zend_ffi_cdata_do_operation()
1781 t1 = ZEND_FFI_TYPE(type1->pointer.type); in zend_ffi_cdata_do_operation()
1784 t1 = ZEND_FFI_TYPE(type1->array.type); in zend_ffi_cdata_do_operation()
1788 t2 = ZEND_FFI_TYPE(type2->pointer.type); in zend_ffi_cdata_do_operation()
1791 t2 = ZEND_FFI_TYPE(type2->array.type); in zend_ffi_cdata_do_operation()
1811 zend_ffi_type *type2 = ZEND_FFI_TYPE(cdata2->type); in zend_ffi_cdata_do_operation()
1844 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_it_valid() local
1846 return (iter->key >= 0 && iter->key < type->array.length) ? SUCCESS : FAILURE; in zend_ffi_cdata_it_valid()
1854 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_it_get_current_data() local
1862 dim_type = type->array.type; in zend_ffi_cdata_it_get_current_data()
1867 type->array.type = dim_type = zend_ffi_remember_type(dim_type); in zend_ffi_cdata_it_get_current_data()
1873 …_R, &iter->value, (cdata->flags & ZEND_FFI_FLAG_CONST) | (zend_ffi_flags)(type->attr & ZEND_FFI_AT… in zend_ffi_cdata_it_get_current_data()
1912 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_get_iterator() local
1915 if (type->kind != ZEND_FFI_TYPE_ARRAY) { in zend_ffi_cdata_get_iterator()
1938 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_get_debug_info() local
1951 switch (type->kind) { in zend_ffi_cdata_get_debug_info()
1968 zend_ffi_cdata_to_zval(cdata, ptr, type, BP_VAR_R, &tmp, ZEND_FFI_FLAG_CONST, 0, 0); in zend_ffi_cdata_get_debug_info()
1981 } else if (ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_FFI_TYPE_VOID) { in zend_ffi_cdata_get_debug_info()
1988 …zend_ffi_cdata_to_zval(NULL, *(void**)ptr, ZEND_FFI_TYPE(type->pointer.type), BP_VAR_R, &tmp, ZEND… in zend_ffi_cdata_get_debug_info()
1996 ht = zend_new_array(zend_hash_num_elements(&type->record.fields)); in zend_ffi_cdata_get_debug_info()
1997 ZEND_HASH_FOREACH_STR_KEY_PTR(&type->record.fields, key, f) { in zend_ffi_cdata_get_debug_info()
2001 …nd_ffi_cdata_to_zval(NULL, f_ptr, ZEND_FFI_TYPE(f->type), BP_VAR_R, &tmp, ZEND_FFI_FLAG_CONST, 0, in zend_ffi_cdata_get_debug_info()
2012 ht = zend_new_array(type->array.length); in zend_ffi_cdata_get_debug_info()
2013 for (n = 0; n < type->array.length; n++) { in zend_ffi_cdata_get_debug_info()
2014 …zend_ffi_cdata_to_zval(NULL, ptr, ZEND_FFI_TYPE(type->array.type), BP_VAR_R, &tmp, ZEND_FFI_FLAG_C… in zend_ffi_cdata_get_debug_info()
2016 ptr = (void*)(((char*)ptr) + ZEND_FFI_TYPE(type->array.type)->size); in zend_ffi_cdata_get_debug_info()
2037 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_cdata_get_closure() local
2040 if (type->kind != ZEND_FFI_TYPE_POINTER) { in zend_ffi_cdata_get_closure()
2044 type = ZEND_FFI_TYPE(type->pointer.type); in zend_ffi_cdata_get_closure()
2045 if (type->kind != ZEND_FFI_TYPE_FUNC) { in zend_ffi_cdata_get_closure()
2059 func->type = ZEND_INTERNAL_FUNCTION; in zend_ffi_cdata_get_closure()
2067 func->common.required_num_args = type->func.args ? zend_hash_num_elements(type->func.args) : 0; in zend_ffi_cdata_get_closure()
2074 func->internal_function.reserved[0] = type; in zend_ffi_cdata_get_closure()
2094 ctype->type = NULL; in zend_ffi_ctype_new()
2104 zend_ffi_type_dtor(ctype->type); in zend_ffi_ctype_free_obj()
2117 type1 = ZEND_FFI_TYPE(type1->pointer.type); in zend_ffi_is_same_type()
2118 type2 = ZEND_FFI_TYPE(type2->pointer.type); in zend_ffi_is_same_type()
2125 type1 = ZEND_FFI_TYPE(type1->array.type); in zend_ffi_is_same_type()
2126 type2 = ZEND_FFI_TYPE(type2->array.type); in zend_ffi_is_same_type()
2142 return zend_ffi_get_class_name(zobj->ce->name, ZEND_FFI_TYPE(ctype->type)); in zend_ffi_ctype_get_class_name()
2152 zend_ffi_type *type1 = ZEND_FFI_TYPE(ctype1->type); in zend_ffi_ctype_compare_objects()
2153 zend_ffi_type *type2 = ZEND_FFI_TYPE(ctype2->type); in zend_ffi_ctype_compare_objects()
2190 static void _zend_ffi_type_dtor(zend_ffi_type *type) /* {{{ */ in _zend_ffi_type_dtor() argument
2192 type = ZEND_FFI_TYPE(type); in _zend_ffi_type_dtor()
2194 switch (type->kind) { in _zend_ffi_type_dtor()
2196 if (type->enumeration.tag_name) { in _zend_ffi_type_dtor()
2197 zend_string_release(type->enumeration.tag_name); in _zend_ffi_type_dtor()
2201 if (type->record.tag_name) { in _zend_ffi_type_dtor()
2202 zend_string_release(type->record.tag_name); in _zend_ffi_type_dtor()
2204 zend_hash_destroy(&type->record.fields); in _zend_ffi_type_dtor()
2207 zend_ffi_type_dtor(type->pointer.type); in _zend_ffi_type_dtor()
2210 zend_ffi_type_dtor(type->array.type); in _zend_ffi_type_dtor()
2213 if (type->func.args) { in _zend_ffi_type_dtor()
2214 zend_hash_destroy(type->func.args); in _zend_ffi_type_dtor()
2215 pefree(type->func.args, type->attr & ZEND_FFI_ATTR_PERSISTENT); in _zend_ffi_type_dtor()
2217 zend_ffi_type_dtor(type->func.ret_type); in _zend_ffi_type_dtor()
2222 pefree(type, type->attr & ZEND_FFI_ATTR_PERSISTENT); in _zend_ffi_type_dtor()
2228 zend_ffi_type *type = Z_PTR_P(zv); in zend_ffi_type_hash_dtor() local
2229 zend_ffi_type_dtor(type); in zend_ffi_type_hash_dtor()
2236 zend_ffi_type_dtor(field->type); in zend_ffi_field_hash_dtor()
2244 zend_ffi_type_dtor(field->type); in zend_ffi_field_hash_persistent_dtor()
2252 zend_ffi_type_dtor(sym->type); in zend_ffi_symbol_hash_dtor()
2260 zend_ffi_type_dtor(sym->type); in zend_ffi_symbol_hash_persistent_dtor()
2268 zend_ffi_type_dtor(tag->type); in zend_ffi_tag_hash_dtor()
2276 zend_ffi_type_dtor(tag->type); in zend_ffi_tag_hash_persistent_dtor()
2283 zend_ffi_type_dtor(cdata->type); in zend_ffi_cdata_dtor()
2345 zend_ffi_type *type = ZEND_FFI_TYPE(old_cdata->type); in zend_ffi_cdata_clone_obj() local
2349 if (type->kind < ZEND_FFI_TYPE_POINTER) { in zend_ffi_cdata_clone_obj()
2352 new_cdata->type = type; in zend_ffi_cdata_clone_obj()
2353 new_cdata->ptr = emalloc(type->size); in zend_ffi_cdata_clone_obj()
2354 memcpy(new_cdata->ptr, old_cdata->ptr, type->size); in zend_ffi_cdata_clone_obj()
2383 …zend_ffi_cdata_to_zval(NULL, sym->addr, ZEND_FFI_TYPE(sym->type), read_type, rv, (zend_ffi_flags)s… in zend_ffi_read_var()
2392 new_type->pointer.type = ZEND_FFI_TYPE(sym->type); in zend_ffi_read_var()
2397 cdata->type = ZEND_FFI_TYPE_MAKE_OWNED(new_type); in zend_ffi_read_var()
2436 zend_ffi_zval_to_cdata(sym->addr, ZEND_FFI_TYPE(sym->type), value); in zend_ffi_write_var()
2441 static int zend_ffi_pass_arg(zval *arg, zend_ffi_type *type, ffi_type **pass_type, void **arg_value… in zend_ffi_pass_arg() argument
2446 zend_ffi_type_kind kind = type->kind; in zend_ffi_pass_arg()
2515 && ((ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_FFI_TYPE_CHAR) in zend_ffi_pass_arg()
2516 || (ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_FFI_TYPE_VOID))) { in zend_ffi_pass_arg()
2522 if (zend_ffi_is_compatible_type(type, ZEND_FFI_TYPE(cdata->type))) { in zend_ffi_pass_arg()
2523 if (ZEND_FFI_TYPE(cdata->type)->kind == ZEND_FFI_TYPE_POINTER) { in zend_ffi_pass_arg()
2535 } else if (ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_FFI_TYPE_FUNC) { in zend_ffi_pass_arg()
2536 void *callback = zend_ffi_create_callback(ZEND_FFI_TYPE(type->pointer.type), arg); in zend_ffi_pass_arg()
2546 zend_ffi_pass_incompatible(arg, type, n, execute_data); in zend_ffi_pass_arg()
2557 zend_ffi_pass_incompatible(arg, type, n, execute_data); in zend_ffi_pass_arg()
2562 kind = type->enumeration.kind; in zend_ffi_pass_arg()
2565 if (!(type->attr & ZEND_FFI_ATTR_UNION) in zend_ffi_pass_arg()
2569 if (zend_ffi_is_compatible_type(type, ZEND_FFI_TYPE(cdata->type))) { in zend_ffi_pass_arg()
2571 ffi_type *t = zend_ffi_make_fake_struct_type(type); in zend_ffi_pass_arg()
2579 zend_ffi_pass_incompatible(arg, type, n, execute_data); in zend_ffi_pass_arg()
2582 zend_ffi_pass_unsupported(type); in zend_ffi_pass_arg()
2625 zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); in zend_ffi_pass_var_arg() local
2627 return zend_ffi_pass_arg(arg, type, pass_type, arg_values, n, execute_data); in zend_ffi_pass_var_arg()
2640 zend_ffi_type *type = EX(func)->internal_function.reserved[0]; in ZEND_FUNCTION() local
2653 ZEND_ASSERT(type->kind == ZEND_FFI_TYPE_FUNC); in ZEND_FUNCTION()
2654 arg_count = type->func.args ? zend_hash_num_elements(type->func.args) : 0; in ZEND_FUNCTION()
2655 if (type->attr & ZEND_FFI_ATTR_VARIADIC) { in ZEND_FUNCTION()
2666 if (type->func.args) { in ZEND_FUNCTION()
2667 ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { in ZEND_FUNCTION()
2687 ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); in ZEND_FUNCTION()
2689 zend_ffi_return_unsupported(type->func.ret_type); in ZEND_FUNCTION()
2694 …if (ffi_prep_cif_var(&cif, type->func.abi, arg_count, EX_NUM_ARGS(), ret_type, arg_types) != FFI_O… in ZEND_FUNCTION()
2711 if (type->func.args) { in ZEND_FUNCTION()
2712 ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) { in ZEND_FUNCTION()
2724 ret_type = zend_ffi_get_type(ZEND_FFI_TYPE(type->func.ret_type)); in ZEND_FUNCTION()
2726 zend_ffi_return_unsupported(type->func.ret_type); in ZEND_FUNCTION()
2731 if (ffi_prep_cif(&cif, type->func.abi, arg_count, ret_type, arg_types) != FFI_OK) { in ZEND_FUNCTION()
2743 if (arg_types[n]->type == FFI_TYPE_STRUCT) { in ZEND_FUNCTION()
2747 if (ret_type->type == FFI_TYPE_STRUCT) { in ZEND_FUNCTION()
2756 …zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, 0, 1… in ZEND_FUNCTION()
2773 zend_ffi_type *type; in zend_ffi_get_func() local
2805 type = ZEND_FFI_TYPE(sym->type); in zend_ffi_get_func()
2806 ZEND_ASSERT(type->kind == ZEND_FFI_TYPE_FUNC); in zend_ffi_get_func()
2813 func->common.type = ZEND_INTERNAL_FUNCTION; in zend_ffi_get_func()
2821 func->common.required_num_args = type->func.args ? zend_hash_num_elements(type->func.args) : 0; in zend_ffi_get_func()
2828 func->internal_function.reserved[0] = type; in zend_ffi_get_func()
2926 zend_string *mangled_name = zend_ffi_mangled_func_name(name, ZEND_FFI_TYPE(sym->type)); in ZEND_METHOD()
2951 static int zend_ffi_same_types(zend_ffi_type *old, zend_ffi_type *type) /* {{{ */ in zend_ffi_same_types() argument
2953 if (old == type) { in zend_ffi_same_types()
2957 if (old->kind != type->kind in zend_ffi_same_types()
2958 || old->size != type->size in zend_ffi_same_types()
2959 || old->align != type->align in zend_ffi_same_types()
2960 || old->attr != type->attr) { in zend_ffi_same_types()
2966 return old->enumeration.kind == type->enumeration.kind; in zend_ffi_same_types()
2968 return old->array.length == type->array.length in zend_ffi_same_types()
2969 && zend_ffi_same_types(ZEND_FFI_TYPE(old->array.type), ZEND_FFI_TYPE(type->array.type)); in zend_ffi_same_types()
2971 return zend_ffi_same_types(ZEND_FFI_TYPE(old->pointer.type), ZEND_FFI_TYPE(type->pointer.type)); in zend_ffi_same_types()
2973 … if (zend_hash_num_elements(&old->record.fields) != zend_hash_num_elements(&type->record.fields)) { in zend_ffi_same_types()
2978 Bucket *b = type->record.fields.arData; in zend_ffi_same_types()
2998 || !zend_ffi_same_types(ZEND_FFI_TYPE(old_field->type), ZEND_FFI_TYPE(field->type))) { in zend_ffi_same_types()
3006 if (old->func.abi != type->func.abi in zend_ffi_same_types()
3007 …rgs ? zend_hash_num_elements(old->func.args) : 0) != (type->func.args ? zend_hash_num_elements(typ… in zend_ffi_same_types()
3008 … || !zend_ffi_same_types(ZEND_FFI_TYPE(old->func.ret_type), ZEND_FFI_TYPE(type->func.ret_type))) { in zend_ffi_same_types()
3012 Bucket *b = type->func.args->arData; in zend_ffi_same_types()
3045 return zend_ffi_same_types(ZEND_FFI_TYPE(old->type), ZEND_FFI_TYPE(sym->type)); in zend_ffi_same_symbols()
3055 return zend_ffi_same_types(ZEND_FFI_TYPE(old->type), ZEND_FFI_TYPE(tag->type)); in zend_ffi_same_tags()
3059 static int zend_ffi_subst_old_type(zend_ffi_type **dcl, zend_ffi_type *old, zend_ffi_type *type) /*… in zend_ffi_subst_old_type() argument
3064 if (ZEND_FFI_TYPE(*dcl) == type) { in zend_ffi_subst_old_type()
3071 return zend_ffi_subst_old_type(&dcl_type->pointer.type, old, type); in zend_ffi_subst_old_type()
3073 return zend_ffi_subst_old_type(&dcl_type->array.type, old, type); in zend_ffi_subst_old_type()
3075 if (zend_ffi_subst_old_type(&dcl_type->func.ret_type, old, type)) { in zend_ffi_subst_old_type()
3082 if (zend_ffi_subst_old_type((zend_ffi_type**)&Z_PTR_P(zv), old, type)) { in zend_ffi_subst_old_type()
3090 if (zend_ffi_subst_old_type(&field->type, old, type)) { in zend_ffi_subst_old_type()
3101 static void zend_ffi_cleanup_type(zend_ffi_type *old, zend_ffi_type *type) /* {{{ */ in zend_ffi_cleanup_type() argument
3108 zend_ffi_subst_old_type(&sym->type, old, type); in zend_ffi_cleanup_type()
3113 zend_ffi_subst_old_type(&tag->type, old, type); in zend_ffi_cleanup_type()
3119 static zend_ffi_type *zend_ffi_remember_type(zend_ffi_type *type) /* {{{ */ in zend_ffi_remember_type() argument
3126 type->attr |= ZEND_FFI_ATTR_STORED; in zend_ffi_remember_type()
3127 zend_hash_next_index_insert_ptr(FFI_G(weak_types), ZEND_FFI_TYPE_MAKE_OWNED(type)); in zend_ffi_remember_type()
3128 return type; in zend_ffi_remember_type()
3251 zend_string *mangled_name = zend_ffi_mangled_func_name(name, ZEND_FFI_TYPE(sym->type)); in zend_ffi_load()
3273 if (ZEND_FFI_TYPE_IS_OWNED(sym->type) in zend_ffi_load()
3274 && ZEND_FFI_TYPE(old_sym->type) != ZEND_FFI_TYPE(sym->type)) { in zend_ffi_load()
3275 zend_ffi_type *type = ZEND_FFI_TYPE(sym->type); in zend_ffi_load() local
3276 zend_ffi_cleanup_type(ZEND_FFI_TYPE(old_sym->type), ZEND_FFI_TYPE(type)); in zend_ffi_load()
3277 zend_ffi_type_dtor(type); in zend_ffi_load()
3298 if (ZEND_FFI_TYPE_IS_OWNED(tag->type) in zend_ffi_load()
3299 && ZEND_FFI_TYPE(old_tag->type) != ZEND_FFI_TYPE(tag->type)) { in zend_ffi_load()
3300 zend_ffi_type *type = ZEND_FFI_TYPE(tag->type); in zend_ffi_load() local
3301 zend_ffi_cleanup_type(ZEND_FFI_TYPE(old_tag->type), ZEND_FFI_TYPE(type)); in zend_ffi_load()
3302 zend_ffi_type_dtor(type); in zend_ffi_load()
3334 zend_ffi_type_dtor(sym->type); in zend_ffi_load()
3349 zend_ffi_type_dtor(tag->type); in zend_ffi_load()
3454 zend_ffi_type_dtor(dcl->type); in zend_ffi_cleanup_dcl()
3455 dcl->type = NULL; in zend_ffi_cleanup_dcl()
3479 static int zend_ffi_validate_vla(zend_ffi_type *type) /* {{{ */ in zend_ffi_validate_vla() argument
3481 if (!FFI_G(allow_vla) && (type->attr & ZEND_FFI_ATTR_VLA)) { in zend_ffi_validate_vla()
3489 static int zend_ffi_validate_incomplete_type(zend_ffi_type *type, zend_bool allow_incomplete_tag, z… in zend_ffi_validate_incomplete_type() argument
3491 if (!allow_incomplete_tag && (type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG)) { in zend_ffi_validate_incomplete_type()
3497 if (ZEND_FFI_TYPE(tag->type) == type) { in zend_ffi_validate_incomplete_type()
3498 if (type->kind == ZEND_FFI_TYPE_ENUM) { in zend_ffi_validate_incomplete_type()
3500 } else if (type->attr & ZEND_FFI_ATTR_UNION) { in zend_ffi_validate_incomplete_type()
3514 if (type == ZEND_FFI_TYPE(sym->type)) { in zend_ffi_validate_incomplete_type()
3522 } else if (!allow_incomplete_array && type->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY) { in zend_ffi_validate_incomplete_type()
3525 } else if (!FFI_G(allow_vla) && (type->attr & ZEND_FFI_ATTR_VLA)) { in zend_ffi_validate_incomplete_type()
3533 static int zend_ffi_validate_type(zend_ffi_type *type, zend_bool allow_incomplete_tag, zend_bool al… in zend_ffi_validate_type() argument
3535 if (type->kind == ZEND_FFI_TYPE_VOID) { in zend_ffi_validate_type()
3539 return zend_ffi_validate_incomplete_type(type, allow_incomplete_tag, allow_incomplete_array); in zend_ffi_validate_type()
3543 static int zend_ffi_validate_var_type(zend_ffi_type *type, zend_bool allow_incomplete_array) /* {{{… in zend_ffi_validate_var_type() argument
3545 if (type->kind == ZEND_FFI_TYPE_FUNC) { in zend_ffi_validate_var_type()
3549 return zend_ffi_validate_type(type, 0, allow_incomplete_array); in zend_ffi_validate_var_type()
3556 if (zend_ffi_validate_var_type(ZEND_FFI_TYPE(dcl->type), 0) != SUCCESS) { in zend_ffi_validate_type_name()
3563 static int zend_ffi_subst_type(zend_ffi_type **dcl, zend_ffi_type *type) /* {{{ */ in zend_ffi_subst_type() argument
3568 if (*dcl == type) { in zend_ffi_subst_type()
3569 *dcl = ZEND_FFI_TYPE_MAKE_OWNED(type); in zend_ffi_subst_type()
3575 return zend_ffi_subst_type(&dcl_type->pointer.type, type); in zend_ffi_subst_type()
3577 return zend_ffi_subst_type(&dcl_type->array.type, type); in zend_ffi_subst_type()
3579 if (zend_ffi_subst_type(&dcl_type->func.ret_type, type)) { in zend_ffi_subst_type()
3586 if (zend_ffi_subst_type((zend_ffi_type**)&Z_PTR_P(zv), type)) { in zend_ffi_subst_type()
3594 if (zend_ffi_subst_type(&field->type, type)) { in zend_ffi_subst_type()
3609 if (ZEND_FFI_TYPE_IS_OWNED(tag->type)) { in zend_ffi_tags_cleanup()
3610 zend_ffi_type *type = ZEND_FFI_TYPE(tag->type); in zend_ffi_tags_cleanup() local
3611 zend_ffi_subst_type(&dcl->type, type); in zend_ffi_tags_cleanup()
3612 tag->type = type; in zend_ffi_tags_cleanup()
3624 zend_ffi_type *type, *type_ptr; in ZEND_METHOD() local
3667 zend_ffi_type_dtor(dcl.type); in ZEND_METHOD()
3683 type = ZEND_FFI_TYPE(dcl.type); in ZEND_METHOD()
3701 type_ptr = dcl.type; in ZEND_METHOD()
3705 type_ptr = type = ctype->type; in ZEND_METHOD()
3706 if (ZEND_FFI_TYPE_IS_OWNED(type)) { in ZEND_METHOD()
3707 type = ZEND_FFI_TYPE(type); in ZEND_METHOD()
3708 if (!(type->attr & ZEND_FFI_ATTR_STORED)) { in ZEND_METHOD()
3711 ctype->type = type; in ZEND_METHOD()
3713 ctype->type = type_ptr = type = zend_ffi_remember_type(type); in ZEND_METHOD()
3719 if (type->size == 0) { in ZEND_METHOD()
3725 ptr = pemalloc(type->size, flags & ZEND_FFI_FLAG_PERSISTENT); in ZEND_METHOD()
3726 memset(ptr, 0, type->size); in ZEND_METHOD()
3729 if (type->kind < ZEND_FFI_TYPE_POINTER) { in ZEND_METHOD()
3732 cdata->type = type_ptr; in ZEND_METHOD()
3755 if (ZEND_FFI_TYPE(cdata->type)->kind == ZEND_FFI_TYPE_POINTER) { in ZEND_METHOD()
3781 zend_ffi_type *old_type, *type, *type_ptr; in ZEND_METHOD() local
3815 zend_ffi_type_dtor(dcl.type); in ZEND_METHOD()
3831 type = ZEND_FFI_TYPE(dcl.type); in ZEND_METHOD()
3849 type_ptr = dcl.type; in ZEND_METHOD()
3853 type_ptr = type = ctype->type; in ZEND_METHOD()
3854 if (ZEND_FFI_TYPE_IS_OWNED(type)) { in ZEND_METHOD()
3855 type = ZEND_FFI_TYPE(type); in ZEND_METHOD()
3856 if (!(type->attr & ZEND_FFI_ATTR_STORED)) { in ZEND_METHOD()
3859 ctype->type = type; in ZEND_METHOD()
3861 ctype->type = type_ptr = type = zend_ffi_remember_type(type); in ZEND_METHOD()
3868 if (type->kind < ZEND_FFI_TYPE_POINTER && Z_TYPE_P(zv) < IS_STRING) { in ZEND_METHOD()
3872 cdata->type = type_ptr; in ZEND_METHOD()
3873 cdata->ptr = emalloc(type->size); in ZEND_METHOD()
3874 zend_ffi_zval_to_cdata(cdata->ptr, type, zv); in ZEND_METHOD()
3880 } else if (type->kind == ZEND_FFI_TYPE_POINTER && Z_TYPE_P(zv) == IS_LONG) { in ZEND_METHOD()
3883 cdata->type = type_ptr; in ZEND_METHOD()
3890 } else if (type->kind == ZEND_FFI_TYPE_POINTER && Z_TYPE_P(zv) == IS_NULL) { in ZEND_METHOD()
3893 cdata->type = type_ptr; in ZEND_METHOD()
3907 old_type = ZEND_FFI_TYPE(old_cdata->type); in ZEND_METHOD()
3911 if (type->kind < ZEND_FFI_TYPE_POINTER) { in ZEND_METHOD()
3914 cdata->type = type_ptr; in ZEND_METHOD()
3917 && type->kind != ZEND_FFI_TYPE_POINTER in ZEND_METHOD()
3918 && ZEND_FFI_TYPE(old_type->pointer.type)->kind == ZEND_FFI_TYPE_VOID) { in ZEND_METHOD()
3922 && type->kind == ZEND_FFI_TYPE_POINTER) { in ZEND_METHOD()
3925 } else if (type->size > old_type->size) { in ZEND_METHOD()
3953 ZEND_METHOD(FFI, type) /* {{{ */ in ZEND_METHOD() argument
3976 zend_ffi_type_dtor(dcl.type); in ZEND_METHOD()
4006 ctype->type = dcl.type; in ZEND_METHOD()
4016 zend_ffi_type *type; in ZEND_METHOD() local
4028 type = cdata->type; in ZEND_METHOD()
4029 if (ZEND_FFI_TYPE_IS_OWNED(type)) { in ZEND_METHOD()
4030 type = ZEND_FFI_TYPE(type); in ZEND_METHOD()
4031 if (!(type->attr & ZEND_FFI_ATTR_STORED)) { in ZEND_METHOD()
4034 cdata->type = type; in ZEND_METHOD()
4035 type = ZEND_FFI_TYPE_MAKE_OWNED(type); in ZEND_METHOD()
4037 cdata->type = type = zend_ffi_remember_type(type); in ZEND_METHOD()
4047 ctype->type = type; in ZEND_METHOD()
4057 zend_ffi_type *type; in ZEND_METHOD() local
4068 type = ZEND_FFI_TYPE(ctype->type); in ZEND_METHOD()
4070 if (type->kind == ZEND_FFI_TYPE_FUNC) { in ZEND_METHOD()
4073 } else if (type->kind == ZEND_FFI_TYPE_ARRAY && (type->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY)) { in ZEND_METHOD()
4076 } else if (type->kind == ZEND_FFI_TYPE_VOID) { in ZEND_METHOD()
4079 } else if (type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG) { in ZEND_METHOD()
4084 if (ZEND_FFI_TYPE_IS_OWNED(ctype->type)) { in ZEND_METHOD()
4085 if (!(type->attr & ZEND_FFI_ATTR_STORED)) { in ZEND_METHOD()
4088 ctype->type = type; in ZEND_METHOD()
4089 type = ZEND_FFI_TYPE_MAKE_OWNED(type); in ZEND_METHOD()
4091 ctype->type = type = zend_ffi_remember_type(type); in ZEND_METHOD()
4102 zend_ffi_type_dtor(type); in ZEND_METHOD()
4104 …} else if (ZEND_FFI_TYPE(type)->kind == ZEND_FFI_TYPE_ARRAY && (ZEND_FFI_TYPE(type)->attr & ZEND_F… in ZEND_METHOD()
4106 zend_ffi_type_dtor(type); in ZEND_METHOD()
4113 new_type->size = n * ZEND_FFI_TYPE(type)->size; in ZEND_METHOD()
4114 new_type->align = ZEND_FFI_TYPE(type)->align; in ZEND_METHOD()
4115 new_type->array.type = type; in ZEND_METHOD()
4122 type = ZEND_FFI_TYPE_MAKE_OWNED(new_type); in ZEND_METHOD()
4126 ctype->type = type; in ZEND_METHOD()
4134 zend_ffi_type *type, *new_type; in ZEND_METHOD() local
4151 type = ZEND_FFI_TYPE(cdata->type); in ZEND_METHOD()
4159 new_type->pointer.type = type; in ZEND_METHOD()
4162 new_cdata->type = ZEND_FFI_TYPE_MAKE_OWNED(new_type); in ZEND_METHOD()
4167 if (ZEND_FFI_TYPE_IS_OWNED(cdata->type)) { in ZEND_METHOD()
4169 cdata->type = type; in ZEND_METHOD()
4170 new_type->pointer.type = ZEND_FFI_TYPE_MAKE_OWNED(type); in ZEND_METHOD()
4186 zend_ffi_type *type; in ZEND_METHOD() local
4196 type = ZEND_FFI_TYPE(cdata->type); in ZEND_METHOD()
4199 type = ZEND_FFI_TYPE(ctype->type); in ZEND_METHOD()
4205 RETURN_LONG(type->size); in ZEND_METHOD()
4212 zend_ffi_type *type; in ZEND_METHOD() local
4222 type = ZEND_FFI_TYPE(cdata->type); in ZEND_METHOD()
4225 type = ZEND_FFI_TYPE(ctype->type); in ZEND_METHOD()
4231 RETURN_LONG(type->align); in ZEND_METHOD()
4251 type1 = ZEND_FFI_TYPE(cdata1->type); in ZEND_METHOD()
4271 type2 = ZEND_FFI_TYPE(cdata2->type); in ZEND_METHOD()
4315 type1 = ZEND_FFI_TYPE(cdata1->type); in ZEND_METHOD()
4339 type2 = ZEND_FFI_TYPE(cdata2->type); in ZEND_METHOD()
4369 zend_ffi_type *type; in ZEND_METHOD() local
4381 type = ZEND_FFI_TYPE(cdata->type); in ZEND_METHOD()
4382 if (type->kind == ZEND_FFI_TYPE_POINTER) { in ZEND_METHOD()
4386 if (type->kind != ZEND_FFI_TYPE_POINTER && size > type->size) { in ZEND_METHOD()
4400 zend_ffi_type *type; in ZEND_METHOD() local
4412 type = ZEND_FFI_TYPE(cdata->type); in ZEND_METHOD()
4414 if (type->kind == ZEND_FFI_TYPE_POINTER) { in ZEND_METHOD()
4418 if (type->kind != ZEND_FFI_TYPE_POINTER && size > type->size) { in ZEND_METHOD()
4425 …if (type->kind == ZEND_FFI_TYPE_POINTER && ZEND_FFI_TYPE(type->pointer.type)->kind == ZEND_FFI_TYP… in ZEND_METHOD()
4427 …} else if (type->kind == ZEND_FFI_TYPE_ARRAY && ZEND_FFI_TYPE(type->array.type)->kind == ZEND_FFI_… in ZEND_METHOD()
4442 zend_ffi_type *type; in ZEND_METHOD() local
4456 type = ZEND_FFI_TYPE(cdata->type); in ZEND_METHOD()
4458 if (type->kind != ZEND_FFI_TYPE_POINTER){ in ZEND_METHOD()
4481 ZEND_ARG_INFO(0, type)
4491 ZEND_ARG_INFO(0, type)
4496 ZEND_ARG_INFO(0, type)
4504 ZEND_ARG_INFO(0, type)
4554 ZEND_ME(FFI, type, arginfo_func_type, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
4690 static ZEND_COLD zval *zend_fake_read_dimension(zval *object, zval *offset, int type, zval *rv) /* … in zend_fake_read_dimension() argument
4726 static ZEND_COLD zval *zend_fake_read_property(zval *object, zval *member, int type, void **cache_s… in zend_fake_read_property() argument
4757 static zval *zend_fake_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot… in zend_fake_get_property_ptr_ptr() argument
4798 static ZEND_COLD zval *zend_ffi_free_read_dimension(zval *object, zval *offset, int type, zval *rv)… in zend_ffi_free_read_dimension() argument
4824 static ZEND_COLD zval *zend_ffi_free_read_property(zval *object, zval *member, int type, void **cac… in zend_ffi_free_read_property() argument
5222 …D_FFI_TYPE_POINTER, .size=sizeof(void*), .align=_Alignof(void*), .pointer.type = (zend_ffi_type*)&…
5226 const zend_ffi_type *type; member
5280 …als->types, zend_ffi_types[i].name, strlen(zend_ffi_types[i].name), (void*)zend_ffi_types[i].type);
5348 if (!dcl->type) {
5351 dcl->type = (zend_ffi_type*)&zend_ffi_type_void;
5354 dcl->type = (zend_ffi_type*)&zend_ffi_type_char;
5357 dcl->type = (zend_ffi_type*)&zend_ffi_type_sint8;
5361 dcl->type = (zend_ffi_type*)&zend_ffi_type_uint8;
5367 dcl->type = (zend_ffi_type*)&zend_ffi_type_sint16;
5371 dcl->type = (zend_ffi_type*)&zend_ffi_type_uint16;
5376 dcl->type = (zend_ffi_type*)&zend_ffi_type_sint32;
5380 dcl->type = (zend_ffi_type*)&zend_ffi_type_uint32;
5387 dcl->type = (zend_ffi_type*)&zend_ffi_type_sint32;
5389 dcl->type = (zend_ffi_type*)&zend_ffi_type_sint64;
5395 dcl->type = (zend_ffi_type*)&zend_ffi_type_uint32;
5397 dcl->type = (zend_ffi_type*)&zend_ffi_type_uint64;
5404 dcl->type = (zend_ffi_type*)&zend_ffi_type_sint64;
5408 dcl->type = (zend_ffi_type*)&zend_ffi_type_uint64;
5411 dcl->type = (zend_ffi_type*)&zend_ffi_type_float;
5414 dcl->type = (zend_ffi_type*)&zend_ffi_type_double;
5418 dcl->type = (zend_ffi_type*)&zend_ffi_type_double;
5420 dcl->type = (zend_ffi_type*)&zend_ffi_type_long_double;
5441 zend_ffi_type *type; local
5449 type = zend_hash_str_find_ptr(&FFI_G(types), name, name_len);
5450 if (type) {
5460 zend_ffi_type *type; local
5465 dcl->type = ZEND_FFI_TYPE(sym->type);;
5472 type = zend_hash_str_find_ptr(&FFI_G(types), name, name_len);
5473 if (type) {
5474 dcl->type = type;
5494 switch (sym->type->kind) {
5523 zend_ffi_type *type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent)); local
5524 type->kind = ZEND_FFI_TYPE_ENUM;
5525 type->attr = FFI_G(default_type_attr) | (dcl->attr & ZEND_FFI_ENUM_ATTRS);
5526 type->enumeration.tag_name = NULL;
5527 if (type->attr & ZEND_FFI_ATTR_PACKED) {
5528 type->size = zend_ffi_type_uint8.size;
5529 type->align = zend_ffi_type_uint8.align;
5530 type->enumeration.kind = ZEND_FFI_TYPE_UINT8;
5532 type->size = zend_ffi_type_uint32.size;
5533 type->align = zend_ffi_type_uint32.align;
5534 type->enumeration.kind = ZEND_FFI_TYPE_UINT32;
5536 dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type);
5546 zend_ffi_type *enum_type = ZEND_FFI_TYPE(enum_dcl->type);
5644 sym->type = (zend_ffi_type*)sym_type;
5653 zend_ffi_type *type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent)); local
5654 type->kind = ZEND_FFI_TYPE_STRUCT;
5655 type->attr = FFI_G(default_type_attr) | (dcl->attr & ZEND_FFI_STRUCT_ATTRS);
5656 type->size = 0;
5657 type->align = dcl->align > 1 ? dcl->align : 1;
5659 type->attr |= ZEND_FFI_ATTR_UNION;
5661 dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type);
5662 type->record.tag_name = NULL;
5663 …zend_hash_init(&type->record.fields, 0, NULL, FFI_G(persistent) ? zend_ffi_field_hash_persistent_d…
5677 if (ZEND_FFI_TYPE(field->type)->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY) {
5686 static int zend_ffi_validate_field_type(zend_ffi_type *type, zend_ffi_type *struct_type) /* {{{ */ argument
5688 if (type == struct_type) {
5691 } else if (zend_ffi_validate_var_type(type, 1) != SUCCESS) {
5694 if (type->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY) {
5706 zend_ffi_type *struct_type = ZEND_FFI_TYPE(struct_dcl->type);
5711 field_type = ZEND_FFI_TYPE(field_dcl->type);
5732 field->type = field_dcl->type;
5737 field_dcl->type = field_type; /* reset "owned" flag */
5740 zend_ffi_type_dtor(field->type);
5749 zend_ffi_type *struct_type = ZEND_FFI_TYPE(struct_dcl->type);
5756 field_type = ZEND_FFI_TYPE(field_dcl->type);
5785 new_field->type = field->type;
5790 field->type = ZEND_FFI_TYPE(field->type); /* reset "owned" flag */
5794 zend_ffi_type_dtor(new_field->type);
5810 zend_ffi_type_dtor(field_dcl->type);
5811 field_dcl->type = NULL;
5817 zend_ffi_type *struct_type = ZEND_FFI_TYPE(struct_dcl->type);
5823 field_type = ZEND_FFI_TYPE(field_dcl->type);
5900 field->type = field_dcl->type;
5903 field_dcl->type = field_type; /* reset "owned" flag */
5907 zend_ffi_type_dtor(field->type);
5919 zend_ffi_type *struct_type = ZEND_FFI_TYPE(dcl->type);
5934 zend_ffi_type *type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent)); local
5935 type->kind = ZEND_FFI_TYPE_POINTER;
5936 type->attr = FFI_G(default_type_attr) | (dcl->attr & ZEND_FFI_POINTER_ATTRS);
5937 type->size = sizeof(void*);
5938 type->align = _Alignof(void*);
5940 if (zend_ffi_validate_vla(ZEND_FFI_TYPE(dcl->type)) != SUCCESS) {
5944 type->pointer.type = dcl->type;
5945 dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type);
5952 static int zend_ffi_validate_array_element_type(zend_ffi_type *type) /* {{{ */ argument
5954 if (type->kind == ZEND_FFI_TYPE_FUNC) {
5957 } else if (type->kind == ZEND_FFI_TYPE_ARRAY && (type->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY)) {
5961 return zend_ffi_validate_type(type, 0, 1);
5969 zend_ffi_type *type; local
5972 element_type = ZEND_FFI_TYPE(dcl->type);
5998 type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent));
5999 type->kind = ZEND_FFI_TYPE_ARRAY;
6000 type->attr = FFI_G(default_type_attr) | (dcl->attr & ZEND_FFI_ARRAY_ATTRS);
6001 type->size = length * element_type->size;
6002 type->align = element_type->align;
6003 type->array.type = dcl->type;
6004 type->array.length = length;
6005 dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type);
6012 static int zend_ffi_validate_func_ret_type(zend_ffi_type *type) /* {{{ */ argument
6014 if (type->kind == ZEND_FFI_TYPE_FUNC) {
6017 } else if (type->kind == ZEND_FFI_TYPE_ARRAY) {
6021 return zend_ffi_validate_incomplete_type(type, 1, 0);
6027 zend_ffi_type *type; local
6031 ret_type = ZEND_FFI_TYPE(dcl->type);
6092 type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent));
6093 type->kind = ZEND_FFI_TYPE_FUNC;
6094 type->attr = FFI_G(default_type_attr) | (dcl->attr & ZEND_FFI_FUNC_ATTRS);
6095 type->size = sizeof(void*);
6096 type->align = 1;
6097 type->func.ret_type = dcl->type;
6101 type->func.abi = FFI_DEFAULT_ABI;
6105 type->func.abi = FFI_FASTCALL;
6110 type->func.abi = FFI_THISCALL;
6115 type->func.abi = FFI_STDCALL;
6120 type->func.abi = FFI_PASCAL;
6125 type->func.abi = FFI_REGISTER;
6130 type->func.abi = FFI_MS_CDECL;
6135 type->func.abi = FFI_SYSV;
6140 type->func.abi = FFI_VECTORCALL_PARTIAL;
6144 type->func.abi = FFI_DEFAULT_ABI;
6150 type->func.args = NULL;
6151 _zend_ffi_type_dtor(type);
6155 type->func.args = args;
6156 dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type);
6165 zend_ffi_type *type; local
6172 type = ZEND_FFI_TYPE(arg_dcl->type);
6173 if (type->kind == ZEND_FFI_TYPE_ARRAY) {
6174 if (ZEND_FFI_TYPE_IS_OWNED(arg_dcl->type)) {
6175 type->kind = ZEND_FFI_TYPE_POINTER;
6176 type->size = sizeof(void*);
6180 new_type->attr = FFI_G(default_type_attr) | (type->attr & ZEND_FFI_POINTER_ATTRS);
6183 new_type->pointer.type = ZEND_FFI_TYPE(type->array.type);
6184 arg_dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(new_type);
6186 } else if (type->kind == ZEND_FFI_TYPE_FUNC) {
6192 new_type->pointer.type = arg_dcl->type;
6193 arg_dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(new_type);
6195 if (zend_ffi_validate_incomplete_type(type, 1, 1) != SUCCESS) {
6202 zend_hash_next_index_insert_ptr(*args, (void*)arg_dcl->type);
6219 && zend_ffi_is_same_type(ZEND_FFI_TYPE(sym->type), ZEND_FFI_TYPE(dcl->type))
6222 zend_ffi_type_dtor(dcl->type);
6226 zend_ffi_type *type = ZEND_FFI_TYPE(dcl->type); local
6228 if (type->kind == ZEND_FFI_TYPE_FUNC) {
6230 && zend_ffi_same_types(ZEND_FFI_TYPE(sym->type), type)) {
6232 zend_ffi_type_dtor(dcl->type);
6237 && zend_ffi_is_same_type(ZEND_FFI_TYPE(sym->type), type)
6240 zend_ffi_type_dtor(dcl->type);
6248 if (zend_ffi_validate_vla(ZEND_FFI_TYPE(dcl->type)) != SUCCESS) {
6252 if (dcl->align && dcl->align > ZEND_FFI_TYPE(dcl->type)->align) {
6253 if (ZEND_FFI_TYPE_IS_OWNED(dcl->type)) {
6254 ZEND_FFI_TYPE(dcl->type)->align = dcl->align;
6256 zend_ffi_type *type = pemalloc(sizeof(zend_ffi_type), FFI_G(persistent)); local
6258 memcpy(type, ZEND_FFI_TYPE(dcl->type), sizeof(zend_ffi_type));
6259 type->attr |= FFI_G(default_type_attr);
6260 type->align = dcl->align;
6261 dcl->type = ZEND_FFI_TYPE_MAKE_OWNED(type);
6266 sym->type = dcl->type;
6268 dcl->type = ZEND_FFI_TYPE(dcl->type); /* reset "owned" flag */
6271 zend_ffi_type *type; local
6273 type = ZEND_FFI_TYPE(dcl->type);
6274 …if (zend_ffi_validate_type(type, (dcl->flags & ZEND_FFI_DCL_STORAGE_CLASS) == ZEND_FFI_DCL_EXTERN,…
6281 sym->kind = (type->kind == ZEND_FFI_TYPE_FUNC) ? ZEND_FFI_SYM_FUNC : ZEND_FFI_SYM_VAR;
6282 sym->type = dcl->type;
6284 dcl->type = type; /* reset "owned" flag */
6288 zend_ffi_type_dtor(dcl->type);
6298 zend_ffi_type *type; local
6306 zend_ffi_type *type = ZEND_FFI_TYPE(tag->type); local
6312 } else if (!incomplete && !(type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG)) {
6320 } else if (!incomplete && !(type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG)) {
6328 } else if (!incomplete && !(type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG)) {
6336 dcl->type = type;
6338 type->attr &= ~ZEND_FFI_ATTR_INCOMPLETE_TAG;
6347 type = ZEND_FFI_TYPE(dcl->type);
6348 type->record.tag_name = zend_string_copy(tag_name);
6352 type = ZEND_FFI_TYPE(dcl->type);
6353 type->record.tag_name = zend_string_copy(tag_name);
6357 type = ZEND_FFI_TYPE(dcl->type);
6358 type->enumeration.tag_name = zend_string_copy(tag_name);
6362 tag->type = ZEND_FFI_TYPE_MAKE_OWNED(dcl->type);
6363 dcl->type = ZEND_FFI_TYPE(dcl->type);
6365 dcl->type->attr |= ZEND_FFI_ATTR_INCOMPLETE_TAG;
6620 static int zend_ffi_nested_type(zend_ffi_type *type, zend_ffi_type *nested_type) /* {{{ */ argument
6626 if (nested_type->pointer.type == &zend_ffi_type_char) {
6627 nested_type->pointer.type = type;
6628 return zend_ffi_validate_vla(ZEND_FFI_TYPE(type));
6630 return zend_ffi_nested_type(type, nested_type->pointer.type);
6635 if (nested_type->array.type == &zend_ffi_type_char) {
6636 nested_type->array.type = type;
6637 if (zend_ffi_validate_array_element_type(ZEND_FFI_TYPE(type)) != SUCCESS) {
6641 if (zend_ffi_nested_type(type, nested_type->array.type) != SUCCESS) {
6645 nested_type->size = nested_type->array.length * ZEND_FFI_TYPE(nested_type->array.type)->size;
6646 nested_type->align = ZEND_FFI_TYPE(nested_type->array.type)->align;
6652 nested_type->func.ret_type = type;
6653 return zend_ffi_validate_func_ret_type(ZEND_FFI_TYPE(type));
6655 return zend_ffi_nested_type(type, nested_type->func.ret_type);
6668 if (!nested_dcl->type || nested_dcl->type == &zend_ffi_type_char) {
6669 nested_dcl->type = dcl->type;
6671 if (zend_ffi_nested_type(dcl->type, nested_dcl->type) != SUCCESS) {
6676 dcl->type = nested_dcl->type;
6683 dcl->align = MAX(align_dcl->align, ZEND_FFI_TYPE(align_dcl->type)->align);
7067 switch (ZEND_FFI_TYPE(dcl->type)->kind) {
7194 zend_ffi_type_dtor(dcl->type);
7289 zend_ffi_type *type; local
7292 type = ZEND_FFI_TYPE(dcl->type);
7293 val->kind = (type->size > 0xffffffff) ? ZEND_FFI_VAL_UINT64 : ZEND_FFI_VAL_UINT32;
7294 val->u64 = type->size;
7295 zend_ffi_type_dtor(dcl->type);
7334 val->u64 = ZEND_FFI_TYPE(dcl->type)->align;
7335 zend_ffi_type_dtor(dcl->type);