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

End-to-end unit test for passing and returning aggregate types (structs). More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
#include <math.h>
Include dependency graph for 006_end_to_end_calls.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

Point move_point (Point p, double dx, double dy)
 A C function to be called via a forward trampoline. Takes and returns a struct.
 
Point point_callback_handler (Point p)
 A C handler to be invoked by a reverse trampoline.
 
void execute_point_callback (Point(*func_ptr)(Point), Point p)
 A C "harness" function that simulates a C library calling our JIT-compiled callback.
 
 subtest ("Forward calls with aggregate types (structs)")
 
 subtest ("Reverse calls (callbacks) with aggregate types")
 

Variables

 TEST
 

Detailed Description

End-to-end unit test for passing and returning aggregate types (structs).

This test verifies that infix can correctly handle FFI calls where structs are passed by value as arguments and/or returned by value. This is a complex scenario that heavily depends on the correctness of both the type layout calculation and the ABI-specific classification and code generation logic.

The test covers:

  • Forward Call: A call from the test harness into a native C function (move_point) that takes a Point struct by value and returns one by value. This is tested with both bound and unbound trampolines.
  • Reverse Call: A native C function (execute_point_callback) calls a JIT-compiled function pointer generated by infix. This callback then invokes a C handler (point_callback_handler) that also takes and returns a Point struct by value.

This test serves as a high-level integration test, confirming that all the pieces of the library (parser, type system, ABI classifier, JIT emitter) work together correctly for a common and important use case.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ execute_point_callback()

void execute_point_callback ( Point(*)(Point func_ptr,
Point  p 
)

A C "harness" function that simulates a C library calling our JIT-compiled callback.

◆ move_point()

Point move_point ( Point  p,
double  dx,
double  dy 
)

A C function to be called via a forward trampoline. Takes and returns a struct.

◆ point_callback_handler()

Point point_callback_handler ( Point  p)

A C handler to be invoked by a reverse trampoline.

◆ subtest() [1/2]

subtest ( "Forward calls with aggregate types (structs)"  )

◆ subtest() [2/2]

subtest ( "Reverse calls (callbacks) with aggregate types"  )

Variable Documentation

◆ TEST

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