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

Tests reverse trampolines (callbacks) with struct and union arguments/returns. More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
#include <math.h>
#include <string.h>
Include dependency graph for 302_aggregates.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

Point point_callback_handler (Point p)
 
int large_struct_pass_handler (LargeStruct s)
 
LargeStruct large_struct_return_handler (int a)
 
int vector4_callback_handler (Vector4 v)
 
Number number_union_return_handler (float f)
 
void point_closure_handler (infix_context_t *ctx, void *ret, void **args)
 
void execute_point_callback (Point(*func_ptr)(Point), Point p)
 
void execute_large_struct_pass_callback (int(*func_ptr)(LargeStruct), LargeStruct s)
 
void execute_large_struct_return_callback (LargeStruct(*func_ptr)(int), int a)
 
void execute_vector4_callback (int(*func_ptr)(Vector4), Vector4 v, int expected)
 
void execute_number_union_return_callback (Number(*func_ptr)(float), float f)
 
int process_packed_struct (PackedStruct p)
 
 subtest ("Callback with small struct: Point(Point)")
 
 subtest ("Callback with large struct argument: int(LargeStruct)")
 
 subtest ("Callback returning large struct: LargeStruct(int)")
 
 subtest ("Callback with struct containing array: int(Vector4)")
 
 subtest ("Callback returning union: Number(float)")
 
 subtest ("Packed struct")
 

Variables

 TEST
 

Detailed Description

Tests reverse trampolines (callbacks) with struct and union arguments/returns.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

This is a comprehensive test suite for verifying the reverse FFI (callback) functionality with aggregate types. It covers a wide range of scenarios that are highly dependent on the target platform's ABI rules.

The suite consolidates several previous tests and verifies:

  • Small Structs: Passing and returning a Point struct, which is small enough to be handled in registers on most platforms.
  • Large Structs (Pass by Reference): Passing a LargeStruct to a callback, which ABIs will handle by passing a pointer to a copy on the stack.
  • Large Structs (Return via Hidden Pointer): Returning a LargeStruct from a callback, which ABIs handle by having the caller provide a hidden pointer to a buffer where the result is written.
  • ABI-Specific Aggregates (HFA): Passing a Vector4 struct, which is treated as a Homogeneous Floating-point Aggregate on AArch64.
  • Unions: Returning a Number union from a callback.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ execute_large_struct_pass_callback()

void execute_large_struct_pass_callback ( int(*)(LargeStruct func_ptr,
LargeStruct  s 
)

◆ execute_large_struct_return_callback()

void execute_large_struct_return_callback ( LargeStruct(*)(int)  func_ptr,
int  a 
)

◆ execute_number_union_return_callback()

void execute_number_union_return_callback ( Number(*)(float)  func_ptr,
float  f 
)

◆ execute_point_callback()

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

◆ execute_vector4_callback()

void execute_vector4_callback ( int(*)(Vector4 func_ptr,
Vector4  v,
int  expected 
)

◆ large_struct_pass_handler()

int large_struct_pass_handler ( LargeStruct  s)

◆ large_struct_return_handler()

LargeStruct large_struct_return_handler ( int  a)

◆ number_union_return_handler()

Number number_union_return_handler ( float  f)

◆ point_callback_handler()

Point point_callback_handler ( Point  p)

◆ point_closure_handler()

void point_closure_handler ( infix_context_t ctx,
void *  ret,
void **  args 
)

◆ process_packed_struct()

int process_packed_struct ( PackedStruct  p)

◆ subtest() [1/6]

subtest ( "Callback returning large struct: LargeStruct(int)"  )

◆ subtest() [2/6]

subtest ( "Callback returning union: Number(float)"  )

◆ subtest() [3/6]

subtest ( "Callback with large struct argument: int(LargeStruct)"  )

◆ subtest() [4/6]

subtest ( "Callback with small struct: Point(Point)"  )

◆ subtest() [5/6]

subtest ( "Callback with struct containing array: int(Vector4)"  )

◆ subtest() [6/6]

subtest ( "Packed struct"  )

◆ vector4_callback_handler()

int vector4_callback_handler ( Vector4  v)

Variable Documentation

◆ TEST

TEST
Initial value:
{
plan(6)
#define plan(count)
Definition double_tap.h:132