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

Unit test for advanced reverse trampoline (callback) scenarios. More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
#include <string.h>
Include dependency graph for 303_advanced.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Typedefs

typedef int(* int_func_int) (int)
 
typedef int_func_int(* callback_provider) (void)
 

Functions

void pointer_modify_handler (int *p)
 
void execute_pointer_modify_callback (void(*func_ptr)(int *), int *p)
 
void inner_callback_handler (int val)
 
void execute_callback_as_arg_harness (void(*cb)(int))
 
int final_multiply_handler (int val)
 
void closure_provider_handler (infix_context_t *context, void *ret, void **args)
 
int call_returned_callback_harness (callback_provider provider, int val)
 
 subtest ("Callback modifies data via pointer")
 
 subtest ("Callback passed as an argument")
 
 subtest ("Closure returns a function pointer (via user_data)")
 

Variables

 TEST
 

Detailed Description

Unit test for advanced reverse trampoline (callback) scenarios.

This test file explores more complex and dynamic uses of reverse trampolines, verifying that the library's features compose correctly.

The test covers:

  1. Modifying Data via Pointers: A callback is created for a function that takes a pointer (void(int*)). The test verifies that when the C harness calls the JIT-compiled pointer, the handler is able to correctly dereference the pointer and modify the original data in the harness.
  2. Callbacks as Arguments: This is a "callback inception" test. It creates an "inner" callback and passes its JIT-compiled function pointer as an argument (via a forward trampoline) to a C "harness" function. The harness then calls the function pointer it received. This complex chain tests the interoperability of forward and reverse trampolines.
  3. Closures Returning Function Pointers: A "provider" closure is created. Its user_data is set to the function pointer of another, "worker" callback. When the provider is called, its handler retrieves the worker's function pointer from user_data and returns it. The C harness then calls this returned pointer, verifying that function pointers can be passed as data through closures.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Typedef Documentation

◆ callback_provider

typedef int_func_int(* callback_provider) (void)

◆ int_func_int

typedef int(* int_func_int) (int)

Function Documentation

◆ call_returned_callback_harness()

int call_returned_callback_harness ( callback_provider  provider,
int  val 
)

◆ closure_provider_handler()

void closure_provider_handler ( infix_context_t context,
void *  ret,
void **  args 
)

◆ execute_callback_as_arg_harness()

void execute_callback_as_arg_harness ( void(*)(int)  cb)

◆ execute_pointer_modify_callback()

void execute_pointer_modify_callback ( void(*)(int *)  func_ptr,
int *  p 
)

◆ final_multiply_handler()

int final_multiply_handler ( int  val)

◆ inner_callback_handler()

void inner_callback_handler ( int  val)

◆ pointer_modify_handler()

void pointer_modify_handler ( int *  p)

◆ subtest() [1/3]

subtest ( "Callback modifies data via pointer"  )

◆ subtest() [2/3]

subtest ( "Callback passed as an argument"  )

◆ subtest() [3/3]

subtest ( "Closure returns a function pointer (via user_data)"  )

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(3)
#define plan(count)
Definition double_tap.h:163