Skip to content

Commit

Permalink
Minimal changes to support OCaml 4.00
Browse files Browse the repository at this point in the history
  • Loading branch information
thelema committed Aug 30, 2012
1 parent d6b7a95 commit efe28fc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/batDigest.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ in
assert_equal ~printer:(Printf.sprintf "%S") assert_equal ~printer:(Printf.sprintf "%S")
(legacy_result ()) (batteries_result ()) (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
14 changes: 14 additions & 0 deletions src/batDigest.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ val file : string -> t
val to_hex : t -> string val to_hex : t -> string
(** Return the printable hexadecimal representation of the given digest. *) (** 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 val channel : input -> int -> Digest.t
(** If [len] is nonnegative, [Digest.channel ic len] reads [len] (** If [len] is nonnegative, [Digest.channel ic len] reads [len]
characters from channel [ic] and returns their digest, or raises characters from channel [ic] and returns their digest, or raises
Expand All @@ -70,3 +76,11 @@ val print : 'a output -> Digest.t -> unit


val input : input -> Digest.t val input : input -> Digest.t
(** Read a digest from the given input. *) (** 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 *)
3 changes: 1 addition & 2 deletions src/batHashtbl.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Note: We can't directly [include Hashtbl] as this Note: We can't directly [include Hashtbl] as this
would cause a collision on [Make]*) would cause a collision on [Make]*)
type ('a, 'b) t = ('a, 'b) Hashtbl.t type ('a, 'b) t = ('a, 'b) Hashtbl.t
let create = Hashtbl.create let create s = Hashtbl.create s
let clear = Hashtbl.clear let clear = Hashtbl.clear
let add = Hashtbl.add let add = Hashtbl.add
let copy = Hashtbl.copy let copy = Hashtbl.copy
Expand Down Expand Up @@ -523,4 +523,3 @@
let find = find_option let find = find_option
end end
end end

5 changes: 3 additions & 2 deletions src/batInnerWeaktbl.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 create = W.create and clear = W.clear
let find_all tbl key = let find_all tbl key =
try all_value (W.find tbl (dummy key)) with Not_found-> [] 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 add tbl key data =
let bd = bind_new key data in let bd = bind_new key data in
let cls = let cls =
Expand All @@ -118,6 +118,8 @@ module Make (H: Hashtbl.HashedType) : Hashtbl.S with type key = H.t = struct
let copy tbl = let copy tbl =
let tbl'= W.create (W.count tbl * 3 / 2 + 2) in let tbl'= W.create (W.count tbl * 3 / 2 + 2) in
W.iter (fun cls -> W.add tbl' (Stack.copy cls)) tbl; tbl' W.iter (fun cls -> W.add tbl' (Stack.copy cls)) tbl; tbl'
let stats _ = assert false
let reset _ = assert false
end end


module StdHash = Make module StdHash = Make
Expand All @@ -135,4 +137,3 @@ let replace tbl k = replace tbl (repr k)
let mem tbl k = mem tbl (repr k) let mem tbl k = mem tbl (repr k)
let iter f = iter (fun k d -> f (obj k) d) let iter f = iter (fun k d -> f (obj k) d)
let fold f = fold (fun k d a -> f (obj k) d a) let fold f = fold (fun k d a -> f (obj k) d a)

2 changes: 2 additions & 0 deletions src/batSys.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*) *)


let big_endian = false

include Sys include Sys


let files_of d = BatArray.enum (readdir d) let files_of d = BatArray.enum (readdir d)
Expand Down
4 changes: 4 additions & 0 deletions src/batSys.mli
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ val word_size : int
(** Size of one word on the machine currently executing the Caml (** Size of one word on the machine currently executing the Caml
program, in bits: 32 or 64. *) 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 val max_string_length : int
(** Maximum length of a string. *) (** Maximum length of a string. *)


Expand Down

0 comments on commit efe28fc

Please sign in to comment.