fix calling convention and arg types
authorMichael Wallner <mike@php.net>
Wed, 28 Nov 2018 13:23:20 +0000 (14:23 +0100)
committerMichael Wallner <mike@php.net>
Tue, 4 Dec 2018 11:13:50 +0000 (12:13 +0100)
src/libffi.c
src/libjit.c
src/types/decl_type.c
src/types/number.c

index 6f808d4ce2360c4d1ba49079682e247a6fa72417..fe2bc614b2c2bc21617cc0c73dcf4120a3cad445 100644 (file)
@@ -229,10 +229,15 @@ static bool psi_ffi_init(struct psi_context *C)
 {
        ffi_status rc;
        struct psi_ffi_context *context = pecalloc(1, sizeof(*context), 1);
+       ffi_abi abi = FFI_DEFAULT_ABI;
+
+#if HAVE_FFI_FASTCALL
+       abi = FFI_FASTCALL;
+#endif
 
        context->params[0] = &ffi_type_pointer;
        context->params[1] = &ffi_type_pointer;
-       rc = ffi_prep_cif(&context->signature, FFI_DEFAULT_ABI, 2, &ffi_type_void,
+       rc = ffi_prep_cif(&context->signature, abi, 2, &ffi_type_void,
                        context->params);
 
        if (FFI_OK != rc) {
@@ -292,22 +297,6 @@ static void psi_ffi_composite_dtor(struct psi_context *C,
                darg->engine.info = NULL;
                darg->engine.type = NULL;
 
-               struct psi_plist *args = NULL;
-               struct psi_decl_type *dtype = psi_decl_type_get_real(darg->type);
-
-               if (dtype->type == PSI_T_STRUCT) {
-                       args = dtype->real.strct->args;
-               } else if (dtype->type == PSI_T_UNION) {
-                       args = dtype->real.unn->args;
-               }
-
-               size_t i = 0;
-               struct psi_decl_arg *tmp;
-
-               while (psi_plist_get(args, i++, &tmp)) {
-                       psi_ffi_composite_dtor(C, tmp);
-               }
-
                psi_plist_free(info->eles);
                pefree(info, 1);
        }
index 0b4989b1dd2f92f35cb96dd2997e8078633cceee..37703e4606d8e9cafa63b7c018863ef4cd3ae1b8 100644 (file)
@@ -215,7 +215,7 @@ static bool psi_jit_init(struct psi_context *C)
                return false;
        }
 
-       context->signature = jit_type_create_signature(jit_abi_cdecl, jit_type_void,
+       context->signature = jit_type_create_signature(jit_abi_fastcall, jit_type_void,
                        params, 2, 1);
        if (!context->signature) {
                jit_context_destroy(context->jit);
@@ -252,8 +252,9 @@ static bool psi_jit_composite_init(struct psi_context *C,
 
        info = pecalloc(1, sizeof(*info), 1);
        info->eles = psi_plist_init((psi_plist_dtor) psi_jit_type_free);
+       psi_context_composite_type_elements(C, darg, &info->eles);
        info->strct = jit_type_create_struct((jit_type_t *)
-                       psi_context_composite_type_elements(C, darg, &info->eles),
+                       psi_plist_eles(info->eles),
                        psi_plist_count(info->eles), 0);
 
        darg->engine.info = info;
@@ -272,7 +273,8 @@ static void psi_jit_composite_dtor(struct psi_context *C,
                darg->engine.type = NULL;
 
                jit_type_free(info->strct);
-               psi_plist_free(info->eles);
+               /* just free */
+               pefree(info->eles, 1);
                pefree(info, 1);
        }
 }
@@ -307,7 +309,7 @@ static bool psi_jit_extvar_init(struct psi_context *C,
        jit_context_build_start(ctx->jit);
 
        info->get.signature = jit_type_create_signature(jit_abi_cdecl,
-                       psi_context_decl_arg_full_type(C, evar->getter->func), NULL, 0, 1);
+                       psi_context_decl_arg_call_type(C, evar->getter->func), NULL, 0, 1);
        if (!info->get.signature) {
                goto failure;
        }
@@ -319,7 +321,7 @@ static bool psi_jit_extvar_init(struct psi_context *C,
 
        info->set.params[0] = psi_context_decl_arg_call_type(C, evar->arg);
        info->set.signature = jit_type_create_signature(jit_abi_cdecl,
-                       psi_context_decl_arg_full_type(C, evar->setter->func),
+                       psi_context_decl_arg_call_type(C, evar->setter->func),
                        info->set.params, 1, 1);
        if (!info->set.signature) {
                goto failure;
@@ -565,6 +567,9 @@ static void psi_jit_layoutof_type(struct psi_context *C, void *orig_type,
 {
        l->pos = jit_type_get_alignment(orig_type);
        l->len = jit_type_get_size(orig_type);
+
+       assert(l->pos);
+       assert(l->len);
 }
 
 static struct psi_context_ops ops = {
index 66fb5f4e3a4d4d1be90fa5200605a70bc84c84cf..f5086f14eeb73aa222a1cfb69ef0853e933c27e6 100644 (file)
@@ -345,6 +345,7 @@ void psi_decl_type_dump(struct psi_dump *dump, struct psi_decl_type *t, unsigned
        case PSI_T_UNION:
                PSI_DUMP(dump, "union ");
                if (psi_decl_type_is_anon(t->name, "union")) {
+                       PSI_DUMP(dump, "/*::(%zu, %zu)*/", t->real.unn->align, t->real.unn->size);
                        psi_decl_type_dump_args_with_layout(dump, t->real.unn->args, level);
                        return;
                }
index c3ec31b6d99ac83b9c07da92764b9dadd2bb02c3..10505dfe8988169b229b71de1f509d415e202038 100644 (file)
@@ -576,7 +576,7 @@ static inline bool psi_number_validate_number(struct psi_data *data, struct psi_
                                                return true;
                                        }
                                }
-                               break;
+                               /* no break */
                        default:
                                zend_string_release(exp->data.numb);
                                exp->type = PSI_T_INT64;