Don't use raise_with_backtrace in backward-compatible Fun.protect

This commit is contained in:
Christopher Zimmermann 2019-10-07 14:07:11 +02:00
parent f759a92214
commit 6a51830305
2 changed files with 4 additions and 6 deletions

View file

@ -58,8 +58,8 @@ let shims_fun_mli_pre_408 =
(** This is the [Fun] module distributed with the OCaml Core system.
It is linked with containers in case the installed OCaml system does not
provide a compatible [Fun] module.
It is the an unmodified version of [Fun] as shipped with the OCaml core
system.
It is the a slightly modified version of [Fun] as shipped with the OCaml
core system.
*)
"
^ read_file "stdlib/fun.mli"

View file

@ -23,12 +23,10 @@ exception Finally_raised of exn
let protect ~(finally : unit -> unit) work =
let finally_no_exn () =
try finally () with e ->
let bt = Printexc.get_raw_backtrace () in
Printexc.raise_with_backtrace (Finally_raised e) bt
raise (Finally_raised e)
in
match work () with
| result -> finally_no_exn () ; result
| exception work_exn ->
let work_bt = Printexc.get_raw_backtrace () in
finally_no_exn () ;
Printexc.raise_with_backtrace work_exn work_bt
raise work_exn