Skip to content

Commit

Permalink
ocamlformat 0.26.1
Browse files Browse the repository at this point in the history
  • Loading branch information
balat committed May 22, 2024
1 parent 20b9963 commit 7b56b45
Show file tree
Hide file tree
Showing 48 changed files with 683 additions and 686 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.19.0
version=0.26.1
break-cases = fit
break-collection-expressions = fit-or-vertical
break-fun-decl = wrap
Expand Down
18 changes: 9 additions & 9 deletions src/baselib/ocsigen_cache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ end = struct
end

module Weak = Weak.Make (struct
type t = unit -> unit
type t = unit -> unit

let hash = Hashtbl.hash
let equal = ( == )
end)
let hash = Hashtbl.hash
let equal = ( == )
end)

let clear_all = Weak.create 17

Expand All @@ -424,18 +424,18 @@ functor
->
struct
module H = Hashtbl.Make (struct
type t = A.key
type t = A.key

let equal a a' = a = a'
let hash = Hashtbl.hash
end)
let equal a a' = a = a'
let hash = Hashtbl.hash
end)

type t =
{ mutable pointers : A.key Dlist.t
; mutable table : (A.value * A.key Dlist.node) H.t
; finder : A.key -> A.value Lwt.t
; clear : unit -> unit
(* This function clears the cache. It is put inside the
(* This function clears the cache. It is put inside the
cache structure so that it is garbage-collected only when the cache
is no longer referenced, as the functions themselves are put inside
a weak hash table *)
Expand Down
34 changes: 15 additions & 19 deletions src/baselib/ocsigen_cache.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
*)

module Make : functor
(A : sig
type key
type value
end)
-> sig
(A : sig
type key
type value
end)
-> sig
(** [new cache finder ?timer size] creates a cache object where [finder]
is the function responsible for retrieving non-cached data, [timer]
(if any) is the life span of cached values (in seconds) (values in the
Expand All @@ -53,25 +53,21 @@ module Make : functor
Using [timer] allow one to create a cache
bounded both in space and time. It is to be noted that real lifespan
of values is always slightly greater than [timer]. *)
class cache :
(A.key -> A.value Lwt.t)
-> ?timer:float
-> int
-> object
method find : A.key -> A.value Lwt.t
(** Find the cached value associated to the key, or binds this
class cache : (A.key -> A.value Lwt.t) -> ?timer:float -> int -> object
method find : A.key -> A.value Lwt.t
(** Find the cached value associated to the key, or binds this
value in the cache using the function [finder] passed as argument
to [create], and returns this value *)

method find_in_cache : A.key -> A.value
(** Find the cached value associated to the key. Raises [Not_found]
method find_in_cache : A.key -> A.value
(** Find the cached value associated to the key. Raises [Not_found]
if the key is not present in the cache *)

method remove : A.key -> unit
method add : A.key -> A.value -> unit
method clear : unit -> unit
method size : int
end
method remove : A.key -> unit
method add : A.key -> A.value -> unit
method clear : unit -> unit
method size : int
end
end

val clear_all_caches : unit -> unit
Expand Down
4 changes: 2 additions & 2 deletions src/baselib/ocsigen_config_static.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ let datadir = ref "_DATADIR_"
let bindir = ref "_BINDIR_"
let extdir = ref "_EXTDIR_"
let command_pipe = ref "_COMMANDPIPE_"

let builtin_packages =
List.fold_left
(fun a s -> Ocsigen_lib.String.Set.add s a)
Ocsigen_lib.String.Set.empty
[_DEPS_]
Ocsigen_lib.String.Set.empty [_DEPS_]
42 changes: 21 additions & 21 deletions src/baselib/ocsigen_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module Ip_address = struct
in
let options =
[ (if v6
then Lwt_unix.AI_FAMILY Lwt_unix.PF_INET6
else Lwt_unix.AI_FAMILY Lwt_unix.PF_INET) ]
then Lwt_unix.AI_FAMILY Lwt_unix.PF_INET6
else Lwt_unix.AI_FAMILY Lwt_unix.PF_INET) ]
in
Lwt.bind (Lwt_unix.getaddrinfo host "" options) aux

Expand Down Expand Up @@ -181,7 +181,7 @@ module Url = struct

let fixup_url_string1 =
Netstring_pcre.global_substitute problem_re1 (fun m s ->
Printf.sprintf "%%%02x" (Char.code s.[fst (Pcre.get_substring_ofs m 0)]))
Printf.sprintf "%%%02x" (Char.code s.[fst (Pcre.get_substring_ofs m 0)]))

(* I add this fixup to handle %uxxxx sent by browsers.
Translated to %xx%xx *)
Expand All @@ -191,11 +191,11 @@ module Url = struct
fixup_url_string1
(Netstring_pcre.global_substitute problem_re2
(fun m s ->
String.concat ""
[ "%"
; Netstring_pcre.matched_group m 1 s
; "%"
; Netstring_pcre.matched_group m 2 s ])
String.concat ""
[ "%"
; Netstring_pcre.matched_group m 1 s
; "%"
; Netstring_pcre.matched_group m 2 s ])
s)

