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

Cookbook Chapter 7: Introspecting a Trampoline for a Wrapper. More...

#include <infix/infix.h>
#include <stdbool.h>
#include <stdio.h>
Include dependency graph for Ch07_IntrospectWrapper.c:

Functions

static int add_and_multiply (int a, double b)
 
static bool dynamic_wrapper (infix_forward_t *trampoline, void *target_func, void **args, size_t num_provided_args, void *ret_buffer)
 A conceptual generic "wrapper" function for an unbound trampoline.
 
int main ()
 

Detailed Description

Cookbook Chapter 7: Introspecting a Trampoline for a Wrapper.

This example demonstrates how a language binding or a generic wrapper function can use the trampoline introspection API to validate arguments at runtime before making an FFI call. This allows for more robust error checking.

Function Documentation

◆ add_and_multiply()

static int add_and_multiply ( int  a,
double  b 
)
static

◆ dynamic_wrapper()

static bool dynamic_wrapper ( infix_forward_t trampoline,
void *  target_func,
void **  args,
size_t  num_provided_args,
void *  ret_buffer 
)
static

A conceptual generic "wrapper" function for an unbound trampoline.

In a real language binding, this function would take language-native objects as arguments, unbox them into a C void** array, and perform type checking.

Parameters
trampolineAn unbound trampoline for the desired signature.
target_funcThe native C function to call.
argsAn array of pointers to the C argument values.
num_provided_argsThe number of arguments provided by the caller.
ret_bufferA buffer to receive the return value.
Returns
true on success, false on failure.

◆ main()

int main ( void  )