git: 4014d0b9962c - main - devel/ocaml-sexplib: unbreak against immutable strings in OCaml 4.06+.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 11 Apr 2022 06:18:52 UTC
The branch main has been updated by danfe:
URL: https://cgit.FreeBSD.org/ports/commit/?id=4014d0b9962c0c00b1bfe709696fa20797ee4e81
commit 4014d0b9962c0c00b1bfe709696fa20797ee4e81
Author: Alexey Dokuchaev <danfe@FreeBSD.org>
AuthorDate: 2022-04-11 06:18:08 +0000
Commit: Alexey Dokuchaev <danfe@FreeBSD.org>
CommitDate: 2022-04-11 06:18:08 +0000
devel/ocaml-sexplib: unbreak against immutable strings in OCaml 4.06+.
---
devel/ocaml-sexplib/files/patch-lib_conv.ml | 26 ++--
devel/ocaml-sexplib/files/patch-lib_lexer.mll | 29 +++++
devel/ocaml-sexplib/files/patch-lib_path.ml | 16 +++
devel/ocaml-sexplib/files/patch-lib_pre__sexp.ml | 139 ++++++++++++++++++++++
devel/ocaml-sexplib/files/patch-lib_sexp__intf.ml | 133 +++++++++++++++++++++
5 files changed, 334 insertions(+), 9 deletions(-)
diff --git a/devel/ocaml-sexplib/files/patch-lib_conv.ml b/devel/ocaml-sexplib/files/patch-lib_conv.ml
index 4e1382e8aa58..60f5ec3cb17e 100644
--- a/devel/ocaml-sexplib/files/patch-lib_conv.ml
+++ b/devel/ocaml-sexplib/files/patch-lib_conv.ml
@@ -1,11 +1,19 @@
-From cba80ebe02962504fbe404b1baf484a5000f44b4
-From: Jeremie Dimino <jdimino@janestreet.com>
-Date: Tue, 12 Jul 2016 17:08:10 +0100
-Subject: [PATCH] 114.01+04
-
---- lib/conv.ml.orig 2016-03-09 15:44:55 UTC
+--- lib/conv.ml.orig 2015-08-18 11:17:27 UTC
+++ lib/conv.ml
-@@ -185,7 +185,7 @@ module Exn_converter = struct
+@@ -92,9 +92,9 @@ let sexp_of_float_vec vec =
+
+ let sexp_of_bigstring (bstr : bigstring) =
+ let n = Array1.dim bstr in
+- let str = String.create n in
+- for i = 0 to n - 1 do str.[i] <- bstr.{i} done;
+- Atom str
++ let str = Bytes.create n in
++ for i = 0 to n - 1 do Bytes.set str i bstr.{i} done;
++ Atom (Bytes.unsafe_to_string str)
+
+ let sexp_of_float32_vec (vec : float32_vec) = sexp_of_float_vec vec
+ let sexp_of_float64_vec (vec : float64_vec) = sexp_of_float_vec vec
+@@ -183,7 +183,7 @@ module Exn_converter = struct
(* [Obj.extension_id] works on both the exception itself, and the extension slot of the
exception. *)
@@ -14,7 +22,7 @@ Subject: [PATCH] 114.01+04
let id = Obj.extension_id slot in
let old_exn_id_map = !exn_id_map in
let new_exn_id_map = Exn_ids.remove id old_exn_id_map in
-@@ -196,7 +196,7 @@ module Exn_converter = struct
+@@ -194,7 +194,7 @@ module Exn_converter = struct
exn_id_map := new_exn_id_map
let add_auto ?(finalise = true) exn sexp_of_exn =
@@ -23,7 +31,7 @@ Subject: [PATCH] 114.01+04
let rec loop () =
let old_exn_id_map = !exn_id_map in
let new_exn_id_map = Exn_ids.add id sexp_of_exn old_exn_id_map in
-@@ -205,13 +205,18 @@ module Exn_converter = struct
+@@ -203,13 +203,18 @@ module Exn_converter = struct
loop ()
else begin
exn_id_map := new_exn_id_map;
diff --git a/devel/ocaml-sexplib/files/patch-lib_lexer.mll b/devel/ocaml-sexplib/files/patch-lib_lexer.mll
new file mode 100644
index 000000000000..f531544ee1df
--- /dev/null
+++ b/devel/ocaml-sexplib/files/patch-lib_lexer.mll
@@ -0,0 +1,29 @@
+--- lib/lexer.mll.orig 2015-08-18 11:17:27 UTC
++++ lib/lexer.mll
+@@ -54,7 +54,7 @@
+ type t
+ val create : int -> t
+ val add_char : t -> char -> unit
+- val add_substring : t -> string -> int -> int -> unit
++ val add_subbytes : t -> bytes -> int -> int -> unit
+ val add_lexeme : t -> lexbuf -> unit
+ val clear : t -> unit
+ val of_buffer : Buffer.t -> t
+@@ -189,7 +189,7 @@ and scan_string buf start = parse
+ {
+ let ofs = lexbuf.lex_start_pos in
+ let len = lexbuf.lex_curr_pos - ofs in
+- Quoted_string_buffer.add_substring buf lexbuf.lex_buffer ofs len;
++ Quoted_string_buffer.add_subbytes buf lexbuf.lex_buffer ofs len;
+ Quoted_string_buffer.add_lexeme buf lexbuf;
+ scan_string buf start lexbuf
+ }
+@@ -294,7 +294,7 @@ and scan_block_comment buf locs = parse
+ let create n = {contents = Buffer.create n; lexeme = Buffer.create n}
+ let of_buffer contents = { contents; lexeme = Buffer.create 64 }
+ let add_char t ch = Buffer.add_char t.contents ch
+- let add_substring t str ofs len = Buffer.add_substring t.contents str ofs len
++ let add_subbytes t str ofs len = Buffer.add_subbytes t.contents str ofs len
+ let add_lexeme t lexbuf = Buffer.add_string t.lexeme (Lexing.lexeme lexbuf)
+ let clear t = Buffer.clear t.lexeme; Buffer.clear t.contents
+ end
diff --git a/devel/ocaml-sexplib/files/patch-lib_path.ml b/devel/ocaml-sexplib/files/patch-lib_path.ml
new file mode 100644
index 000000000000..551bbf75f2c8
--- /dev/null
+++ b/devel/ocaml-sexplib/files/patch-lib_path.ml
@@ -0,0 +1,16 @@
+--- lib/path.ml.orig 2015-08-18 11:17:27 UTC
++++ lib/path.ml
+@@ -74,10 +74,10 @@ and subst_path sexp = function
+
+ let implode lst =
+ let len = List.length lst in
+- let str = String.create len in
++ let str = Bytes.create len in
+ let rec loop ix = function
+- | h :: t -> str.[ix] <- h; loop (ix + 1) t
+- | [] -> str in
++ | h :: t -> Bytes.set str ix h; loop (ix + 1) t
++ | [] -> Bytes.unsafe_to_string str in
+ loop 0 lst
+
+ let fail_parse msg = failwith ("Path.parse: " ^ msg)
diff --git a/devel/ocaml-sexplib/files/patch-lib_pre__sexp.ml b/devel/ocaml-sexplib/files/patch-lib_pre__sexp.ml
new file mode 100644
index 000000000000..bbc40c44febb
--- /dev/null
+++ b/devel/ocaml-sexplib/files/patch-lib_pre__sexp.ml
@@ -0,0 +1,139 @@
+--- lib/pre_sexp.ml.orig 2015-08-18 11:17:27 UTC
++++ lib/pre_sexp.ml
+@@ -32,11 +32,11 @@ let must_escape str =
+ let esc_str str =
+ let estr = String.escaped str in
+ let elen = String.length estr in
+- let res = String.create (elen + 2) in
++ let res = Bytes.create (elen + 2) in
+ String.blit estr 0 res 1 elen;
+- res.[0] <- '"';
+- res.[elen + 1] <- '"';
+- res
++ Bytes.set res 0 '"';
++ Bytes.set res (elen + 1) '"';
++ Bytes.unsafe_to_string res
+
+ let index_of_newline str start =
+ try Some (String.index_from str start '\n')
+@@ -898,7 +898,7 @@ let mk_cont_parser cont_parse = (); fun _state str ~ma
+ PARSE state str ~max_pos ~pos
+
+ MK_PARSER(
+- string, String.length, parse_str, str.[pos],
++ string, String.length, parse_str, String.get str pos,
+ state.pstack, state.pstack <- pstack,
+ ,,
+ Atom pbuf_str, List sexp_lst, [], `Sexp
+@@ -906,7 +906,6 @@ MK_PARSER(
+
+ let parse = parse_str
+
+-
+ (* Annot parsers *)
+
+ let get_glob_ofs parse_pos pos =
+@@ -954,7 +953,7 @@ let mk_annot_list parse_state annot_lst pos =
+ let init_annot_pstate () = { Annot.positions = []; stack = [] }
+
+ MK_PARSER(
+- string, String.length, parse_str_annot, str.[pos],
++ string, String.length, parse_str_annot, String.get str pos,
+ state.pstack.Annot.stack, state.pstack.Annot.stack <- pstack,
+ add_annot_pos state pos;,add_annot_pos1 state pos;,
+ mk_annot_atom state pbuf_str pos, mk_annot_list state sexp_lst pos,
+@@ -995,11 +994,11 @@ let mk_this_parse ?parse_pos my_parse = (); fun ~pos ~
+ my_parse ?parse_pos:(Some parse_pos) ?len:(Some len) str
+
+ let gen_input_sexp my_parse ?parse_pos ic =
+- let buf = String.create 1 in
++ let buf = Bytes.create 1 in
+ let rec loop this_parse =
+ let c = input_char ic in
+- buf.[0] <- c;
+- match this_parse ~pos:0 ~len:1 buf with
++ Bytes.set buf 0 c;
++ match this_parse ~pos:0 ~len:1 (Bytes.unsafe_to_string buf) with
+ | Done (sexp, _) -> sexp
+ | Cont (_, this_parse) -> loop this_parse
+ in
+@@ -1007,12 +1006,12 @@ let gen_input_sexp my_parse ?parse_pos ic =
+
+ let input_sexp ?parse_pos ic = gen_input_sexp parse ?parse_pos ic
+
+-let gen_input_rev_sexps my_parse ?parse_pos ?(buf = String.create 8192) ic =
++let gen_input_rev_sexps my_parse ?parse_pos ?(buf = Bytes.create 8192) ic =
+ let rev_sexps_ref = ref [] in
+- let buf_len = String.length buf in
++ let buf_len = Bytes.length buf in
+ let rec loop this_parse ~pos ~len ~cont_state =
+ if len > 0 then
+- match this_parse ~pos ~len buf with
++ match this_parse ~pos ~len (Bytes.unsafe_to_string buf) with
+ | Done (sexp, ({ Parse_pos.buf_pos; _ } as parse_pos)) ->
+ rev_sexps_ref := sexp :: !rev_sexps_ref;
+ let n_parsed = buf_pos - pos in
+@@ -1073,9 +1072,9 @@ let of_string str =
+ of_string_bigstring "of_string" parse " " String.length String.sub str
+
+ let get_bstr_sub_str bstr pos len =
+- let str = String.create len in
+- for i = 0 to len - 1 do str.[i] <- bstr.{pos + i} done;
+- str
++ let str = Bytes.create len in
++ for i = 0 to len - 1 do Bytes.set str i (bstr.{pos + i}) done;
++ Bytes.unsafe_to_string str
+
+ let bstr_ws_buf = Array1.create char c_layout 1
+ let () = bstr_ws_buf.{0} <- ' '
+@@ -1101,8 +1100,8 @@ let load_sexps ?buf file = List.rev (load_rev_sexps ?b
+
+ let gen_load_sexp_loc = "Sexplib.Sexp.gen_load_sexp"
+
+-let gen_load_sexp my_parse ?(strict = true) ?(buf = String.create 8192) file =
+- let buf_len = String.length buf in
++let gen_load_sexp my_parse ?(strict = true) ?(buf = Bytes.create 8192) file =
++ let buf_len = Bytes.length buf in
+ let ic = open_in file in
+ let rec loop this_parse ~cont_state =
+ let len = input ic buf 0 buf_len in
+@@ -1111,10 +1110,10 @@ let gen_load_sexp my_parse ?(strict = true) ?(buf = St
+ sprintf "%s: EOF in %s while in state %s"
+ gen_load_sexp_loc file (Cont_state.to_string cont_state))
+ else
+- match this_parse ~pos:0 ~len buf with
++ match this_parse ~pos:0 ~len (Bytes.unsafe_to_string buf) with
+ | Done (sexp, ({ Parse_pos.buf_pos; _ } as parse_pos)) when strict ->
+ let rec strict_loop this_parse ~pos ~len =
+- match this_parse ~pos ~len buf with
++ match this_parse ~pos ~len (Bytes.unsafe_to_string buf) with
+ | Done _ ->
+ failwith (
+ sprintf "%s: more than one S-expression in file %s"
+@@ -1186,7 +1185,7 @@ module Annotated = struct
+ Of_sexp_error (Annot.Conv_exn (loc, exc), get_sexp annot_sexp)
+ end
+
+-let load_sexp_conv ?(strict = true) ?(buf = String.create 8192) file f =
++let load_sexp_conv ?(strict = true) ?(buf = Bytes.create 8192) file f =
+ let sexp = load_sexp ~strict ~buf file in
+ try `Result (f sexp)
+ with Of_sexp_error _ ->
+@@ -1200,7 +1199,7 @@ let raise_conv_exn ~file = function
+ let load_sexp_conv_exn ?strict ?buf file f =
+ raise_conv_exn ~file (load_sexp_conv ?strict ?buf file f)
+
+-let load_sexps_conv ?(buf = String.create 8192) file f =
++let load_sexps_conv ?(buf = Bytes.create 8192) file f =
+ let rev_sexps = load_rev_sexps ~buf file in
+ try List.rev_map (fun sexp -> `Result (f sexp)) rev_sexps
+ with Of_sexp_error _ as e ->
+@@ -1212,7 +1211,7 @@ let load_sexps_conv ?(buf = String.create 8192) file f
+ List.rev_map (fun annot_sexp -> Annotated.conv f annot_sexp)
+ rev_annot_sexps
+
+-let load_sexps_conv_exn ?(buf = String.create 8192) file f =
++let load_sexps_conv_exn ?(buf = Bytes.create 8192) file f =
+ let rev_sexps = load_rev_sexps ~buf file in
+ try List.rev_map f rev_sexps
+ with Of_sexp_error _ as e ->
diff --git a/devel/ocaml-sexplib/files/patch-lib_sexp__intf.ml b/devel/ocaml-sexplib/files/patch-lib_sexp__intf.ml
new file mode 100644
index 000000000000..725cdd7d5138
--- /dev/null
+++ b/devel/ocaml-sexplib/files/patch-lib_sexp__intf.ml
@@ -0,0 +1,133 @@
+--- lib/sexp_intf.ml.orig 2015-08-18 11:17:27 UTC
++++ lib/sexp_intf.ml
+@@ -192,12 +192,12 @@ module type S = sig
+ annotated S-expression instead. *)
+
+ val input_sexps :
+- ?parse_pos : Parse_pos.t -> ?buf : string -> in_channel -> t list
++ ?parse_pos : Parse_pos.t -> ?buf : bytes -> in_channel -> t list
+ (** [input_sexps ?parse_pos ?buf ic] like {!input_sexps}, but returns
+ a list of annotated S-expressions. *)
+
+ val input_rev_sexps :
+- ?parse_pos : Parse_pos.t -> ?buf : string -> in_channel -> t list
++ ?parse_pos : Parse_pos.t -> ?buf : bytes -> in_channel -> t list
+ (** [input_sexps ?parse_pos ?buf ic] like {!input_rev_sexps}, but
+ returns a list of annotated S-expressions. *)
+
+@@ -207,15 +207,15 @@ module type S = sig
+ (** NOTE: these functions should only be used if an annotated S-expression
+ is required. *)
+
+- val load_sexp : ?strict : bool -> ?buf : string -> string -> t
++ val load_sexp : ?strict : bool -> ?buf : bytes -> string -> t
+ (** [load_sexp ?strict ?buf file] like {!load_sexp}, but returns an
+ annotated S-expression. *)
+
+- val load_sexps : ?buf : string -> string -> t list
++ val load_sexps : ?buf : bytes -> string -> t list
+ (** [load_sexps ?buf file] like {!load_sexps}, but returns a list of
+ annotated S-expressions. *)
+
+- val load_rev_sexps : ?buf : string -> string -> t list
++ val load_rev_sexps : ?buf : bytes -> string -> t list
+ (** [load_rev_sexps ?buf file] like {!load_rev_sexps}, but returns a
+ list of annotated S-expressions. *)
+
+@@ -311,7 +311,7 @@ module type S = sig
+ *)
+
+ val input_sexps :
+- ?parse_pos : Parse_pos.t -> ?buf : string -> in_channel -> t list
++ ?parse_pos : Parse_pos.t -> ?buf : bytes -> in_channel -> t list
+ (** [input_sexps ?parse_pos ?buf ic] parses whitespace separated
+ S-expressions from input channel [ic] until EOF is reached. Faster than
+ the scan-functions.
+@@ -320,7 +320,7 @@ module type S = sig
+ *)
+
+ val input_rev_sexps :
+- ?parse_pos : Parse_pos.t -> ?buf : string -> in_channel -> t list
++ ?parse_pos : Parse_pos.t -> ?buf : bytes -> in_channel -> t list
+ (** [input_rev_sexps ?parse_pos ?buf ic] same as {!Sexp.input_sexps},
+ but returns a reversed list of S-expressions, which is slightly more
+ efficient. *)
+@@ -328,7 +328,7 @@ module type S = sig
+
+ (** {6 Loading of (converted) S-expressions} *)
+
+- val load_sexp : ?strict : bool -> ?buf : string -> string -> t
++ val load_sexp : ?strict : bool -> ?buf : bytes -> string -> t
+ (** [load_sexp ?strict ?buf file] reads one S-expression from [file] using
+ buffer [buf] for storing intermediate data. Faster than the
+ scan-functions.
+@@ -344,7 +344,7 @@ module type S = sig
+ @param strict default = [true]
+ *)
+
+- val load_sexps : ?buf : string -> string -> t list
++ val load_sexps : ?buf : bytes -> string -> t list
+ (** [load_sexps ?buf file] reads a list of whitespace separated S-expressions
+ from [file] using buffer [buf] for storing intermediate data.
+ Faster than the scan-functions.
+@@ -355,12 +355,12 @@ module type S = sig
+ S-expression could be fully read.
+ *)
+
+- val load_rev_sexps : ?buf : string -> string -> t list
++ val load_rev_sexps : ?buf : bytes -> string -> t list
+ (** [load_rev_sexps ?buf file] same as {!Sexp.load_sexps}, but returns a
+ reversed list of S-expressions, which is slightly more efficient. *)
+
+ val load_sexp_conv :
+- ?strict : bool -> ?buf : string -> string -> (t -> 'a) -> 'a Annotated.conv
++ ?strict : bool -> ?buf : bytes -> string -> (t -> 'a) -> 'a Annotated.conv
+ (** [load_sexp_conv ?strict ?buf file f] like {!Sexp.load_sexp}, but
+ performs a conversion on the fly using [f]. Performance is equivalent
+ to executing {!Sexp.load_sexp} and performing conversion when there
+@@ -375,13 +375,13 @@ module type S = sig
+ *)
+
+ val load_sexp_conv_exn :
+- ?strict : bool -> ?buf : string -> string -> (t -> 'a) -> 'a
++ ?strict : bool -> ?buf : bytes -> string -> (t -> 'a) -> 'a
+ (** [load_sexp_conv_exn ?strict ?buf file f] like {!load_sexp_conv},
+ but returns the converted value or raises [Of_sexp_error] with exact
+ location information in the case of a conversion error. *)
+
+ val load_sexps_conv :
+- ?buf : string -> string -> (t -> 'a) -> 'a Annotated.conv list
++ ?buf : bytes -> string -> (t -> 'a) -> 'a Annotated.conv list
+ (** [load_sexps_conv ?buf file f] like {!Sexp.load_sexps}, but performs
+ a conversion on the fly using [f]. Performance is equivalent to
+ executing {!Sexp.load_sexps} and performing conversion when there
+@@ -395,7 +395,7 @@ module type S = sig
+ S-expression could be fully read.
+ *)
+
+- val load_sexps_conv_exn : ?buf : string -> string -> (t -> 'a) -> 'a list
++ val load_sexps_conv_exn : ?buf : bytes -> string -> (t -> 'a) -> 'a list
+ (** [load_sexps_conv_exn ?buf file f] like {!load_sexps_conv}, but returns
+ the converted value or raises [Of_sexp_error] with exact location
+ information in the case of a conversion error. *)
+@@ -611,14 +611,16 @@ module type S = sig
+ type pos = Src_pos.Relative.t = { row : int; col : int }
+ val sexp_of_pos : pos -> Type.t
+
+- (** S-expressions annotated with relative source positions and comments *)
+- type t =
++ (** S-expressions annotated with relative source positions and comments. All the
++ positions are relative to the opening paren of the enclosing list, or the first
++ character of the file. *)
++ type t = Type_with_layout.t =
+ | Atom of pos * string * string option (* second is quoted representation *)
+ | List of pos * t_or_comment list * pos (* positions of left and right parens *)
+- and t_or_comment =
++ and t_or_comment = Type_with_layout.t_or_comment =
+ | Sexp of t
+ | Comment of comment
+- and comment =
++ and comment = Type_with_layout.comment =
+ | Plain_comment of pos * string (* line or block comment *)
+ | Sexp_comment of pos * comment list * t (* position of #; *)
+