static ffi_status psi_ffi_prep_closure(ffi_closure **closure, void **code, ffi_cif *sig, void (*handler)(ffi_cif*,void*,void**,void*), void *data) {
*closure = psi_ffi_closure_alloc(sizeof(ffi_closure), code);
- ZEND_ASSERT(*closure != NULL);
+ assert(*closure != NULL);
#if PSI_HAVE_FFI_PREP_CLOSURE_LOC
return ffi_prep_closure_loc(*closure, sig, handler, data, *code);
rc = ffi_prep_cif(signature, base->abi, argc + va_count, base->rtype, param_types);
#endif
- ZEND_ASSERT(FFI_OK == rc);
+ assert(FFI_OK == rc);
}
static inline ffi_type *psi_ffi_decl_arg_type(struct psi_decl_arg *darg);
}
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;
}
rc = ffi_prep_cif(&call->signature, psi_ffi_abi(decl->abi->convention),
c, psi_ffi_decl_arg_type(decl->func), call->params);
- ZEND_ASSERT(FFI_OK == rc);
+ assert(FFI_OK == rc);
return call;
}
static inline ffi_type *psi_ffi_token_type(token_t t) {
switch (t) {
default:
- ZEND_ASSERT(0);
+ assert(0);
/* no break */
case PSI_T_VOID:
return &ffi_type_void;
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 **els = calloc(argc + 1, sizeof(*els));
+ ffi_type **tmp, **els = calloc(argc + 1, sizeof(*els));
struct psi_decl_arg *darg;
while (psi_plist_get(strct->args, i++, &darg)) {
if ((padding = psi_offset_padding(darg->layout->pos - offset, type->alignment))) {
if (nels + padding + 1 > argc) {
argc += padding;
- els = realloc(els, (argc + 1) * sizeof(*els));
+ tmp = realloc(els, (argc + 1) * sizeof(*els));
+ if (tmp) {
+ els = tmp;
+ } else {
+ free(els);
+ return NULL;
+ }
els[argc] = NULL;
}
psi_ffi_struct_type_pad(&els[nels], padding);
L->params[0] = &ffi_type_pointer;
L->params[1] = &ffi_type_pointer;
rc = ffi_prep_cif(&L->signature, FFI_DEFAULT_ABI, 2, &ffi_type_void, L->params);
- ZEND_ASSERT(rc == FFI_OK);
+ assert(rc == FFI_OK);
return L;
}