-static void psi_ffi_handler(ffi_cif *sig, void *result, void **args, void *data)
-{
- struct psi_ffi_call *call = data;
-
- psi_context_call(call->context, *(zend_execute_data **)args[0], *(zval **)args[1], call->impl.fn.impl);
-}
-
-static void psi_ffi_callback(ffi_cif *sig, void *result, void **args, void *data)
-{
- struct psi_ffi_call *call = data, *impl_call = call->impl.cb.impl_call;
-
- if (impl_call->impl.fn.frame) {
- struct psi_call_frame_callback cbdata;
-
- cbdata.cb = call->impl.cb.let_exp;
- cbdata.argc = sig->nargs;
- cbdata.argv = args;
- cbdata.rval = result;
-
- psi_call_frame_do_callback(impl_call->impl.fn.frame, &cbdata);
- } else {
- assert(0);
- }
-}
-
-static inline ffi_abi psi_ffi_abi(const char *convention) {
- return FFI_DEFAULT_ABI;
-}
-
-static inline struct psi_ffi_call *psi_ffi_call_alloc(struct psi_context *C, struct psi_decl *decl) {
- int rc;
- size_t i, c = psi_plist_count(decl->args);
- struct psi_ffi_call *call = calloc(1, sizeof(*call) + 2 * c * sizeof(void *));
- struct psi_decl_arg *arg;
-
- decl->info = call;
- call->context = C;
-
- for (i = 0; psi_plist_get(decl->args, i, &arg); ++i) {
- call->params[i] = psi_ffi_decl_arg_type(arg);
- }
- call->params[c] = NULL;
-
- 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);
-
- return call;
-}