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

Unit test for FFI calls involving pointer types. More...

#include "common/double_tap.h"
#include <infix/infix.h>
#include <math.h>
#include <string.h>
Include dependency graph for 201_basic.c:

Macros

#define DBLTAP_IMPLEMENTATION
 

Functions

const char * find_char_in_string (const char *s, int c)
 A C function that takes a string and a character, and returns a pointer into the string.
 
void modify_data_via_pointers (int *a, double *b)
 A C function that modifies the caller's data through pointers.
 
bool check_if_null (void *ptr)
 A simple helper to check if a received pointer is NULL.
 
 subtest ("Passing and returning pointers")
 
 subtest ("Modifying data via pointer arguments")
 
 subtest ("Passing nullptr pointers")
 

Variables

 TEST
 

Detailed Description

Unit test for FFI calls involving pointer types.

This test file verifies that the infix library correctly handles pointer arguments and return values. Pointers are fundamental to C, and their correct handling (passing by value, dereferencing) is critical for any FFI library.

The test covers three key scenarios:

  1. Passing and Returning Pointers: A call is made to a C function that takes a const char* and returns a const char* (the result of strchr). This validates that pointer values themselves are passed and returned correctly.
  2. Modifying Data Via Pointers: A call is made to a C function that takes pointers to an int and a double (int*, double*) and modifies the data at those addresses. This verifies that the JIT-compiled code correctly passes the pointers, allowing the callee to dereference them and modify the caller's original data.
  3. Passing nullptr: Verifies that a NULL pointer can be correctly passed through the FFI boundary and is received as NULL by the callee.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ check_if_null()

bool check_if_null ( void *  ptr)

A simple helper to check if a received pointer is NULL.

◆ find_char_in_string()

const char * find_char_in_string ( const char *  s,
int  c 
)

A C function that takes a string and a character, and returns a pointer into the string.

◆ modify_data_via_pointers()

void modify_data_via_pointers ( int *  a,
double *  b 
)

A C function that modifies the caller's data through pointers.

◆ subtest() [1/3]

subtest ( "Modifying data via pointer arguments"  )

◆ subtest() [2/3]

subtest ( "Passing and returning pointers"  )

◆ subtest() [3/3]

subtest ( "Passing nullptr pointers"  )

Variable Documentation

◆ TEST

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