Unit test for advanced reverse trampoline (callback) scenarios.
This test file explores more complex and dynamic uses of reverse trampolines, verifying that the library's features compose correctly.
The test covers:
- Modifying Data via Pointers: A callback is created for a function that takes a pointer (
void(int*)). The test verifies that when the C harness calls the JIT-compiled pointer, the handler is able to correctly dereference the pointer and modify the original data in the harness.
- Callbacks as Arguments: This is a "callback inception" test. It creates an "inner" callback and passes its JIT-compiled function pointer as an argument (via a forward trampoline) to a C "harness" function. The harness then calls the function pointer it received. This complex chain tests the interoperability of forward and reverse trampolines.
- Closures Returning Function Pointers: A "provider" closure is created. Its
user_data is set to the function pointer of another, "worker" callback. When the provider is called, its handler retrieves the worker's function pointer from user_data and returns it. The C harness then calls this returned pointer, verifying that function pointers can be passed as data through closures.