summaryrefslogtreecommitdiff
path: root/toplevel
diff options
context:
space:
mode:
authorhhugo <hugo.heuzard@gmail.com>2023-03-11 21:17:02 +0900
committerGitHub <noreply@github.com>2023-03-11 13:17:02 +0100
commitd408cac30d4cbad5a125520c96a7a351d7950577 (patch)
tree94a3e4e5962a1ea0155a04e2387ff9a955c4ed70 /toplevel
parent2ec73e516bc511c4ef32fae50b1f737df36b8632 (diff)
downloadocaml-d408cac30d4cbad5a125520c96a7a351d7950577.tar.gz
Bytesections: cleanup API (#11623)
Diffstat (limited to 'toplevel')
-rw-r--r--toplevel/expunge.ml44
1 files changed, 22 insertions, 22 deletions
diff --git a/toplevel/expunge.ml b/toplevel/expunge.ml
index 2a756573c0..a8ad126dd6 100644
--- a/toplevel/expunge.ml
+++ b/toplevel/expunge.ml
@@ -45,33 +45,33 @@ let main () =
to_keep := String.Set.add (String.capitalize_ascii Sys.argv.(i)) !to_keep
done;
let ic = open_in_bin input_name in
- Bytesections.read_toc ic;
- let toc = Bytesections.toc() in
- let pos_first_section = Bytesections.pos_first_section ic in
+ let toc = Bytesections.read_toc ic in
+ seek_in ic 0;
let oc =
open_out_gen [Open_wronly; Open_creat; Open_trunc; Open_binary] 0o777
- output_name in
- (* Copy the file up to the symbol section as is *)
- seek_in ic 0;
- copy_file_chunk ic oc pos_first_section;
+ output_name in
+ let first_pos = Bytesections.pos_first_section toc in
+ (* Copy the file up to the first section as is *)
+ copy_file_chunk ic oc first_pos;
(* Copy each section, modifying the symbol section in passing *)
- Bytesections.init_record oc;
+ let toc_writer = Bytesections.init_record oc in
List.iter
- (fun (name, len) ->
- begin match name with
- "SYMB" ->
- let global_map = (input_value ic : Symtable.global_map) in
- output_value oc (expunge_map global_map)
- | "CRCS" ->
- let crcs = (input_value ic : (string * Digest.t option) list) in
- output_value oc (expunge_crcs crcs)
- | _ ->
- copy_file_chunk ic oc len
- end;
- Bytesections.record oc name)
- toc;
+ (fun {Bytesections.name; pos; len} ->
+ seek_in ic pos;
+ begin match name with
+ SYMB ->
+ let global_map : Symtable.global_map = input_value ic in
+ output_value oc (expunge_map global_map)
+ | CRCS ->
+ let crcs : (string * Digest.t option) list = input_value ic in
+ output_value oc (expunge_crcs crcs)
+ | _ ->
+ copy_file_chunk ic oc len
+ end;
+ Bytesections.record toc_writer name)
+ (Bytesections.all toc);
(* Rewrite the toc and trailer *)
- Bytesections.write_toc_and_trailer oc;
+ Bytesections.write_toc_and_trailer toc_writer;
(* Done *)
close_in ic;
close_out oc