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
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