diff options
| author | Maxime Dénès | 2017-11-20 11:02:21 +0100 |
|---|---|---|
| committer | Maxime Dénès | 2017-11-20 11:02:21 +0100 |
| commit | 4db3eeaf447bb8cc3b753945eda901d13965a8a7 (patch) | |
| tree | 3aeb97151b5a8e3902f3145bfda66c0d55ae6deb /lib/flags.ml | |
| parent | c9f45bd9aa75cbcfcee7089b722eb5fac1832472 (diff) | |
| parent | a554519874c15d0a790082e5f15f3dc2419c6c38 (diff) | |
Merge PR #6184: [lib] Minor pending cleanup to consolidate helper function.
Diffstat (limited to 'lib/flags.ml')
| -rw-r--r-- | lib/flags.ml | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/lib/flags.ml b/lib/flags.ml index 323b5492dd..ddc8f84825 100644 --- a/lib/flags.ml +++ b/lib/flags.ml @@ -6,13 +6,17 @@ (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) -let with_option o f x = - let old = !o in o:=true; - try let r = f x in if !o = true then o := old; r - with reraise -> - let reraise = Backtrace.add_backtrace reraise in - let () = o := old in - Exninfo.iraise reraise +let with_modified_ref r nf f x = + let old_ref = !r in r := nf !r; + try let res = f x in r := old_ref; res + with reraise -> + let reraise = Backtrace.add_backtrace reraise in + r := old_ref; + Exninfo.iraise reraise + +let with_option o f x = with_modified_ref o (fun _ -> true) f x +let without_option o f x = with_modified_ref o (fun _ -> false) f x +let with_extra_values o l f x = with_modified_ref o (fun ol -> ol@l) f x let with_options ol f x = let vl = List.map (!) ol in @@ -25,22 +29,6 @@ let with_options ol f x = let () = List.iter2 (:=) ol vl in Exninfo.iraise reraise -let without_option o f x = - let old = !o in o:=false; - try let r = f x in if !o = false then o := old; r - with reraise -> - let reraise = Backtrace.add_backtrace reraise in - let () = o := old in - Exninfo.iraise reraise - -let with_extra_values o l f x = - let old = !o in o:=old@l; - try let r = f x in o := old; r - with reraise -> - let reraise = Backtrace.add_backtrace reraise in - let () = o := old in - Exninfo.iraise reraise - let boot = ref false let record_aux_file = ref false |
