Author: Ralf Treinen <treinen@debian.org>
Description: ocaml strings are immutable in recent ocaml versions,
  replace them by Bytes.t where necessary

Index: pplacer-1.1~alpha19/common_src/ppatteries.ml
===================================================================
--- pplacer-1.1~alpha19.orig/common_src/ppatteries.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/common_src/ppatteries.ml	2020-06-13 18:52:51.000000000 +0200
@@ -60,7 +60,7 @@
 let maybe_cons o l = maybe_map_cons identity o l
 
 let to_csv_out ch =
-  (ch :> <close_out: unit -> unit; output: string -> int -> int -> int>)
+  (ch :> <close_out: unit -> unit; output: Bytes.t -> int -> int -> int>)
 let csv_out_channel ch = new IO.out_channel ch |> to_csv_out
 
 let to_csv_in ch = object
@@ -243,8 +243,8 @@
         ~write:(Gzip.output_char out_chan)
         ~output:(fun s p l ->
           let buf = Buffer.create l in
-          Buffer.add_substring buf s p l;
-          Gzip.output out_chan (Buffer.contents buf) 0 (Buffer.length buf);
+          Buffer.add_subbytes buf s p l;
+          Gzip.output out_chan (Bytes.of_string (Buffer.contents buf)) 0 (Buffer.length buf);
           Buffer.length buf)
         ~close:(fun () -> Gzip.close_out out_chan)
         (* Gzip.flush disposes of the Gzip stream and prevents further writes -
@@ -714,8 +714,8 @@
   let left_pad pad_width c s =
     assert(pad_width >= 0);
     let len = String.length s in
-    let new_s = String.make (len+pad_width) c in
-    String.blit s 0 new_s pad_width len;
+    let new_s = Bytes.make (len+pad_width) c in
+    Bytes.blit_string s 0 new_s pad_width len;
     new_s
 
 end
Index: pplacer-1.1~alpha19/json_src/json.ml
===================================================================
--- pplacer-1.1~alpha19.orig/json_src/json.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/json_src/json.ml	2020-06-13 18:52:51.000000000 +0200
@@ -72,7 +72,7 @@
 let to_file name o =
   let file = MaybeZipped.open_out name in
   let formatter= Format.make_formatter
-    (fun s p l -> let _ = IO.output file s p l in ())
+    (fun s p l -> let _ = IO.output file (Bytes.of_string s) p l in ())
     (fun () -> IO.flush file)
   in
   to_formatter formatter o;
Index: pplacer-1.1~alpha19/common_src/alignment.ml
===================================================================
--- pplacer-1.1~alpha19.orig/common_src/alignment.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/common_src/alignment.ml	2020-06-13 18:52:51.000000000 +0200
@@ -102,7 +102,7 @@
   Printf.fprintf ch "%d %d\n" (n_seqs align) (length align);
   Array.iter (
     fun (name, seq) ->
-      Printf.fprintf ch "%s %s\n" (StringFuns.left_pad 14 ' ' name) seq;
+      Printf.fprintf ch "%s %s\n" (Bytes.to_string (StringFuns.left_pad 14 ' ' name)) seq;
   ) align;
   close_out ch
 
Index: pplacer-1.1~alpha19/pplacer_src/string_matrix.ml
===================================================================
--- pplacer-1.1~alpha19.orig/pplacer_src/string_matrix.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/pplacer_src/string_matrix.ml	2020-06-13 18:52:51.000000000 +0200
@@ -50,7 +50,7 @@
 let m = add_names [|"a";"b"|] [|[|"0";"1"|];[|"2";"3"|]|]
 
 let row_to_str delim row =
-  String.concat delim (Array.to_list row)
+  Bytes.to_string (Bytes.concat (Bytes.of_string delim) (Array.to_list row))
 
 let write_row ch row =
   Printf.fprintf ch "%s\n" (row_to_str "  " row)
Index: pplacer-1.1~alpha19/pplacer_src/pplacer_run.ml
===================================================================
--- pplacer-1.1~alpha19.orig/pplacer_src/pplacer_run.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/pplacer_src/pplacer_run.ml	2020-06-13 18:52:51.000000000 +0200
@@ -118,7 +118,7 @@
           (seq'.[!pos] <- seq.[e];
            incr pos))
       mask;
-    name, seq'
+    name, (Bytes.to_string seq')
   in
   dprintf "sequence length cut from %d to %d.\n" n_sites masklen;
   let effective_length = match seq_type with
@@ -372,7 +372,7 @@
     |> Array.append
         [|[|"node"; "tree_likelihood"; "slow_tree_like"; "supernode_like"|]|]
     |> String_matrix.pad
-    |> Array.iter (Array.iter (dprintf "%s  ") %> tap (fun () -> dprint "\n"))
+    |> Array.iter (Array.iter (function b -> (dprintf "%s  ") (Bytes.to_string b)) %> tap (fun () -> dprint "\n"))
 
   end;
 
Index: pplacer-1.1~alpha19/json_src/jsonparse.mly
===================================================================
--- pplacer-1.1~alpha19.orig/json_src/jsonparse.mly	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/json_src/jsonparse.mly	2020-06-13 18:52:51.000000000 +0200
@@ -42,7 +42,7 @@
         | "t" -> "\t"
         | _ ->
           let escape = Str.replace_matched "\\2" s in
-          utf8_encode (int_of_string ("0x" ^ escape))
+          (Bytes.to_string (utf8_encode (int_of_string ("0x" ^ escape))))
     ) s
 
   let add_to_hash h (s, v) = Hashtbl.add h s v; h
