Permalink
Browse files

Minimal changes to support OCaml 4.00

  • Loading branch information...
1 parent d6b7a95 commit efe28fc741f214b47db2df7a3fbbdbc0d92c8dc4 @thelema thelema committed Jul 2, 2012
Showing with 42 additions and 4 deletions.
  1. +18 −0 src/batDigest.ml
  2. +14 −0 src/batDigest.mli
  3. +1 −2 src/batHashtbl.ml
  4. +3 −2 src/batInnerWeaktbl.ml
  5. +2 −0 src/batSys.ml
  6. +4 −0 src/batSys.mli
View
@@ -67,3 +67,21 @@ in
assert_equal ~printer:(Printf.sprintf "%S")
(legacy_result ()) (batteries_result ())
*)
+
+let from_hex s =
+ if String.length s <> 32 then raise (Invalid_argument "Digest.from_hex");
+ let digit c =
+ match c with
+ | '0'..'9' -> Char.code c - Char.code '0'
+ | 'A'..'F' -> Char.code c - Char.code 'A' + 10
+ | 'a'..'f' -> Char.code c - Char.code 'a' + 10
+ | _ -> raise (Invalid_argument "Digest.from_hex")
+ in
+ let byte i = digit s.[i] lsl 4 + digit s.[i+1] in
+ let result = String.create 16 in
+ for i = 0 to 15 do
+ result.[i] <- Char.chr (byte (2 * i));
+ done;
+ result
+
+let compare = String.compare
View
@@ -49,6 +49,12 @@ val file : string -> t
val to_hex : t -> string
(** Return the printable hexadecimal representation of the given digest. *)
+val from_hex : string -> t
+(** Convert a hexadecimal representation back into the corresponding digest.
+ Raise [Invalid_argument] if the argument is not exactly 32 hexadecimal
+ characters.
+ @since 4.00.0 *)
+
val channel : input -> int -> Digest.t
(** If [len] is nonnegative, [Digest.channel ic len] reads [len]
characters from channel [ic] and returns their digest, or raises
@@ -70,3 +76,11 @@ val print : 'a output -> Digest.t -> unit
val input : input -> Digest.t
(** Read a digest from the given input. *)
+
+val compare : t -> t -> int
+(** The comparison function for 16-character digest, with the same
+ specification as {!Pervasives.compare} and the implementation
+ shared with {!String.compare}. Along with the type [t], this
+ function [compare] allows the module [Digest] to be passed as
+ argument to the functors {!Set.Make} and {!Map.Make}.
+ @since 4.00.0 *)
View
@@ -27,7 +27,7 @@
Note: We can't directly [include Hashtbl] as this
would cause a collision on [Make]*)
type ('a, 'b) t = ('a, 'b) Hashtbl.t
- let create = Hashtbl.create
+ let create s = Hashtbl.create s
let clear = Hashtbl.clear
let add = Hashtbl.add
let copy = Hashtbl.copy
@@ -523,4 +523,3 @@
let find = find_option
end
end
-
View
@@ -94,7 +94,7 @@ module Make (H: Hashtbl.HashedType) : Hashtbl.S with type key = H.t = struct
let create = W.create and clear = W.clear
let find_all tbl key =
try all_value (W.find tbl (dummy key)) with Not_found-> []
- let rec find tbl key = top_value (W.find tbl (dummy key))
+ let find tbl key = top_value (W.find tbl (dummy key))
let add tbl key data =
let bd = bind_new key data in
let cls =
@@ -118,6 +118,8 @@ module Make (H: Hashtbl.HashedType) : Hashtbl.S with type key = H.t = struct
let copy tbl =
let tbl'= W.create (W.count tbl * 3 / 2 + 2) in
W.iter (fun cls -> W.add tbl' (Stack.copy cls)) tbl; tbl'
+ let stats _ = assert false
+ let reset _ = assert false
end
module StdHash = Make
@@ -135,4 +137,3 @@ let replace tbl k = replace tbl (repr k)
let mem tbl k = mem tbl (repr k)
let iter f = iter (fun k d -> f (obj k) d)
let fold f = fold (fun k d a -> f (obj k) d a)
-
View
@@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
+let big_endian = false
+
include Sys
let files_of d = BatArray.enum (readdir d)
View
@@ -99,6 +99,10 @@ val word_size : int
(** Size of one word on the machine currently executing the Caml
program, in bits: 32 or 64. *)
+val big_endian : bool
+(** Whether the machine currently executing the Caml program is big-endian.
+ @since 4.00.0 *)
+
val max_string_length : int
(** Maximum length of a string. *)

0 comments on commit efe28fc

Please sign in to comment.