diff options
-rw-r--r-- | stdlib/pervasives.ml | 11 | ||||
-rw-r--r-- | stdlib/pervasives.mli | 2 | ||||
-rw-r--r-- | stdlib/std_exit.ml | 4 |
3 files changed, 11 insertions, 6 deletions
diff --git a/stdlib/pervasives.ml b/stdlib/pervasives.ml index eb8aa8e0f..ad1bb2b3b 100644 --- a/stdlib/pervasives.ml +++ b/stdlib/pervasives.ml @@ -293,10 +293,13 @@ external sys_exit : int -> 'a = "sys_exit" let exit_function = ref (fun () -> flush stdout; flush stderr) -let exit retcode = - (!exit_function)(); - sys_exit retcode - let at_exit f = let g = !exit_function in exit_function := (fun () -> f(); g()) + +let do_at_exit () = (!exit_function) () + +let exit retcode = + do_at_exit (); + sys_exit retcode + diff --git a/stdlib/pervasives.mli b/stdlib/pervasives.mli index 3acb81bfb..f2e5fa1fb 100644 --- a/stdlib/pervasives.mli +++ b/stdlib/pervasives.mli @@ -539,3 +539,5 @@ val at_exit: (unit -> unit) -> unit (*** For system use only, not for the casual user *) val unsafe_really_input : in_channel -> string -> int -> int -> unit + +val do_at_exit: unit -> unit diff --git a/stdlib/std_exit.ml b/stdlib/std_exit.ml index 5debeac6d..e53eadfd6 100644 --- a/stdlib/std_exit.ml +++ b/stdlib/std_exit.ml @@ -11,6 +11,6 @@ (* $Id$ *) -(* Ensure that [exit] is called at the end of every program *) +(* Ensure that [at_exit] functions are called at the end of every program *) -let _ = exit 0 +let _ = do_at_exit() |