Index: pplacer-1.1~alpha19/pplacer_src/multiprocessing.ml
===================================================================
--- pplacer-1.1~alpha19.orig/pplacer_src/multiprocessing.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/pplacer_src/multiprocessing.ml	2020-06-13 18:52:51.000000000 +0200
@@ -71,11 +71,11 @@
   in aux pipe_map
 
 type buffer = {
-  buf: string;
+  buf: Bytes.t;
   mutable pos: int;
   length: int;
 }
-let buffer n = {buf = String.create n; pos = 0; length = n}
+let buffer n = {buf = Bytes.create n; pos = 0; length = n}
 type buffer_state =
   | Needs_more
   | Done of string
@@ -87,7 +87,7 @@
     | n ->
       let n_read = b.pos + n in
       if n_read = b.length then
-        Done b.buf
+        Done (Bytes.to_string b.buf)
       else begin
         b.pos <- n_read;
         Needs_more
@@ -184,7 +184,7 @@
     in match fill_buffer b h.ch, marshal_state with
       | Needs_more, _ -> ()
       | Done header, Needs_header _ ->
-        marshal_state <- Needs_data (header, buffer (Marshal.data_size header 0))
+        marshal_state <- Needs_data (header, buffer (Marshal.data_size (Bytes.of_string header) 0))
       | Done body, Needs_data (header, _) ->
         let obj = Marshal.from_string (header ^ body) 0 in
         self#obj_received obj;
Index: pplacer-1.1~alpha19/pplacer_src/guppy_squash.ml
===================================================================
--- pplacer-1.1~alpha19.orig/pplacer_src/guppy_squash.ml	2020-06-13 18:52:51.000000000 +0200
+++ pplacer-1.1~alpha19/pplacer_src/guppy_squash.ml	2020-06-13 21:02:42.674037660 +0200
@@ -174,7 +174,7 @@
       Newick_gtree.to_file cluster_t (path cluster_tree_name);
       let outdir = path mass_trees_dirname in mkdir outdir;
       let pad_width = find_zero_pad_width (IntMap.cardinal blobim) in
-      let prefix_of_int i = Filename.concat outdir (zero_pad_int pad_width i) in
+      let prefix_of_int i = Filename.concat outdir (Bytes.to_string (zero_pad_int pad_width i)) in
       (* make a tax tree here then run mimic on it *)
       let wpt infix t i =
         self#write_pre_tree (prefix_of_int i) infix t
@@ -217,8 +217,8 @@
         let (_, cluster_t, _) = our_make_cluster refpkgo mode_str boot_prl in
         Newick_gtree.to_file
           cluster_t
-          (path ("cluster."^(zero_pad_int pad_width i)^".tre"));
-        dprintf "Finished bootstrap %s/%d\n" (zero_pad_int pad_width i) (List.length boots);
+          (path ("cluster."^(Bytes.to_string (zero_pad_int pad_width i))^".tre"));
+        dprintf "Finished bootstrap %s/%d\n" (Bytes.to_string (zero_pad_int pad_width i)) (List.length boots);
       in
       match children with
       | 1 -> List.iter run_boot boots
Index: pplacer-1.1~alpha19/pam_src/pam_solver.ml
===================================================================
--- pplacer-1.1~alpha19.orig/pam_src/pam_solver.ml	2020-06-13 18:52:38.000000000 +0200
+++ pplacer-1.1~alpha19/pam_src/pam_solver.ml	2020-06-13 21:05:17.174881638 +0200
@@ -20,7 +20,7 @@
   let old_leaf_idx old = Array.findi ((=) (IntMap.find old transm)) leaf_arr
   and rtrans i = IntMap.find i rtransm
   and total_mass = I.total_mass mass in
-  let keep_string = String.make (Array.length leaf_arr) '\000' in
+  let keep_string = Bytes.make (Array.length leaf_arr) '\000' in
   Option.may
     (IntSet.iter (fun leaf -> keep_string.[old_leaf_idx leaf] <- '\001'))
     keep;
@@ -39,7 +39,7 @@
   |> Matrix.of_arrays
   (* rows are masses; columns are leaves. thus, we need to transpose *)
   |> Matrix.rect_transpose
-  |> c_pam leaves keep_string
+  |> c_pam leaves (Bytes.to_string keep_string)
   in
   BA1.enum leaf_vec
   |> Enum.map (Array.get leaf_arr %> rtrans)
