diff options
author | Stephane Glondu <steph@glondu.net> | 2019-08-12 06:29:00 +0200 |
---|---|---|
committer | Stephane Glondu <steph@glondu.net> | 2019-08-12 06:29:00 +0200 |
commit | 7b088f6093ce141f8038e6cb98c3bf82a26be2f9 (patch) | |
tree | ac8510fe68363af9114847ae35ebfce04437d6c5 | |
parent | c85b0921f35cec79e437eb253be4fa73e44c41e4 (diff) |
New upstream version 1.0.13
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | bi_io.ml | 8 | ||||
-rw-r--r-- | bi_util.ml | 10 | ||||
-rw-r--r-- | bi_util.mli | 2 | ||||
-rw-r--r-- | bi_vint.ml | 17 |
5 files changed, 26 insertions, 17 deletions
@@ -1,4 +1,4 @@ -VERSION = 1.0.12 +VERSION = 1.0.13 FLAGS = -g -annot -bin-annot PACKS = easy-format @@ -84,7 +84,7 @@ biniou.cmxs: biniou.cmxa ocamlfind ocamlopt -shared -linkall -I . -o $@ $^ bdump.byte: biniou.cma bdump.ml - ocamlfind ocamlc -o $@ $(FLAGS) \ + ocamlfind ocamlc -compat-32 -o $@ $(FLAGS) \ -package $(PACKS) -linkpkg $^ bdump.native: biniou.cmxa bdump.ml @@ -92,7 +92,7 @@ bdump.native: biniou.cmxa bdump.ml -package $(PACKS) -linkpkg $^ test_biniou.byte: biniou.cma test_biniou.ml - ocamlfind ocamlc -o $@ $(FLAGS) \ + ocamlfind ocamlc -compat-32 -o $@ $(FLAGS) \ -package "$(PACKS) unix" -linkpkg $^ test_biniou.native: biniou.cmxa test_biniou.ml @@ -79,8 +79,14 @@ let hash_name s = record fields. *) + +let mask_31bit = + let n = Bi_util.int_size - 31 in + assert (n >= 0); + fun x -> (x lsl n) lsr n + let write_hashtag ob h has_arg = - let h = h land 0x7fffffff in + let h = mask_31bit h in let pos = Bi_outbuf.alloc ob 4 in let s = ob.o_s in String.unsafe_set s (pos+3) (Char.chr (h land 0xff)); @@ -43,3 +43,13 @@ let print_bits ?(pos = 0) ?len s = r.[k+8] <- if (i + 1) mod 8 = 0 then '\n' else ' ' done; r + +(* int size in bits *) +let int_size = + let c = ref 0 in + let r = ref (-1) in + while !r <> 0 do + r := !r lsr 1; + incr c + done; + !c diff --git a/bi_util.mli b/bi_util.mli index 7d6601b..34d99d3 100644 --- a/bi_util.mli +++ b/bi_util.mli @@ -13,3 +13,5 @@ val error : string -> 'a val string8_of_int : int -> string val string4_of_int : int -> string val print_bits : ?pos:int -> ?len:int -> string -> string + +val int_size : int @@ -6,25 +6,16 @@ open Bi_inbuf type uint = int -(* Word size in bytes *) -let word_size = - if 0x7fffffff = -1 then 4 - else 8 - -(* Maximum int size in bits *) -let max_int_bits = - 8 * word_size - 1 - (* Maximum length of a vint decodable into an OCaml int, maximum value of the highest byte of the largest vint supported *) let max_vint_bytes, max_highest_byte = - if max_int_bits mod 7 = 0 then - let m = max_int_bits / 7 in + if Bi_util.int_size mod 7 = 0 then + let m = Bi_util.int_size / 7 in let h = 1 lsl 7 - 1 in m, h else - let m = max_int_bits / 7 + 1 in - let h = 1 lsl (max_int_bits mod 7) - 1 in + let m = Bi_util.int_size / 7 + 1 in + let h = 1 lsl (Bi_util.int_size mod 7) - 1 in m, h let check_highest_byte x = |