infix
A JIT-Powered FFI Library for C
|
Tests advanced reverse trampoline (callback) patterns. More...
Macros | |
#define | DBLTAP_IMPLEMENTATION |
Typedefs | |
typedef int(* | int_func_int) (int) |
A harness that receives the provider, calls it to get the real callback, and then calls that. | |
typedef int_func_int(* | callback_provider) (void) |
Functions | |
void | pointer_modify_handler (int *p) |
Handler that dereferences a pointer and writes a new value. | |
void | execute_pointer_modify_callback (void(*func_ptr)(int *), int *p) |
Harness that calls the provided function pointer, passing it an address. | |
void | inner_callback_handler (int val) |
The inner callback that will be passed as an argument. | |
void | execute_callback_as_arg_harness (void(*cb)(int)) |
The harness function that accepts a function pointer as its argument. | |
int | final_multiply_handler (int val) |
The innermost handler that will be returned and ultimately called. | |
void | closure_provider_handler (infix_context_t *context, void *ret, void **args) |
A generic handler for the "provider" closure. | |
int | call_returned_callback_harness (callback_provider provider, int val) |
subtest ("Callback modifies data via pointer") | |
subtest ("Callback passed as an argument") | |
subtest ("Closure returns a function pointer (via user_data)") | |
Variables | |
TEST | |
Tests advanced reverse trampoline (callback) patterns.
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 complex, higher-order function patterns involving callbacks. It consolidates several previous tests to create a focused suite for advanced use cases.
The scenarios tested are:
user_data
field of the reverse trampoline context, demonstrating a powerful feature for creating stateful, dynamic callback providers. #define DBLTAP_IMPLEMENTATION |
typedef int_func_int(* callback_provider) (void) |
typedef int(* int_func_int) (int) |
A harness that receives the provider, calls it to get the real callback, and then calls that.
int call_returned_callback_harness | ( | callback_provider | provider, |
int | val | ||
) |
void closure_provider_handler | ( | infix_context_t * | context, |
void * | ret, | ||
void ** | args | ||
) |
A generic handler for the "provider" closure.
This handler leverages user_data
to return another function pointer. It retrieves the function pointer from its context and writes it to the return buffer.
void execute_callback_as_arg_harness | ( | void(*)(int) | cb | ) |
The harness function that accepts a function pointer as its argument.
void execute_pointer_modify_callback | ( | void(*)(int *) | func_ptr, |
int * | p | ||
) |
Harness that calls the provided function pointer, passing it an address.
int final_multiply_handler | ( | int | val | ) |
The innermost handler that will be returned and ultimately called.
void inner_callback_handler | ( | int | val | ) |
The inner callback that will be passed as an argument.
void pointer_modify_handler | ( | int * | p | ) |
Handler that dereferences a pointer and writes a new value.
subtest | ( | "Callback modifies data via pointer" | ) |
subtest | ( | "Callback passed as an argument" | ) |
subtest | ( | "Closure returns a function pointer (via user_data)" | ) |