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

Unit test for the Manual API's struct and union layout calculations. More...

#include "common/double_tap.h"
#include <infix/infix.h>
#include <stddef.h>
Include dependency graph for 005_layouts.c:

Classes

struct  test_struct_padding
 
struct  test_struct_no_padding
 
struct  test_struct_nested
 
struct  test_struct_packed
 
union  test_union
 

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

 subtest ("Struct with standard padding")
 
 subtest ("Struct with no padding")
 
 subtest ("Nested struct")
 
 subtest ("Packed struct (pack 1)")
 
 subtest ("Union layout")
 
 infix_arena_destroy (arena)
 

Variables

 TEST
 
infix_arena_tarena = infix_arena_create(4096)
 

Detailed Description

Unit test for the Manual API's struct and union layout calculations.

This test file verifies that the layout algorithms in types.c (specifically infix_type_create_struct and infix_type_create_union) produce memory layouts that are identical to those produced by the host C compiler.

It defines several native C struct and union types and then programmatically creates their infix_type equivalents. It then asserts that the size, alignment, and member offset fields of the generated types match the results of the sizeof, _Alignof, and offsetof operators on the native types.

The test covers:

  • A struct with standard internal padding.
  • A struct with no padding.
  • A struct containing a nested struct.
  • A packed struct (#pragma pack(1)).
  • A union with members of different sizes and alignments.

This test is crucial for ensuring that infix can correctly and portably reason about the memory representation of C data structures.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ infix_arena_destroy()

infix_arena_destroy ( arena  )

◆ subtest() [1/5]

subtest ( "Nested struct"  )

◆ subtest() [2/5]

subtest ( "Packed struct (pack 1)"  )

◆ subtest() [3/5]

subtest ( "Struct with no padding"  )

◆ subtest() [4/5]

subtest ( "Struct with standard padding"  )

◆ subtest() [5/5]

subtest ( "Union layout"  )

Variable Documentation

◆ arena

◆ TEST

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