mirror of
https://github.com/vlang/v.git
synced 2025-09-09 07:15:50 -04:00
builtin: implement an at_exit(cb)
wrapper for C.atexit (part 1) (#21254)
This commit is contained in:
parent
27cd1b106e
commit
a222d7beb2
@ -32,6 +32,23 @@ pub fn exit(code int) {
|
||||
C.exit(code)
|
||||
}
|
||||
|
||||
// at_exit registers a fn callback, that will be called at normal process termination.
|
||||
// It returns an error, if the registration was not successful.
|
||||
// The registered callback functions, will be called either via exit/1,
|
||||
// or via return from the main program, in the reverse order of their registration.
|
||||
// The same fn may be registered multiple times.
|
||||
// Each callback fn will called once for each registration.
|
||||
pub fn at_exit(cb FnExitCb) ! {
|
||||
$if freestanding {
|
||||
return error('at_exit not implemented with -freestanding')
|
||||
} $else {
|
||||
res := C.atexit(cb)
|
||||
if res != 0 {
|
||||
return error_with_code('at_exit failed', res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// panic_debug private function that V uses for panics, -cg/-g is passed
|
||||
// recent versions of tcc print nicer backtraces automatically
|
||||
// Note: the duplication here is because tcc_backtrace should be called directly
|
||||
|
Loading…
x
Reference in New Issue
Block a user