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

Tests fundamental FFI operations involving pointers. 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 strchr-like function to test pointer arguments and return values.
 
void modify_data_via_pointers (int *a, double *b)
 Modifies the data pointed to by its arguments.
 
bool check_if_null (void *ptr)
 Checks if the pointer it received is nullptr.
 
 subtest ("Passing and returning pointers")
 
 subtest ("Modifying data via pointer arguments")
 
 subtest ("Passing nullptr pointers")
 

Variables

 TEST
 

Detailed Description

Tests fundamental FFI operations involving pointers.

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 can correctly handle pointers as both arguments and return values. It covers three essential scenarios:

  1. Passing and Returning Pointers: A function similar to strchr is called to ensure that a pointer passed into a function and a pointer returned from a function both retain their correct values.
  2. Modifying Data Via Pointers: A function is called with pointers to local variables. The test verifies that the native function can dereference these pointers and modify the original data in the caller's stack frame, a common C idiom.
  3. Passing nullptr Pointers: A nullptr pointer is passed to a native function to ensure it is transmitted correctly without being corrupted or causing a crash.

Macro Definition Documentation

◆ DBLTAP_IMPLEMENTATION

#define DBLTAP_IMPLEMENTATION

Function Documentation

◆ check_if_null()

bool check_if_null ( void *  ptr)

Checks if the pointer it received is nullptr.

◆ find_char_in_string()

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

A strchr-like function to test pointer arguments and return values.

◆ modify_data_via_pointers()

void modify_data_via_pointers ( int *  a,
double *  b 
)

Modifies the data pointed to by its arguments.

◆ 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:132