|
infix
A JIT-Powered FFI Library for C
|
Unit test for passing and returning unions by value. More...
#include "common/double_tap.h"#include "types.h"#include <infix/infix.h>#include <math.h>#include <string.h>Macros | |
| #define | DBLTAP_IMPLEMENTATION |
Functions | |
| int | process_number_union_as_int (Number num) |
A C function that interprets a passed-in Number union as an integer. | |
| float | process_number_union_as_float (Number num) |
A C function that interprets a passed-in Number union as a float. | |
| Number | return_number_union (int selector) |
A C function that returns a Number union by value. | |
| if (!ok(status==INFIX_SUCCESS, "infix_type for Number union created successfully")) | |
| subtest ("Passing union as argument") | |
| subtest ("Returning union by value") | |
| infix_arena_destroy (arena) | |
Variables | |
| TEST | |
| infix_arena_t * | arena = infix_arena_create(4096) |
| infix_struct_member * | members |
| infix_type * | union_type = nullptr |
| infix_status | status = infix_type_create_union(arena, &union_type, members, 2) |
Unit test for passing and returning unions by value.
This test verifies that infix correctly handles C unions in FFI calls. A union is a special type of aggregate, and its handling by the ABI often follows the same rules as structs of the same size and alignment.
This test uses a simple Number union containing an int and a float. It verifies that:
infix_type for the union is created with the correct size (the size of the largest member) and alignment (the alignment of the most-aligned member).int or a float.This test is important for validating the aggregate classification logic for a type that is less common than structs but still a core part of the C language.
| #define DBLTAP_IMPLEMENTATION |
| if | ( | ! | okstatus==INFIX_SUCCESS, "infix_type for Number union created successfully" | ) |
| infix_arena_destroy | ( | arena | ) |
| float process_number_union_as_float | ( | Number | num | ) |
A C function that interprets a passed-in Number union as a float.
| int process_number_union_as_int | ( | Number | num | ) |
A C function that interprets a passed-in Number union as an integer.
| subtest | ( | "Passing union as argument" | ) |
| subtest | ( | "Returning union by value" | ) |
| infix_arena_t* arena = infix_arena_create(4096) |
| members[1] |
| infix_status status = infix_type_create_union(arena, &union_type, members, 2) |
| infix_type* union_type = nullptr |