(*VVV This is in Netencoding but we have a problem with ~
Expand Down Expand Up @@ -296,19 +296,19 @@ module Url = struct
let l = String.length s1 in
Netstring_pcre.global_substitute url_decoding_re
(fun r _ ->
match Netstring_pcre.matched_string r s1 with
| "+" -> if plus then " " else "+"
| _ -> (
let i = fst (Pcre.get_substring_ofs r 0) in
(* Assertion: s1.[i] = '%' *)
if i + 2 >= l then failwith "decode";
let c1 = s1.[i + 1] in
let c2 = s1.[i + 2] in
try
let k1 = of_hex1 c1 in
let k2 = of_hex1 c2 in
String.make 1 (Char.chr ((k1 lsl 4) lor k2))
with Not_found -> failwith "decode"))
match Netstring_pcre.matched_string r s1 with
| "+" -> if plus then " " else "+"
| _ -> (
let i = fst (Pcre.get_substring_ofs r 0) in
(* Assertion: s1.[i] = '%' *)
if i + 2 >= l then failwith "decode";
let c1 = s1.[i + 1] in
let c2 = s1.[i + 2] in
try
let k1 = of_hex1 c1 in
let k2 = of_hex1 c2 in
String.make 1 (Char.chr ((k1 lsl 4) lor k2))
with Not_found -> failwith "decode"))
s1

let make_encoded_parameters params =
Expand Down
14 changes: 7 additions & 7 deletions src/baselib/ocsigen_lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

include
module type of Ocsigen_lib_base
with type poly = Ocsigen_lib_base.poly
and type yesnomaybe = Ocsigen_lib_base.yesnomaybe
and type ('a, 'b) leftright = ('a, 'b) Ocsigen_lib_base.leftright
and type 'a Clist.t = 'a Ocsigen_lib_base.Clist.t
and type 'a Clist.node = 'a Ocsigen_lib_base.Clist.node
with type poly = Ocsigen_lib_base.poly
and type yesnomaybe = Ocsigen_lib_base.yesnomaybe
and type ('a, 'b) leftright = ('a, 'b) Ocsigen_lib_base.leftright
and type 'a Clist.t = 'a Ocsigen_lib_base.Clist.t
and type 'a Clist.node = 'a Ocsigen_lib_base.Clist.node

val make_cryptographic_safe_string : unit -> string
(** Generate an unique and cryptographically safe random string.
Expand Down Expand Up @@ -60,8 +60,8 @@ module Url : sig
val make_encoded_parameters : (string * string) list -> string
val string_of_url_path : encode:bool -> path -> uri

val parse
: t
val parse :
t
-> bool option
* string option
* int option
Expand Down
10 changes: 5 additions & 5 deletions src/baselib/ocsigen_lib_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ end

module Int = struct
module Table = Map.Make (struct
type t = int
type t = int

let compare = compare
end)
let compare = compare
end)
end

(*****************************************************************************)
Expand Down Expand Up @@ -312,8 +312,8 @@ module Url_base = struct
(if https then "https://" else "http://")
^ host
^ (if (port = 80 && not https) || (https && port = 443)
then ""
else ":" ^ string_of_int port)
then ""
else ":" ^ string_of_int port)
^ uri

let remove_dotdot =
Expand Down
2 changes: 1 addition & 1 deletion src/baselib/ocsigen_loader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ let findfiles =
let deps =
List.filter
(fun a ->
not @@ String.Set.mem a Ocsigen_config_static.builtin_packages)
not @@ String.Set.mem a Ocsigen_config_static.builtin_packages)
(Findlib.package_deep_ancestors preds [package])
in
Lwt_log.ign_info_f ~section "Dependencies of %s: %s" package
Expand Down
35 changes: 17 additions & 18 deletions src/baselib/ocsigen_stream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ let rec get_aux st =
(Lwt.try_bind
(fun () -> Lazy.force st.stream)
(fun e ->
Lwt.return
(match e with
| Cont (s, rem) ->
st.stream <- rem;
Cont (s, get_aux st)
| _ -> e))
Lwt.return
(match e with
| Cont (s, rem) ->
st.stream <- rem;
Cont (s, get_aux st)
| _ -> e))
(fun e ->
st.stream <- lazy (Lwt.fail e);
Lwt.fail (Interrupted e)))
st.stream <- lazy (Lwt.fail e);
Lwt.fail (Interrupted e)))

