Unit test to explicitly compare the "Callback" vs. "Closure" reverse trampoline APIs.
More...
Unit test to explicitly compare the "Callback" vs. "Closure" reverse trampoline APIs.
This test serves as a clear, side-by-side demonstration of the two main models for creating reverse trampolines in infix. Both models are functionally equivalent from the perspective of the C code that calls the generated function pointer, but they offer different interfaces to the developer using the infix library.
- **
infix_reverse_create_callback**:
- Handler: A native, type-safe C function (e.g.,
int handler(int, int)).
- Pros: Easy to use from C/C++, compile-time type checking, potentially higher performance.
- Cons: Less flexible, stateless by default.
- **
infix_reverse_create_closure**:
- Handler: A generic function (
infix_closure_handler_fn) that receives arguments as a void** array.
- Pros: Highly flexible, ideal for language bindings, supports stateful callbacks via
user_data.
- Cons: Requires manual argument unpacking, lacks compile-time type safety.
This test creates a JIT-compiled function pointer using both APIs for the same signature ((int, int) -> int) and verifies that both can be called from a C harness function and produce the correct result.