infix
A JIT-Powered FFI Library for C
|
Tests passing and returning C 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) |
Receives a Number union and processes it as an integer. | |
float | process_number_union_as_float (Number num) |
Receives a Number union and processes it as a float. | |
Number | return_number_union (int selector) |
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) |
Tests passing and returning C unions by value.
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 test suite verifies that the library correctly handles C union
types according to the target platform's ABI. It ensures that the size and alignment are calculated correctly and that the data is placed in the appropriate registers or stack locations.
The suite covers two primary scenarios:
Number
union is passed to native functions that interpret its contents as either an int
or a double
. This implicitly verifies the ABI classification rules (e.g., on System V x64, this union is passed in an XMM register, while on Windows x64 it's passed in a GPR).Number
union by value, and the test verifies that the returned data is correct. #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 | ) |
Receives a Number union and processes it as a float.
int process_number_union_as_int | ( | Number | num | ) |
Receives a Number union and processes it as an integer.
Number return_number_union | ( | int | selector | ) |
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 |