I know that, ensure Drop
trait being called before the program exit is not feasible (for example, when an atom bomb force the program to stop running), but is there something that allow calling Drop
before the program exits?
When panic = unwind
is set, I tried registering a function for libc::atexit
that executing panic!("executing unwind")
, which unwind the whole stack, drop every resources it could touch. But an annoying panic message occurs.
I checked the implementation, it seems that I could call panic_impl
directly, but that op requires a nightly feature, panic_internal
, which cannot be used in stable rust.
Is there some better way to unwind the stack?
What's more, when I tried to handle more conditions with libc::atexit
, I cannot register that function since libc does not accept functions with signature extern "C-unwind" fn() {unwind}
.
So, what is the best way to drop important variables before exiting rust program? Should I just examine all the possible exit path and marks them manually?