|
| 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") |
| |
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:
- 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.
- 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.
- Passing
nullptr: Verifies that a NULL pointer can be correctly passed through the FFI boundary and is received as NULL by the callee.