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

Unit test for reverse trampolines (callbacks) with primitive C types. More...

#include "common/double_tap.h"
#include <infix/infix.h>
#include <math.h>
#include <string.h>
Include dependency graph for 301_primitives.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

int int_callback_handler (int a, int b)
 A type-safe handler for an int(int, int) callback.
 
float float_callback_handler (float a, float b)
 A type-safe handler for a float(float, float) callback.
 
void void_callback_handler (int check_val)
 A type-safe handler for a void(int) callback.
 
void int_closure_handler (infix_context_t *context, void *return_value, void **args)
 A generic closure handler for an int(int, int) signature.
 
void float_closure_handler (infix_context_t *context, void *return_value, void **args)
 A generic closure handler for a float(float, float) signature.
 
void void_closure_handler (infix_context_t *context, void *return_value, void **args)
 A generic closure handler for a void(int) signature.
 
void execute_int_callback (int(*func_ptr)(int, int), int x, int y)
 
void execute_float_callback (float(*func_ptr)(float, float), float a, float b)
 
void execute_void_callback (void(*func_ptr)(int), int val)
 
 subtest ("Callback with signature: int(int, int)")
 
 subtest ("Callback with signature: float(float, float)")
 
 subtest ("Callback with signature: void(int)")
 

Variables

 TEST
 

Detailed Description

Unit test for reverse trampolines (callbacks) with primitive C types.

This test file is the reverse-call counterpart to 001_primitives.c. It verifies that infix can correctly generate a callable C function pointer from a user-provided handler function for all basic primitive types.

For each primitive type, it tests two distinct reverse trampoline models:

  1. Type-Safe Callback (infix_reverse_create_callback_manual):** The user provides a C handler with a native, type-safe signature (e.g., int handler(int, int)). This is the high-level, convenient API.
  2. **Generic Closure (infix_reverse_create_closure_manual):** The user provides a generic handler (infix_closure_handler_fn) that receives arguments as a `void` array. This is the low-level, more flexible API, typically used for language bindings.

The test creates a JIT-compiled function pointer for each model and passes it to a C "harness" function. The harness calls the pointer, and the test verifies that the user-provided handler was invoked correctly and that the return value was transmitted back to the harness.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ execute_float_callback()

void execute_float_callback ( float(*)(float, float)  func_ptr,
float  a,
float  b 
)

◆ execute_int_callback()

void execute_int_callback ( int(*)(int, int)  func_ptr,
int  x,
int  y 
)

◆ execute_void_callback()

void execute_void_callback ( void(*)(int)  func_ptr,
int  val 
)

◆ float_callback_handler()

float float_callback_handler ( float  a,
float  b 
)

A type-safe handler for a float(float, float) callback.

◆ float_closure_handler()

void float_closure_handler ( infix_context_t context,
void *  return_value,
void **  args 
)

A generic closure handler for a float(float, float) signature.

◆ int_callback_handler()

int int_callback_handler ( int  a,
int  b 
)

A type-safe handler for an int(int, int) callback.

◆ int_closure_handler()

void int_closure_handler ( infix_context_t context,
void *  return_value,
void **  args 
)

A generic closure handler for an int(int, int) signature.

◆ subtest() [1/3]

subtest ( "Callback with signature: float(float, float)"  )

◆ subtest() [2/3]

subtest ( "Callback with signature: int(int, int)"  )

◆ subtest() [3/3]

subtest ( "Callback with signature: void(int)"  )

◆ void_callback_handler()

void void_callback_handler ( int  check_val)

A type-safe handler for a void(int) callback.

◆ void_closure_handler()

void void_closure_handler ( infix_context_t context,
void *  return_value,
void **  args 
)

A generic closure handler for a void(int) signature.

Variable Documentation

◆ TEST

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