X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Flibffi.c;h=1741513b02df21a3d8409e441bf920a5ae9504d4;hp=e859dbd1bad9b687c40a14ef46d78bf96819aa10;hb=a2a2428b6e50787a7f33151275fb5ceabc7c5621;hpb=ddeb4918bce67ed63c5f4c8c4e250e92ebdef89d diff --git a/src/libffi.c b/src/libffi.c index e859dbd..1741513 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -156,6 +156,18 @@ static void psi_ffi_callback(ffi_cif *sig, void *result, void **args, void *data } static inline ffi_abi psi_ffi_abi(const char *convention) { + if (FFI_LAST_ABI - 2 != FFI_FIRST_ABI) { +#ifdef HAVE_FFI_STDCALL + if (!strcasecmp(convention, "stdcall")) { + return FFI_STDCALL; + } +#endif +#ifdef HAVE_FFI_FASTCALL + if (!strcasecmp(convention, "fastcall")) { + return FFI_FASTCALL; + } +#endif + } return FFI_DEFAULT_ABI; } @@ -288,14 +300,24 @@ static size_t psi_ffi_struct_type_pad(ffi_type **els, size_t padding) { } static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { - size_t i = 0, argc = psi_plist_count(strct->args), nels = 0, offset = 0, maxalign = 0; - ffi_type **tmp, **els = calloc(argc + 1, sizeof(*els)); + size_t i = 0, argc, nels = 0, offset = 0, maxalign = 0, last_arg_pos = -1; + ffi_type **tmp, **els; struct psi_decl_arg *darg; + argc = psi_plist_count(strct->args); + els = calloc(argc + 1, sizeof(*els)); + while (psi_plist_get(strct->args, i++, &darg)) { - ffi_type *type = malloc(sizeof(*type)); + ffi_type *type; size_t padding; + if (darg->layout->pos == last_arg_pos) { + /* skip bit fields */ + continue; + } + last_arg_pos = darg->layout->pos; + + type = malloc(sizeof(*type)); *type = *psi_ffi_decl_arg_type(darg); if (type->alignment > maxalign) { @@ -330,7 +352,17 @@ static ffi_type **psi_ffi_struct_type_elements(struct psi_decl_struct *strct) { assert(offset <= strct->size); if (offset < strct->size) { - psi_ffi_struct_type_pad(&els[nels], strct->size - offset); + size_t padding = strct->size - offset; + + tmp = realloc(els, (padding + argc + 1) * sizeof(*els)); + if (tmp) { + els = tmp; + } else { + free(els); + return NULL; + } + psi_ffi_struct_type_pad(&els[nels], padding); + els[argc + padding] = NULL; } return els;