|
infix
A JIT-Powered FFI Library for C
|
Cookbook Chapter 8: Building a Dynamic Call Frame with an Arena. More...
Functions | |
| static void | process_user_data (int id, double score, const char *name) |
| static void | dynamic_ffi_call (infix_forward_t *trampoline, void *target_func, int arg_count,...) |
| int | main () |
Cookbook Chapter 8: Building a Dynamic Call Frame with an Arena.
This example demonstrates an advanced, high-performance technique for language bindings: using an infix arena to build the entire call frame for an FFI call.
In a binding, you receive arguments from the host language (e.g., Python), unbox them into temporary C values, and create the void* args[] array of pointers to these temporaries. Using malloc for this in a tight loop is inefficient.
This recipe shows how to allocate both the unboxed C values AND the void** array from a single, short-lived arena. This is extremely fast and simplifies cleanup to a single infix_arena_destroy call, preventing memory leaks.
|
static |
This function simulates the core logic of a language binding's generic "call" function. It takes a va_list to represent dynamic arguments coming from a script.
| int main | ( | void | ) |
|
static |