|
Lutok 0.7.1
|
These tests check that Lua errors do not bypass C++ destructors in callbacks. More...
#include <atf-c++.hpp>#include "lutok/exceptions.hpp"#include "lutok/state.hpp"Classes | |
| struct | anonymous_namespace{state_unwinding_test.cpp}::destruction_guard |
Variables | |
| int | anonymous_namespace{state_unwinding_test.cpp}::destroyed |
| const char * | anonymous_namespace{state_unwinding_test.cpp}::reject_global_write |
These tests check that Lua errors do not bypass C++ destructors in callbacks.
With Lua using longjmp for error propagation, an unprotected Lua API call can jump to an outer lua_pcall without unwinding the intervening C++ frames. Bypassing non-trivial destructors of automatic objects this way is undefined behavior under [csetjmp.syn]/2 of the C++ standard.
Each test invokes a C++ callback from Lua. The callback creates a guard whose destructor increments a counter, then performs an operation that raises a Lua error. We check both that the outer call reports the expected error and that the guard was destroyed exactly once. Protected operations should pass, operations that let longjmp bypass the guard fail the check or may crash.
Please note that this suite doesn't test memory allocation failures.