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

Tests passing structs that contain pointer members. More...

#include "common/double_tap.h"
#include "types.h"
#include <infix/infix.h>
#include <string.h>
Include dependency graph for 202_in_structs.c:

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_tarena = infix_arena_create(4096)
 
infix_struct_membermembers
 
infix_typestruct_type = nullptr
 
infix_typereturn_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_tunbound_t = nullptr
 
int unbound_result = 0
 
infix_unbound_cif_func unbound_cif = infix_forward_get_unbound_code(unbound_t)
 
infix_forward_tbound_t = nullptr
 
int bound_result = 0
 
infix_cif_func bound_cif = infix_forward_get_code(bound_t)
 

Detailed Description

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.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ if()

if ( okinfix_type_create_struct(arena, &struct_type, members, 2)==INFIX_SUCCESS, "Type created")

◆ infix_arena_destroy()

infix_arena_destroy ( arena  )

◆ infix_forward_destroy() [1/2]

infix_forward_destroy ( bound_t  )

◆ infix_forward_destroy() [2/2]

infix_forward_destroy ( unbound_t  )

◆ ok() [1/4]

ok ( bound_result  = =550,
"Bound call correct"   
)

◆ ok() [2/4]

ok ( infix_forward_create_manual(&,, &, 1, 1, *void  process_pointer_struct)

◆ ok() [3/4]

ok ( infix_forward_create_unbound_manual &,, &, 1,  1struct_type = =INFIX_SUCCESS,
"Unbound created"   
)

◆ ok() [4/4]

ok ( unbound_result  = =550,
"Unbound call correct"   
)

◆ process_pointer_struct()

int process_pointer_struct ( PointerStruct  ps)

Receives a PointerStruct and dereferences its members to verify them.

Returns
An integer based on the dereferenced value to confirm success.

◆ unbound_cif()

unbound_cif ( (void *)  process_pointer_struct,
unbound_result,
args   
)

Variable Documentation

◆ arena

◆ args

void* args[] = {&struct_instance}

◆ bound_cif

◆ bound_result

bound_cif & bound_result = 0

◆ bound_t

◆ members

members[1]
Initial value:
=
infix_arena_t * arena
Definition 202_in_structs.c:59
c23_nodiscard void * infix_arena_alloc(infix_arena_t *, size_t, size_t)
Allocates a block of memory from the arena with a specific alignment.
Definition arena.c:86
Describes a single member of an aggregate type (struct or union).
Definition infix.h:219

◆ return_type

◆ string_to_point_to

const char* string_to_point_to = "Hello Pointers"

◆ struct_instance

◆ struct_type

infix_type* struct_type = nullptr

◆ TEST

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

◆ unbound_cif

◆ unbound_result

int unbound_result = 0

◆ unbound_t

infix_forward_t* unbound_t = nullptr

◆ value_to_point_to

int value_to_point_to = 500