infix
A JIT-Powered FFI Library for C
|
Tests passing structs that contain pointer members. More...
Macros | |
#define | DBLTAP_IMPLEMENTATION |
Functions | |
int | process_pointer_struct (PointerStruct ps) |
Receives a PointerStruct and dereferences its members to verify them. | |
if (!ok(infix_type_create_struct(arena, &struct_type, members, 2)==INFIX_SUCCESS, "Type created")) | |
ok (infix_forward_create_unbound_manual(&unbound_t, return_type, &struct_type, 1, 1)==INFIX_SUCCESS, "Unbound created") | |
unbound_cif ((void *) process_pointer_struct, &unbound_result, args) | |
ok (unbound_result==550, "Unbound call correct") | |
ok (infix_forward_create_manual(&bound_t, return_type, &struct_type, 1, 1,(void *) process_pointer_struct)==INFIX_SUCCESS, "Bound created") | |
ok (bound_result==550, "Bound call correct") | |
infix_forward_destroy (unbound_t) | |
infix_forward_destroy (bound_t) | |
infix_arena_destroy (arena) | |
Variables | |
TEST | |
infix_arena_t * | arena = infix_arena_create(4096) |
infix_struct_member * | members |
infix_type * | struct_type = nullptr |
infix_type * | return_type = infix_type_create_primitive(INFIX_PRIMITIVE_SINT32) |
int | value_to_point_to = 500 |
const char * | string_to_point_to = "Hello Pointers" |
PointerStruct | struct_instance = {&value_to_point_to, string_to_point_to} |
void * | args [] = {&struct_instance} |
infix_forward_t * | unbound_t = nullptr |
int | unbound_result = 0 |
infix_unbound_cif_func | unbound_cif = infix_forward_get_unbound_code(unbound_t) |
infix_forward_t * | bound_t = nullptr |
int | bound_result = 0 |
infix_cif_func | bound_cif = infix_forward_get_code(bound_t) |
Tests passing structs that contain pointer members.
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 the library's ability to handle aggregates that have pointers as members. This is a critical test as it combines the rules for aggregate passing with the rules for pointer passing.
The test defines a PointerStruct
containing an int*
and a const char*
. An instance of this struct is passed through the FFI to a native C function. The native function's primary goal is to verify that it can successfully dereference both pointers and access the original, correct data. The test succeeds if the native function receives valid pointers and can return a value based on the data they point to.
#define DBLTAP_IMPLEMENTATION |
if | ( | ! | okinfix_type_create_struct(arena, &struct_type, members, 2)==INFIX_SUCCESS, "Type created" | ) |
infix_arena_destroy | ( | arena | ) |
infix_forward_destroy | ( | bound_t | ) |
infix_forward_destroy | ( | unbound_t | ) |
ok | ( | bound_result | = =550 , |
"Bound call correct" | |||
) |
ok | ( | infix_forward_create_manual(&,, &, 1, 1, *void | process_pointer_struct | ) |
ok | ( | infix_forward_create_unbound_manual &,, &, 1, | 1struct_type = =INFIX_SUCCESS , |
"Unbound created" | |||
) |
ok | ( | unbound_result | = =550 , |
"Unbound call correct" | |||
) |
int process_pointer_struct | ( | PointerStruct | ps | ) |
Receives a PointerStruct and dereferences its members to verify them.
unbound_cif | ( | (void *) | process_pointer_struct, |
& | unbound_result, | ||
args | |||
) |
infix_arena_t* arena = infix_arena_create(4096) |
void* args[] = {&struct_instance} |
infix_cif_func bound_cif = infix_forward_get_code(bound_t) |
bound_cif & bound_result = 0 |
infix_forward_t* bound_t = nullptr |
members[1] |
infix_type* return_type = infix_type_create_primitive(INFIX_PRIMITIVE_SINT32) |
const char* string_to_point_to = "Hello Pointers" |
PointerStruct struct_instance = {&value_to_point_to, string_to_point_to} |
infix_type* struct_type = nullptr |
infix_unbound_cif_func unbound_cif = infix_forward_get_unbound_code(unbound_t) |
int unbound_result = 0 |
infix_forward_t* unbound_t = nullptr |
int value_to_point_to = 500 |