X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Flibffi.c;h=6935ef9c7f760cd4df46cef545169f20c76bf9cb;hp=d01d907d36db2ded651f2eaaa8ee0c4336ff236d;hb=4fd6435041048363289eb7b9243cee39b6901e4e;hpb=53495ef4bd0321f7f92dd05eef8e01b90d7b415a diff --git a/src/libffi.c b/src/libffi.c index d01d907..6935ef9 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -105,6 +105,11 @@ static void psi_ffi_prep_va(ffi_cif *base, ffi_cif *signature, size_t argc, size assert(FFI_OK == rc); } +#if HAVE_INT128 +static ffi_type *ffi_type_sint128; +static ffi_type *ffi_type_uint128; +#endif + static inline ffi_type *psi_ffi_decl_arg_type(struct psi_decl_arg *darg); static inline ffi_type *psi_ffi_token_type(token_t t) { @@ -130,13 +135,16 @@ static inline ffi_type *psi_ffi_token_type(token_t t) { return &ffi_type_sint64; case PSI_T_UINT64: return &ffi_type_uint64; +#if HAVE_INT128 + case PSI_T_INT128: + return ffi_type_sint128; + case PSI_T_UINT128: + return ffi_type_uint128; +#endif case PSI_T_BOOL: return &ffi_type_uchar; - case PSI_T_INT: case PSI_T_ENUM: return &ffi_type_sint; - case PSI_T_LONG: - return &ffi_type_slong; case PSI_T_FLOAT: return &ffi_type_float; case PSI_T_DOUBLE: @@ -217,7 +225,7 @@ static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { maxalign = type->alignment; } - assert(type->size == darg->layout->len); + assert(type->size <= darg->layout->len); if ((padding = psi_offset_padding(darg->layout->pos - offset, type->alignment))) { if (nels + padding + 1 > argc) { argc += padding; @@ -701,7 +709,43 @@ static void *psi_ffi_query(struct psi_context *C, enum psi_context_query q, void return NULL; } +static ZEND_RESULT_CODE psi_ffi_load() +{ +#if HAVE_INT128 + ffi_type *i128, *u128; + + i128 = calloc(1, 3*sizeof(ffi_type)); + i128->type = FFI_TYPE_STRUCT; + i128->size = 0; + i128->elements = (ffi_type **) (i128 + 1); + i128->elements[0] = &ffi_type_sint64; + i128->elements[1] = &ffi_type_sint64; + + ffi_type_sint128 = i128; + + u128 = calloc(1, 3*sizeof(ffi_type)); + u128->type = FFI_TYPE_STRUCT; + u128->size = 0; + u128->elements = (ffi_type **) (u128 + 1); + u128->elements[0] = &ffi_type_uint64; + u128->elements[1] = &ffi_type_uint64; + + ffi_type_uint128 = u128; +#endif + return SUCCESS; +} + +static void psi_ffi_free() +{ +#if HAVE_INT128 + free(ffi_type_sint128); + free(ffi_type_uint128); +#endif +} + static struct psi_context_ops ops = { + psi_ffi_load, + psi_ffi_free, psi_ffi_init, psi_ffi_dtor, psi_ffi_compile,