let get st =
if st.in_use then raise Already_read;
Expand Down Expand Up @@ -141,7 +141,7 @@ let enlarge_stream = function
else
let long4 = long3 - max in
cont (String.sub new_s 0 max) (fun () ->
Lwt.return (Cont (String.sub new_s max long4, ff))))
Lwt.return (Cont (String.sub new_s max long4, ff))))

let rec stream_want s len =
(* returns a stream with at least len bytes read if possible *)
Expand All @@ -154,7 +154,7 @@ let rec stream_want s len =
Lwt.catch
(fun () -> enlarge_stream s >>= fun r -> Lwt.return (`OK r))
(function
| Stream_too_small -> Lwt.return `Too_small | e -> Lwt.fail e)
| Stream_too_small -> Lwt.return `Too_small | e -> Lwt.fail e)
>>= function
| `OK r -> stream_want r len
| `Too_small -> Lwt.return s)
Expand Down Expand Up @@ -191,17 +191,16 @@ let substream delim s =
try
let p, _ = Ocsigen_lib.Netstring_pcre.search_forward rdelim s 0 in
cont (String.sub s 0 p) (fun () ->
empty
(Some
(fun () ->
Lwt.return (Cont (String.sub s p (len - p), f)))))
empty
(Some
(fun () -> Lwt.return (Cont (String.sub s p (len - p), f)))))
with Not_found ->
let pos = len + 1 - ldelim in
cont (String.sub s 0 pos) (fun () ->
next f >>= function
| Finished _ -> Lwt.fail Stream_too_small
| Cont (s', f') ->
aux (Cont (String.sub s pos (len - pos) ^ s', f'))))
next f >>= function
| Finished _ -> Lwt.fail Stream_too_small
| Cont (s', f') ->
aux (Cont (String.sub s pos (len - pos) ^ s', f'))))
in
aux s

Expand Down
6 changes: 3 additions & 3 deletions src/baselib/polytables/polytables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
type 'a key = int * 'a option ref

module T = Map.Make (struct
type t = int
type t = int

let compare = compare
end)
let compare = compare
end)

type t = (unit -> unit) T.t ref

Expand Down
16 changes: 8 additions & 8 deletions src/baselib/tests/test_wrapping.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type a = {a : float; a_wrap : a Ocsigen_wrap.wrapper}

let a_wrap () =
Ocsigen_wrap.create_wrapper (fun t ->
{a = t.a +. 1.; a_wrap = Ocsigen_wrap.empty_wrapper})
{a = t.a +. 1.; a_wrap = Ocsigen_wrap.empty_wrapper})

let a i = {a = i; a_wrap = a_wrap ()}
let va = a 3.14
Expand Down Expand Up @@ -64,7 +64,7 @@ let ( -- ) x y =
aux y x []

(*
type l =
type l =
| A
| L of l * int
Expand Down Expand Up @@ -116,8 +116,8 @@ let i = ref 0

let mtoto () =
Ocsigen_wrap.create_wrapper (fun t ->
incr i;
string_of_float t.a, !i)
incr i;
string_of_float t.a, !i)

let mt () = Ocsigen_wrap.create_wrapper (fun t -> incr i; t.v2)
let toto i = {a = i; mtoto = mtoto ()}
Expand All @@ -140,13 +140,13 @@ let r3 = ref 88

let t1mark () =
Ocsigen_wrap.create_wrapper (fun t ->
incr r1;
{t1a = 3.14; t1mark = Ocsigen_wrap.empty_wrapper})
incr r1;
{t1a = 3.14; t1mark = Ocsigen_wrap.empty_wrapper})

let t2mark () =
Ocsigen_wrap.create_wrapper (fun t ->
(match t.t2f with Some f -> f r2 | None -> assert false);
{t with t2f = None; t2mark = Ocsigen_wrap.empty_wrapper})
(match t.t2f with Some f -> f r2 | None -> assert false);
{t with t2f = None; t2mark = Ocsigen_wrap.empty_wrapper})

let t1 = {t1a = 1.1; t1mark = t1mark ()}
let t2 = {t2t1 = t1; t2f = Some (fun r -> incr r; incr r3); t2mark = t2mark ()}
Expand Down
Loading

0 comments on commit 7b56b45

Please sign in to comment.