sks-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sks-devel] trouble building most recent version of sks-keyserver fr


From: Daniel Kahn Gillmor
Subject: Re: [Sks-devel] trouble building most recent version of sks-keyserver from hg
Date: Fri, 06 May 2016 19:16:27 -0400
User-agent: Notmuch/0.22+16~g87b7bd4 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu)

Hi Brian--

I ran into the same deprecation issues you were running into (also ocaml
4.02.3), and i believe i've fixed them all with the attached patch.

I'm not a serious ocaml dev, though; so hopefully one of the more
experienced folks here can review this and let me know if i've done
anything horrible. (and if it's OK, feel free to apply it upstream!)

         --dkg

From: Daniel Kahn Gillmor <address@hidden>
Date: Fri, 6 May 2016 18:52:17 -0400
Subject: Avoid deprecated ocaml

newer versions of ocaml explicitly deprecate:

 * String.create in favor of Bytes.create
 * String.fill in favor of Bytes.fill
 * Sort.list in favor of List.sort
 * Byte internal assignment like .[] <- (but Bytes.set is fine)

(for this last one, see http://caml.inria.fr/mantis/view.php?id=6706
and https://github.com/ocaml/ocaml/pull/69, which i don't fully
understand)
---
 add_mail.ml   |  2 +-
 bitstring.ml  | 34 +++++++++++++++++-----------------
 channel.ml    |  6 +++---
 dbserver.ml   |  2 +-
 heap.ml       |  2 +-
 keyHash.ml    |  4 ++--
 linearAlg.ml  |  2 +-
 mList.ml      |  4 ++--
 number.ml     | 12 ++++++------
 prefixTree.ml |  4 ++--
 rMisc.ml      | 14 +++++++-------
 utils.ml      | 24 ++++++++++++------------
 wserver.ml    | 22 +++++++++++-----------
 13 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/add_mail.ml b/add_mail.ml
index 3233af6..f5c7cfc 100644
--- a/add_mail.ml
+++ b/add_mail.ml
@@ -54,7 +54,7 @@ let dirname =
 (** dumps contents of one file into another *)
 let pipe_file =
   let blocksize = 100 * 1024 in
-  let buf = String.create blocksize in
+  let buf = Bytes.create blocksize in
   let rec pipe_file file1 file2 =
     let bytes_read = input file1 buf 0 blocksize in
     if bytes_read <> 0 then (
diff --git a/bitstring.ml b/bitstring.ml
index a6d3dad..19d3307 100644
--- a/bitstring.ml
+++ b/bitstring.ml
@@ -40,7 +40,7 @@ let bytelength bits =
 let create bits =
   let bytes = bytelength bits
   in
-  { a = String.create bytes;
+  { a = Bytes.create bytes;
     bitlength = bits;
   }
 
@@ -58,7 +58,7 @@ let flip ba bit =
   let intval = int_of_char (String.get ba.a byte_pos) in
   let new_char = char_of_int ((1 lsl (width - bit_pos - 1)) lxor intval)
   in
-  String.set ba.a byte_pos new_char
+  Bytes.set ba.a byte_pos new_char
 
 let set ba bit =
   let byte_pos = bit / width
@@ -66,7 +66,7 @@ let set ba bit =
   let intval = int_of_char (String.get ba.a byte_pos) in
   let new_char = char_of_int ((1 lsl (width - bit_pos - 1)) lor intval)
   in
-  String.set ba.a byte_pos new_char
+  Bytes.set ba.a byte_pos new_char
 
 let unset ba bit =
   let byte_pos = bit / width
@@ -75,7 +75,7 @@ let unset ba bit =
   let new_char = char_of_int ((lnot (1 lsl (width - bit_pos - 1)))
                               land intval)
   in
-  String.set ba.a byte_pos new_char
+  Bytes.set ba.a byte_pos new_char
 
 let setval ba bit bool =
   if bool then set ba bit else unset ba bit
@@ -98,9 +98,9 @@ let to_bool_array ba =
   Array.init ~f:(fun i -> lget ba i) ba.bitlength
 
 let to_string ba =
-  let string = String.create ba.bitlength in
+  let string = Bytes.create ba.bitlength in
   for i = 0 to ba.bitlength -1 do
-    if get ba i = 0 then string.[i] <- '0' else string.[i] <- '1'
+    if get ba i = 0 then Bytes.set string i '0' else Bytes.set string i '1'
   done;
   string
 
@@ -160,7 +160,7 @@ let copy ba = { ba with a = String.copy ba.a }
  *)
 let copy_len ba bitlength =
   let bytes = bytelength bitlength in
-  let str = String.create bytes in
+  let str = Bytes.create bytes in
   String.blit ~src:ba.a ~src_pos:0
     ~dst:str ~dst_pos:0 ~len:(String.length ba.a);
   { a = str; bitlength = bitlength }
@@ -191,17 +191,17 @@ let shift_left_small ba bits =
   if bits > 0 then
     let bytes = bytelength ba.bitlength in
     for i = 0 to bytes-2 do
-      ba.a.[i] <- shift_pair_left ba.a.[i] ba.a.[i+1] bits
+      Bytes.set ba.a i (shift_pair_left ba.a.[i] ba.a.[i+1] bits)
     done;
-    ba.a.[bytes-1] <- shift_pair_left ba.a.[bytes-1] '\000' bits
+    Bytes.set ba.a (bytes-1) (shift_pair_left ba.a.[bytes-1] '\000' bits)
 
 let shift_right_small ba bits =
   if bits > 0 then
     let bytes = bytelength ba.bitlength in
     for i = bytes-1 downto 1 do
-      ba.a.[i] <- shift_pair_right ba.a.[i-1] ba.a.[i] bits
+      Bytes.set ba.a i (shift_pair_right ba.a.[i-1] ba.a.[i] bits)
     done;
-    ba.a.[0] <-  shift_pair_right '\000' ba.a.[0] bits
+    Bytes.set ba.a 0 (shift_pair_right '\000' ba.a.[0] bits)
 
 (**********************************)
 
@@ -216,10 +216,10 @@ let rec shift_left ba bits =
   then
     begin
       for i = 0 to bytelength - 1 - bytes do
-        ba.a.[i] <- ba.a.[i+bytes];
+        Bytes.set ba.a i ba.a.[i+bytes];
       done;
       for i = bytelength - bytes to bytelength - 1 do
-        ba.a.[i] <- '\000'
+        Bytes.set ba.a i '\000'
       done
     end;
   shift_left_small ba bits
@@ -235,10 +235,10 @@ and shift_right ba bits =
     then
       begin
         for i = bytelength - 1 downto bytes do
-          ba.a.[i] <- ba.a.[i-bytes];
+          Bytes.set ba.a i ba.a.[i-bytes];
         done;
         for i = bytes - 1 downto 0 do
-          ba.a.[i] <- '\000'
+          Bytes.set ba.a i '\000'
         done
       end;
     shift_right_small ba bits
@@ -275,14 +275,14 @@ let blit ~src ~dst ~len =
     let newdst = (rmasks.(bitlen) land srcval) lor
                  ((lnot rmasks.(bitlen)) land dstval)
     in
-    dst.a.[bytelen] <- char_of_int newdst
+    Bytes.set dst.a bytelen (char_of_int newdst)
 
 
 (* let full_blit ~src ~src_pos ~dst ~dst_pos ~len =  *)
 
 
 let zero_out bs =
-  String.fill bs.a ~pos:0 ~len:(String.length bs.a) '\000'
+  Bytes.fill bs.a ~pos:0 ~len:(String.length bs.a) '\000'
 
 (*
 let extract bs ~pos ~len =
diff --git a/channel.ml b/channel.ml
index 95b599b..75f7a3a 100644
--- a/channel.ml
+++ b/channel.ml
@@ -50,7 +50,7 @@ let create_nb_really_input inchan =
     let string =
       match !stringopt with
           None ->
-            let string = String.create len in
+            let string = Bytes.create len in
             stringopt := Some string;
             pos := 0;
             string
@@ -125,7 +125,7 @@ let read_all cin ?len ()=
       None -> 1024 * 100
     | Some x -> x
   in
-  let sbuf = String.create len
+  let sbuf = Bytes.create len
   and buf = Buffer.create len in
     read_all_rec cin sbuf buf;
     Buffer.contents buf
@@ -167,7 +167,7 @@ object (self)
   method virtual read_string_pos : buf:string -> pos:int -> len:int -> unit
   method virtual read_char : char
   method read_string len =
-    let buf = String.create len in
+    let buf = Bytes.create len in
     self#read_string_pos ~buf ~pos:0 ~len;
     buf
   method read_byte = int_of_char self#read_char
diff --git a/dbserver.ml b/dbserver.ml
index d2cab69..71c53cb 100644
--- a/dbserver.ml
+++ b/dbserver.ml
@@ -396,7 +396,7 @@ struct
     let f = (if binary then open_in_bin else open_in) fname in
     protect ~f:(fun () ->
                   let length = in_channel_length f in
-                  let buf = String.create length in
+                  let buf = Bytes.create length in
                   really_input f buf 0 length;
                   buf
                )
diff --git a/heap.ml b/heap.ml
index 292f432..ad9f053 100644
--- a/heap.ml
+++ b/heap.ml
@@ -146,7 +146,7 @@ let push heap ~key ~data =
 (***************************************************************)
 
 let empty cmp i =
-  { a = Array.create i None;
+  { a = Array.make i None;
     length = 0;
     minsize = i;
     cmp = cmp;
diff --git a/keyHash.ml b/keyHash.ml
index ca7c6d6..49cf466 100644
--- a/keyHash.ml
+++ b/keyHash.ml
@@ -73,11 +73,11 @@ let hexchar_to_int c =
 
 let dehexify s =
   let s = String.uppercase s in
-  let ns = String.create (String.length s / 2) in (* new string *)
+  let ns = Bytes.create (String.length s / 2) in (* new string *)
   for i = 0 to String.length ns - 1 do
     let first = hexchar_to_int s.[2 * i]
     and second = hexchar_to_int s.[2 * i + 1]
     in
-    ns.[i] <- char_of_int ((first lsl 4) + second)
+    Bytes.set ns i (char_of_int ((first lsl 4) + second))
   done;
   ns
diff --git a/linearAlg.ml b/linearAlg.ml
index 81a9d88..f4499ed 100644
--- a/linearAlg.ml
+++ b/linearAlg.ml
@@ -62,7 +62,7 @@ struct
   let copy m = { m with array = Array.copy m.array; }
 
   let make ~columns ~rows init =
-    let array = Array.create (columns * rows) init in
+    let array = Array.make (columns * rows) init in
     { columns = columns;
       rows = rows;
       array = array;
diff --git a/mList.ml b/mList.ml
index f473a64..c0d4c79 100644
--- a/mList.ml
+++ b/mList.ml
@@ -200,7 +200,7 @@ let pri_split pri list =
   (low,exact,high)
 
 let has_dups list =
-  let slist = Sort.list (fun x y -> x < y) list in
+  let slist = List.sort compare list in
   let rec dup_scan list = match list with
     [] -> false
   | hd::[] -> false
@@ -208,7 +208,7 @@ let has_dups list =
   in dup_scan slist
 
 let dedup list =
-  let slist = Sort.list (fun x y -> x < y) list in
+  let slist = List.sort compare list in
   let rec dedup ~list ~partial = match list with
       [] -> partial
     | hd::[] -> dedup ~list:[] ~partial:(hd::partial)
diff --git a/number.ml b/number.ml
index 3e33077..94f3b2e 100644
--- a/number.ml
+++ b/number.ml
@@ -60,9 +60,9 @@ let width_pow = power_int_positive_int 2 width
 
 let revstring s =
   let len = String.length s in
-  let copy = String.create len in
+  let copy = Bytes.create len in
   for i = 0 to len - 1 do
-    copy.[i] <- s.[len - 1 - i]
+    Bytes.set copy i s.[len - 1 - i]
   done;
   copy
 
@@ -71,19 +71,19 @@ let revstring_inplace s =
   for i = 0 to (len - 2)/2 do
     let j = len - 1 - i in
     let tmp = s.[i] in
-    s.[i] <- s.[j];
-    s.[j] <- tmp
+    Bytes.set s i s.[j];
+    Bytes.set s j tmp
   done
 
 let to_bytes ~nbytes n =
   if sign_big_int n = -1
   then raise (Invalid_argument "N.to_bytes: negative argument");
-  let string = String.create nbytes in
+  let string = Bytes.create nbytes in
   let rec loop n i =
     if i < 0 then string
     else
       let (a,b) = quomod_big_int n width_pow in
-      string.[i] <- char_of_int (int_of_big_int b);
+      Bytes.set string i (char_of_int (int_of_big_int b));
       loop a (i - 1)
   in
   let str = loop n (nbytes - 1) in
diff --git a/prefixTree.ml b/prefixTree.ml
index 4aa4fbb..a90cc41 100644
--- a/prefixTree.ml
+++ b/prefixTree.ml
@@ -730,8 +730,8 @@ let split_at_depth t zz zzs node depth =
 let pad string bytes =
   let len = String.length string in
   if bytes > len then
-    let nstr = String.create bytes in
-    String.fill nstr ~pos:len ~len:(bytes - len) '\000';
+    let nstr = Bytes.create bytes in
+    Bytes.fill nstr ~pos:len ~len:(bytes - len) '\000';
     String.blit ~src:string ~dst:nstr ~src_pos:0 ~dst_pos:0 ~len;
     nstr
   else
diff --git a/rMisc.ml b/rMisc.ml
index 63792c1..46e687d 100644
--- a/rMisc.ml
+++ b/rMisc.ml
@@ -56,15 +56,15 @@ let rec fill_random_string rfunc string ~pos ~len =
     (* CR yminsky: I think this has the same bug as the function with the same 
name in Utils *)
     let _bits = rfunc () in
       for i = 0 to steps - 1 do
-        string.[pos + i] <-
-        char_of_int (0xFF land ((rfunc ()) lsr (8 * i)))
+        Bytes.set string (pos + i)
+        (char_of_int (0xFF land ((rfunc ()) lsr (8 * i))))
       done;
       fill_random_string rfunc string ~pos:(pos + steps) ~len
   else
     ()
 
 let random_string rfunc len =
-  let string = String.create len in
+  let string = Bytes.create len in
     fill_random_string rfunc string ~pos:0 ~len;
     string
 
@@ -124,8 +124,8 @@ let add_sarray ~data sarray =
 let pad string bytes =
   let len = String.length string in
   if bytes > len then
-    let nstr = String.create bytes in
-    String.fill nstr ~pos:len ~len:(bytes - len) '\000';
+    let nstr = Bytes.create bytes in
+    Bytes.fill nstr ~pos:len ~len:(bytes - len) '\000';
     String.blit ~src:string ~dst:nstr ~src_pos:0 ~dst_pos:0 ~len;
     nstr
   else
@@ -139,7 +139,7 @@ let padset stringset bytes =
 let truncate string bytes =
   let len = String.length string in
   if bytes < len then
-    let nstr = String.create bytes in
+    let nstr = Bytes.create bytes in
     String.blit ~src:string ~dst:nstr ~src_pos:0 ~dst_pos:0 ~len:bytes;
     nstr
   else
@@ -160,7 +160,7 @@ let order_string = "530512889551602322505127520352579437339"
 (** Printing Functions *)
 
 let print_ZZp_list list =
-  let list = Sort.list (fun x y -> compare x y < 0) list in
+  let list = List.sort compare list in
   MList.print2 ~f:ZZp.print list
 
 let print_ZZp_set set = print_ZZp_list (Set.elements set)
diff --git a/utils.ml b/utils.ml
index b9b4347..0acd119 100644
--- a/utils.ml
+++ b/utils.ml
@@ -173,12 +173,12 @@ let random_int low high =
 let char_width = 8
 
 let hexstring digest =
-  let result = String.create (String.length digest * 2) in
-  let hex = "0123456789ABCDEF" in
+  let result = Bytes.create (String.length digest * 2) in
+  let hex = Bytes.of_string "0123456789ABCDEF" in
     for i = 0 to String.length digest - 1 do
       let c = Char.code digest.[i] in
-        result.[2*i] <- hex.[c lsr 4];
-        result.[2*i+1] <- hex.[c land 0xF]
+        Bytes.set result (2*i) hex.[c lsr 4];
+        Bytes.set result (2*i+1) hex.[c land 0xF]
     done;
     result
 
@@ -192,11 +192,11 @@ let int_from_bstring string ~pos ~len =
   int_from_bstring_rec string ~pos ~len 0
 
 let bstring_of_int i =
-     let s = String.create 4 in
-     s.[3] <- char_of_int (i land 0xFF);
-     s.[2] <- char_of_int ((i lsr 8) land 0xFF);
-     s.[1] <- char_of_int ((i lsr 16) land 0xFF);
-     s.[0] <- char_of_int ((i lsr 24) land 0xFF);
+     let s = Bytes.create 4 in
+     Bytes.set s 3 (char_of_int (i land 0xFF));
+     Bytes.set s 2 (char_of_int ((i lsr 8) land 0xFF));
+     Bytes.set s 1 (char_of_int ((i lsr 16) land 0xFF));
+     Bytes.set s 0 (char_of_int ((i lsr 24) land 0xFF));
      s
 
 (* tail recursive *)
@@ -265,15 +265,15 @@ let rec fill_random_string rfunc string ~pos ~len =
        the random generation being deterministic *)
     let _bits = rfunc () in
     for i = 0 to steps - 1 do
-      string.[pos + i] <-
-        char_of_int (0xFF land ((rfunc ()) lsr (8 * i)))
+      Bytes.set string (pos + i)
+        (char_of_int (0xFF land ((rfunc ()) lsr (8 * i))))
     done;
     fill_random_string rfunc string ~pos:(pos + steps) ~len
   else
     ()
 
 let random_string rfunc len =
-  let string = String.create len in
+  let string = Bytes.create len in
     fill_random_string rfunc string ~pos:0 ~len;
     string
 
diff --git a/wserver.ml b/wserver.ml
index 6ccfc62..27adb13 100644
--- a/wserver.ml
+++ b/wserver.ml
@@ -75,9 +75,9 @@ let decode s =
         match s.[i] with
           '%' when i + 2 < String.length s ->
             let v = hexa_val s.[i + 1] * 16 + hexa_val s.[i + 2] in
-            s1.[i1] <- Char.chr v; i + 3
-        | '+' -> s1.[i1] <- ' '; succ i
-        | x -> s1.[i1] <- x; succ i
+            Bytes.set s1 i1 (Char.chr v); i + 3
+        | '+' -> Bytes.set s1 i1 ' '; succ i
+        | x -> Bytes.set s1 i1 x; succ i
       in
       copy_decode_in s1 i (succ i1)
     else s1
@@ -95,7 +95,7 @@ let decode s =
   in
   if need_decode 0 then
     let len = compute_len 0 0 in
-    let s1 = String.create len in
+    let s1 = Bytes.create len in
     strip_heading_and_trailing_spaces (copy_decode_in s1 0 0)
   else s
 
@@ -120,22 +120,22 @@ let encode s =
     if i < String.length s then
       let i1 =
         match s.[i] with
-          ' ' -> s1.[i1] <- '+'; succ i1
+          ' ' -> Bytes.set s1 i1 '+'; succ i1
         | c ->
             if special c then
               begin
-                s1.[i1] <- '%';
-                s1.[i1 + 1] <- hexa_digit (Char.code c / 16);
-                s1.[i1 + 2] <- hexa_digit (Char.code c mod 16);
+                Bytes.set s1 i1 '%';
+                Bytes.set s1 (i1 + 1) (hexa_digit (Char.code c / 16));
+                Bytes.set s1 (i1 + 2) (hexa_digit (Char.code c mod 16));
                 i1 + 3
               end
-            else begin s1.[i1] <- c; succ i1 end
+            else begin Bytes.set s1 i1 c; succ i1 end
       in
       copy_code_in s1 (succ i) i1
     else s1
   in
   if need_code 0 then
-    let len = compute_len 0 0 in copy_code_in (String.create len) 0 0
+    let len = compute_len 0 0 in copy_code_in (Bytes.create len) 0 0
   else s
 
 let stripchars = Set.of_list [ ' '; '\t'; '\n'; '\r' ]
@@ -180,7 +180,7 @@ let parse_post headers cin =
     if len > max_post_length
     then raise (Entity_too_large (sprintf "POST data too long: %f megs"
                               (float len /. 1024. /. 1024.)));
-    let rest = String.create len in
+    let rest = Bytes.create len in
     really_input cin rest 0 len;
     rest
   with

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]