Skip to content

Commit 335469c

Browse files
committed
Use standard In_channel.with_open_* and Out_channel.with_open_* for Marshal (issue #1477)
This should also be more efficient because BatMarshal.output and BatMarshal.input convert everything via string.
1 parent 4112086 commit 335469c

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src/analyses/basePriv.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,12 +2031,11 @@ struct
20312031
v
20322032

20332033
let dump () =
2034-
let f = open_out_bin (get_string "exp.priv-prec-dump") in (* TODO: Out_channel.with_open_bin *)
2034+
Out_channel.with_open_bin (get_string "exp.priv-prec-dump") @@ fun f ->
20352035
(* LVH.iter (fun (l, x) v ->
20362036
Logs.debug "%a %a = %a" CilType.Location.pretty l CilType.Varinfo.pretty x VD.pretty v
20372037
) lvh; *)
2038-
Marshal.output f ({name = get_string "ana.base.privatization"; results = lvh}: result);
2039-
close_out_noerr f
2038+
Stdlib.Marshal.to_channel f ({name = get_string "ana.base.privatization"; results = lvh}: result) []
20402039

20412040
let finalize () =
20422041
if !is_dumping then

src/incremental/serialize.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
(** Serialization/deserialization of incremental analysis data. *)
22

3-
open Batteries
4-
53
(* TODO: GoblintDir *)
64
let incremental_data_file_name = "analysis.data"
75
let results_dir = "results"
@@ -22,13 +20,12 @@ let gob_results_dir op =
2220
let server () = GobConfig.get_bool "server.enabled"
2321

2422
let marshal obj fileName =
25-
let chan = open_out_bin (Fpath.to_string fileName) in (* TODO: Out_channel.with_open_bin *)
26-
Marshal.output chan obj;
27-
close_out chan
23+
Out_channel.with_open_bin (Fpath.to_string fileName) @@ fun chan ->
24+
Marshal.to_channel chan obj []
2825

2926
let unmarshal fileName =
3027
Logs.debug "Unmarshalling %s... If type of content changed, this will result in a segmentation fault!" (Fpath.to_string fileName);
31-
Marshal.input (open_in_bin (Fpath.to_string fileName)) (* TODO: In_channel.with_open_bin *)
28+
In_channel.with_open_bin (Fpath.to_string fileName) Marshal.from_channel
3229

3330
let results_exist () =
3431
(* If Goblint did not crash irregularly, the existence of the result directory indicates that there are results *)

src/util/precCompare.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ struct
9595
open Util
9696

9797
let load filename =
98-
let f = open_in_bin filename in (* TODO: In_channel.with_open_bin *)
99-
let dump: dump = Marshal.from_channel f in
98+
let dump: dump = In_channel.with_open_bin filename Stdlib.Marshal.from_channel in
10099
let dump: result = {name = dump.name; results = unmarshal dump.marshalled } in
101-
close_in_noerr f;
102100
dump
103101

104102
module CompareDump = MakeHashtbl (Key) (Dom) (RH)

0 commit comments

Comments
 (0)