aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/flags.ml
diff options
context:
space:
mode:
authorGravatar Emilio Jesus Gallego Arias <e+git@x80.org>2017-11-19 04:47:15 +0100
committerGravatar Emilio Jesus Gallego Arias <e+git@x80.org>2017-11-19 04:51:49 +0100
commita554519874c15d0a790082e5f15f3dc2419c6c38 (patch)
treefbca74c97943685e93e10b85de708cc7c54a7abe /lib/flags.ml
parentedf1a8f36f75861b822081b3825357e122b6937d (diff)
[lib] Minor pending cleanup to consolidate helper function.
While we are at it we refactor a few special cases of the helper.
Diffstat (limited to 'lib/flags.ml')
-rw-r--r--lib/flags.ml34
1 files changed, 11 insertions, 23 deletions
diff --git a/lib/flags.ml b/lib/flags.ml
index 323b5492d..ddc8f8482 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