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

Unit test for passing and returning large aggregates by reference. More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
Include dependency graph for 102_by_reference.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

int process_large_struct (LargeStruct s)
 A C function that takes a large struct, which the ABI will pass by reference.
 
LargeStruct return_large_struct (int base_val)
 A C function that returns a large struct, which the ABI will return by reference.
 
int process_npot_struct (NonPowerOfTwoStruct s)
 A C function that takes a struct whose size is not a power of two.
 
 subtest ("Large struct (>16 bytes) passed and returned by reference/stack")
 
 subtest ("Non-power-of-two sized struct")
 

Variables

 TEST
 

Detailed Description

Unit test for passing and returning large aggregates by reference.

This test file validates the ABI implementation for handling aggregates (structs) that are too large to be passed or returned directly in registers. According to most ABIs (including System V and Windows x64), such aggregates are handled "by reference."

  • Passing by Reference: The caller allocates memory for the struct, and a pointer to this memory is passed in a general-purpose register.
  • Returning by Reference: The caller allocates space for the return value and passes a hidden pointer to this space as the first (often invisible) argument to the function. The callee then writes its result to this location.

This test verifies both scenarios for:

  • A LargeStruct (24 bytes), which is guaranteed to be passed by reference.
  • A NonPowerOfTwoStruct (12 bytes), which is also passed by reference on many ABIs (like Windows x64) that have strict size rules for register passing.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ process_large_struct()

int process_large_struct ( LargeStruct  s)

A C function that takes a large struct, which the ABI will pass by reference.

◆ process_npot_struct()

int process_npot_struct ( NonPowerOfTwoStruct  s)

A C function that takes a struct whose size is not a power of two.

◆ return_large_struct()

LargeStruct return_large_struct ( int  base_val)

A C function that returns a large struct, which the ABI will return by reference.

◆ subtest() [1/2]

subtest ( "Large struct (>16 bytes) passed and returned by reference/stack"  )

◆ subtest() [2/2]

subtest ( "Non-power-of-two sized struct"  )

Variable Documentation

◆ TEST

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