infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Ch08_ArenaCallFrame.c File Reference

Cookbook Chapter 8: Building a Dynamic Call Frame with an Arena. More...

#include <infix/infix.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for Ch08_ArenaCallFrame.c:

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 ()
 

Detailed Description

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.

Function Documentation

◆ dynamic_ffi_call()

static void dynamic_ffi_call ( infix_forward_t trampoline,
void *  target_func,
int  arg_count,
  ... 
)
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.

◆ main()

int main ( void  )

◆ process_user_data()

static void process_user_data ( int  id,
double  score,
const char *  name 
)
static