summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Glondu <steph@glondu.net>2019-09-04 16:41:40 +0200
committerStephane Glondu <steph@glondu.net>2019-09-04 16:41:40 +0200
commit69a7dd76a9be124b3a18cc51a4c7b2ade20bb8c2 (patch)
tree197c0186d3aa04ad59f0084a8fe45326e00aec51
parentd5b1c54731ff6b66acbc4fb2fda8bc9ac1d22ce5 (diff)
Use string instead of bytes in bitstring type
-rw-r--r--debian/patches/0004-Fix-compilation-with-OCaml-4.08.0.patch223
1 files changed, 66 insertions, 157 deletions
diff --git a/debian/patches/0004-Fix-compilation-with-OCaml-4.08.0.patch b/debian/patches/0004-Fix-compilation-with-OCaml-4.08.0.patch
index 2d1c671..2bd3977 100644
--- a/debian/patches/0004-Fix-compilation-with-OCaml-4.08.0.patch
+++ b/debian/patches/0004-Fix-compilation-with-OCaml-4.08.0.patch
@@ -3,56 +3,25 @@ Date: Mon, 2 Sep 2019 17:41:26 +0200
Subject: Fix compilation with OCaml 4.08.0
---
- bitstring.ml | 59 ++++++++++++++++++++++++------------------------
- bitstring.mli | 2 +-
+ bitstring.ml | 34 ++++++++++------------------------
+ bitstring.mli | 10 ----------
bitstring_persistent.mli | 2 +-
- 3 files changed, 32 insertions(+), 31 deletions(-)
+ 3 files changed, 11 insertions(+), 35 deletions(-)
diff --git a/bitstring.ml b/bitstring.ml
-index cfefb79..6f8b831 100644
+index cfefb79..4d8b11c 100644
--- a/bitstring.ml
+++ b/bitstring.ml
-@@ -36,15 +36,15 @@ exception Construct_failure of string * string * int * int
- * bitoffset and the bitlength within the string. Note offset/length
- * are counted in bits, not bytes.
- *)
--type bitstring = string * int * int
-+type bitstring = bytes * int * int
-
- type t = bitstring
-
- (* Functions to create and load bitstrings. *)
--let empty_bitstring = "", 0, 0
-+let empty_bitstring = Bytes.create 0, 0, 0
-
- let make_bitstring len c =
-- if len >= 0 then String.make ((len+7) lsr 3) c, 0, len
-+ if len >= 0 then Bytes.make ((len+7) lsr 3) c, 0, len
- else
- invalid_arg (
- sprintf "make_bitstring/create_bitstring: len %d < 0" len
-@@ -56,7 +56,7 @@ let zeroes_bitstring = create_bitstring
-
- let ones_bitstring len = make_bitstring len '\xff'
-
--let bitstring_of_string str = str, 0, String.length str lsl 3
-+let bitstring_of_string str = Bytes.of_string str, 0, String.length str lsl 3
-
- let bitstring_of_chan chan =
- let tmpsize = 16384 in
-@@ -64,9 +64,9 @@ let bitstring_of_chan chan =
+@@ -64,7 +64,7 @@ let bitstring_of_chan chan =
let tmp = String.create tmpsize in
let n = ref 0 in
while n := input chan tmp 0 tmpsize; !n > 0 do
- Buffer.add_substring buf tmp 0 !n;
+ Buffer.add_subbytes buf tmp 0 !n;
done;
-- Buffer.contents buf, 0, Buffer.length buf lsl 3
-+ Buffer.to_bytes buf, 0, Buffer.length buf lsl 3
+ Buffer.contents buf, 0, Buffer.length buf lsl 3
- let bitstring_of_chan_max chan max =
- let tmpsize = 16384 in
-@@ -78,14 +78,14 @@ let bitstring_of_chan_max chan max =
+@@ -78,7 +78,7 @@ let bitstring_of_chan_max chan max =
let r = min tmpsize (max - !len) in
let n = input chan tmp 0 r in
if n > 0 then (
@@ -61,27 +30,16 @@ index cfefb79..6f8b831 100644
len := !len + n;
loop ()
)
- )
- in
- loop ();
-- Buffer.contents buf, 0, !len lsl 3
-+ Buffer.to_bytes buf, 0, !len lsl 3
-
- let bitstring_of_file_descr fd =
- let tmpsize = 16384 in
-@@ -93,9 +93,9 @@ let bitstring_of_file_descr fd =
+@@ -93,7 +93,7 @@ let bitstring_of_file_descr fd =
let tmp = String.create tmpsize in
let n = ref 0 in
while n := Unix.read fd tmp 0 tmpsize; !n > 0 do
- Buffer.add_substring buf tmp 0 !n;
+ Buffer.add_subbytes buf tmp 0 !n;
done;
-- Buffer.contents buf, 0, Buffer.length buf lsl 3
-+ Buffer.to_bytes buf, 0, Buffer.length buf lsl 3
+ Buffer.contents buf, 0, Buffer.length buf lsl 3
- let bitstring_of_file_descr_max fd max =
- let tmpsize = 16384 in
-@@ -107,14 +107,14 @@ let bitstring_of_file_descr_max fd max =
+@@ -107,7 +107,7 @@ let bitstring_of_file_descr_max fd max =
let r = min tmpsize (max - !len) in
let n = Unix.read fd tmp 0 r in
if n > 0 then (
@@ -90,50 +48,7 @@ index cfefb79..6f8b831 100644
len := !len + n;
loop ()
)
- )
- in
- loop ();
-- Buffer.contents buf, 0, !len lsl 3
-+ Buffer.to_bytes buf, 0, !len lsl 3
-
- let bitstring_of_file fname =
- let chan = open_in_bin fname in
-@@ -799,7 +799,7 @@ module Buffer = struct
- Buffer.contents buf
- else
- Buffer.contents buf ^ (String.make 1 (Char.chr last)) in
-- data, 0, len
-+ Bytes.of_string data, 0, len
-
- (* Add exactly 8 bits. *)
- let add_byte ({ buf = buf; len = len; last = last } as t) byte =
-@@ -992,7 +992,7 @@ let construct_bitstring buf (data, off, len) =
- let rec loop off len blen =
- if blen = 0 then (off, len)
- else (
-- let b = extract_bit data off len 1
-+ let b = extract_bit (Bytes.to_string data) off len 1
- and off = off + 1 and len = len - 1 in
- Buffer.add_bit buf b;
- loop off len (blen-1)
-@@ -1006,9 +1006,9 @@ let construct_bitstring buf (data, off, len) =
- let off = off lsr 3 in
- (* XXX dangerous allocation *)
- if off = 0 then data
-- else String.sub data off (String.length data - off) in
-+ else Bytes.sub data off (Bytes.length data - off) in
-
-- Buffer.add_bits buf data len
-+ Buffer.add_bits buf (Bytes.to_string data) len
-
- (* Concatenate bitstrings. *)
- let concat bs =
-@@ -1021,11 +1021,11 @@ let concat bs =
- let string_of_bitstring (data, off, len) =
- if off land 7 = 0 && len land 7 = 0 then
- (* Easy case: everything is byte-aligned. *)
-- String.sub data (off lsr 3) (len lsr 3)
-+ Bytes.sub_string data (off lsr 3) (len lsr 3)
+@@ -1025,7 +1025,7 @@ let string_of_bitstring (data, off, len) =
else (
(* Bit-twiddling case. *)
let strlen = (len + 7) lsr 3 in
@@ -142,75 +57,55 @@ index cfefb79..6f8b831 100644
let rec loop data off len i =
if len >= 8 then (
let c = extract_char_unsigned data off len 8
-@@ -1037,8 +1037,8 @@ let string_of_bitstring (data, off, len) =
- str.[i] <- Char.chr (c lsl (8-len))
+@@ -1038,7 +1038,7 @@ let string_of_bitstring (data, off, len) =
)
in
-- loop data off len 0;
+ loop data off len 0;
- str
-+ loop (Bytes.to_string data) off len 0;
+ Bytes.to_string str
)
(* To channel. *)
-@@ -1078,8 +1078,8 @@ let compare ((data1, off1, len1) as bs1) ((data2, off2, len2) as bs2) =
- and len1 = len1 lsr 3 and len2 = len2 lsr 3 in
- let rec loop i =
- if i < len1 && i < len2 then (
-- let c1 = String.unsafe_get data1 (off1 + i)
-- and c2 = String.unsafe_get data2 (off2 + i) in
-+ let c1 = Bytes.unsafe_get data1 (off1 + i)
-+ and c2 = Bytes.unsafe_get data2 (off2 + i) in
- let r = compare c1 c2 in
- if r <> 0 then r
- else loop (i+1)
-@@ -1106,7 +1106,7 @@ let is_zeroes_bitstring ((data, off, len) as bits) =
- let off = off lsr 3 and len = len lsr 3 in
- let rec loop i =
- if i < len then (
-- if String.unsafe_get data (off + i) <> '\000' then false
-+ if Bytes.unsafe_get data (off + i) <> '\000' then false
- else loop (i+1)
- ) else true
- in
-@@ -1124,7 +1124,7 @@ let is_ones_bitstring ((data, off, len) as bits) =
- let off = off lsr 3 and len = len lsr 3 in
- let rec loop i =
- if i < len then (
-- if String.unsafe_get data (off + i) <> '\xff' then false
-+ if Bytes.unsafe_get data (off + i) <> '\xff' then false
- else loop (i+1)
- ) else true
- in
-@@ -1147,7 +1147,7 @@ let put (data, off, len) n v =
+@@ -1049,7 +1049,7 @@ let bitstring_to_chan ((data, off, len) as bits) chan =
+
+ if off land 7 = 0 then
+ (* Easy case: string is byte-aligned. *)
+- output chan data (off lsr 3) (len lsr 3)
++ output chan (Bytes.of_string data) (off lsr 3) (len lsr 3)
else (
- let i = off+n in
- let si = i lsr 3 and mask = 0x80 lsr (i land 7) in
+ (* Bit-twiddling case: reuse string_of_bitstring *)
+ let str = string_of_bitstring bits in
+@@ -1142,20 +1142,6 @@ let is_ones_bitstring ((data, off, len) as bits) =
+
+ let index_out_of_bounds () = invalid_arg "index out of bounds"
+
+-let put (data, off, len) n v =
+- if n < 0 || n >= len then index_out_of_bounds ()
+- else (
+- let i = off+n in
+- let si = i lsr 3 and mask = 0x80 lsr (i land 7) in
- let c = Char.code data.[si] in
-+ let c = Char.code (Bytes.get data si) in
- let c = if v <> 0 then c lor mask else c land (lnot mask) in
- data.[si] <- Char.unsafe_chr c
- )
-@@ -1161,7 +1161,7 @@ let get (data, off, len) n =
+- let c = if v <> 0 then c lor mask else c land (lnot mask) in
+- data.[si] <- Char.unsafe_chr c
+- )
+-
+-let set bits n = put bits n 1
+-
+-let clear bits n = put bits n 0
+-
+ let get (data, off, len) n =
+ if n < 0 || n >= len then index_out_of_bounds ()
else (
- let i = off+n in
- let si = i lsr 3 and mask = 0x80 lsr (i land 7) in
-- let c = Char.code data.[si] in
-+ let c = Char.code (Bytes.get data si) in
- c land mask
- )
-
-@@ -1181,7 +1181,8 @@ let hexdump_bitstring chan (data, off, len) =
+@@ -1181,7 +1167,7 @@ let hexdump_bitstring chan (data, off, len) =
let off = ref off in
let len = ref len in
let linelen = ref 0 in
- let linechars = String.make 16 ' ' in
+ let linechars = Bytes.make 16 ' ' in
-+ let data = Bytes.to_string data in
fprintf chan "00000000 ";
-@@ -1200,7 +1201,7 @@ let hexdump_bitstring chan (data, off, len) =
+@@ -1200,7 +1186,7 @@ let hexdump_bitstring chan (data, off, len) =
incr linelen;
if !linelen = 8 then fprintf chan " ";
if !linelen = 16 then (
@@ -219,7 +114,7 @@ index cfefb79..6f8b831 100644
linelen := 0;
for i = 0 to 15 do linechars.[i] <- ' ' done
)
-@@ -1209,6 +1210,6 @@ let hexdump_bitstring chan (data, off, len) =
+@@ -1209,6 +1195,6 @@ let hexdump_bitstring chan (data, off, len) =
if !linelen > 0 then (
let skip = (16 - !linelen) * 3 + if !linelen < 8 then 1 else 0 in
for i = 0 to skip-1 do fprintf chan " " done;
@@ -228,18 +123,32 @@ index cfefb79..6f8b831 100644
) else
fprintf chan "\n%!"
diff --git a/bitstring.mli b/bitstring.mli
-index 250739d..67ff2ef 100644
+index 250739d..ff4d887 100644
--- a/bitstring.mli
+++ b/bitstring.mli
-@@ -650,7 +650,7 @@ type endian = BigEndian | LittleEndian | NativeEndian
- val string_of_endian : endian -> string
- (** Endianness. *)
-
--type bitstring = string * int * int
-+type bitstring = bytes * int * int
- (** [bitstring] is the basic type used to store bitstrings.
+@@ -895,22 +895,12 @@ end
+ if the index is out of range of the bitstring.
+ *)
+
+-val set : bitstring -> int -> unit
+- (** [set bits n] sets the [n]th bit in the bitstring to 1. *)
+-
+-val clear : bitstring -> int -> unit
+- (** [clear bits n] sets the [n]th bit in the bitstring to 0. *)
+-
+ val is_set : bitstring -> int -> bool
+ (** [is_set bits n] is true if the [n]th bit is set to 1. *)
+
+ val is_clear : bitstring -> int -> bool
+ (** [is_clear bits n] is true if the [n]th bit is set to 0. *)
+
+-val put : bitstring -> int -> int -> unit
+- (** [put bits n v] sets the [n]th bit in the bitstring to 1
+- if [v] is not zero, or to 0 if [v] is zero. *)
+-
+ val get : bitstring -> int -> int
+ (** [get bits n] returns the [n]th bit (returns non-zero or 0). *)
- The type contains the underlying data (a string),
diff --git a/bitstring_persistent.mli b/bitstring_persistent.mli
index 10cbee3..305091e 100644
--- a/bitstring_persistent.mli