git: 4f4912744b79 - main - devel/ocaml-annexlib: convert to safe-by-default strings for OCaml 4.06+.
Alexey Dokuchaev
danfe at FreeBSD.org
Tue Sep 7 09:19:35 UTC 2021
The branch main has been updated by danfe:
URL: https://cgit.FreeBSD.org/ports/commit/?id=4f4912744b7930e00a1ccf46c508d88b16806ea8
commit 4f4912744b7930e00a1ccf46c508d88b16806ea8
Author: Alexey Dokuchaev <danfe at FreeBSD.org>
AuthorDate: 2021-09-07 09:18:24 +0000
Commit: Alexey Dokuchaev <danfe at FreeBSD.org>
CommitDate: 2021-09-07 09:18:25 +0000
devel/ocaml-annexlib: convert to safe-by-default strings for OCaml 4.06+.
---
devel/ocaml-annexlib/files/patch-glob.ml | 27 +++++
devel/ocaml-annexlib/files/patch-iOExtras.ml | 8 ++
devel/ocaml-annexlib/files/patch-strExtras.ml | 137 +++++++++++++++++++++++++
devel/ocaml-annexlib/files/patch-strExtras.mli | 15 +++
devel/ocaml-annexlib/files/patch-syslog.ml | 25 +++++
5 files changed, 212 insertions(+)
diff --git a/devel/ocaml-annexlib/files/patch-glob.ml b/devel/ocaml-annexlib/files/patch-glob.ml
new file mode 100644
index 000000000000..e4afaa334074
--- /dev/null
+++ b/devel/ocaml-annexlib/files/patch-glob.ml
@@ -0,0 +1,27 @@
+--- glob.ml.orig 2006-02-23 06:34:35 UTC
++++ glob.ml
+@@ -100,13 +100,13 @@ let rec optimize_pattern pat res =
+ let s = String.create 2 in
+ s.[0] <- c2;
+ s.[1] <- c1;
+- optimize_pattern (String s :: cdr) res
++ optimize_pattern (String (Bytes.unsafe_to_string s) :: cdr) res
+ | String s :: Char c :: cdr ->
+ let len = String.length s in
+ let ns = String.create (len + 1) in
+ ns.[0] <- c;
+ String.blit s 0 ns 1 (String.length s);
+- optimize_pattern (String ns :: cdr) res
++ optimize_pattern (String (Bytes.unsafe_to_string ns) :: cdr) res
+ | Star :: Star :: cdr -> optimize_pattern (Star :: cdr) res
+ | cons :: cdr -> optimize_pattern cdr (cons :: res)
+
+@@ -245,7 +245,7 @@ let quote_str s =
+ | c ->
+ buf.[!pos] <- c; pos := !pos + 1
+ done;
+- String.sub buf 0 !pos
++ Bytes.sub_string buf 0 !pos
+
+ let rec conv_str buf pat =
+ match pat with
diff --git a/devel/ocaml-annexlib/files/patch-iOExtras.ml b/devel/ocaml-annexlib/files/patch-iOExtras.ml
new file mode 100644
index 000000000000..456112235002
--- /dev/null
+++ b/devel/ocaml-annexlib/files/patch-iOExtras.ml
@@ -0,0 +1,8 @@
+--- iOExtras.ml.orig 2006-02-23 22:09:29 UTC
++++ iOExtras.ml
+@@ -87,4 +87,4 @@ let snarf_file filename =
+ ofs := !ofs + bytes;
+ done;
+ close fd;
+- s
++ Bytes.unsafe_to_string s
diff --git a/devel/ocaml-annexlib/files/patch-strExtras.ml b/devel/ocaml-annexlib/files/patch-strExtras.ml
new file mode 100644
index 000000000000..0ed2c4593bbc
--- /dev/null
+++ b/devel/ocaml-annexlib/files/patch-strExtras.ml
@@ -0,0 +1,137 @@
+--- strExtras.ml.orig 2006-02-23 06:34:35 UTC
++++ strExtras.ml
+@@ -144,7 +144,7 @@ let map f str =
+ for n = 0 to len - 1 do
+ String.unsafe_set nstr n (f (String.unsafe_get str n))
+ done;
+- nstr
++ Bytes.unsafe_to_string nstr
+
+ let mapi f str =
+ let len = String.length str in
+@@ -152,18 +152,18 @@ let mapi f str =
+ for n = 0 to len - 1 do
+ String.unsafe_set nstr n (f (String.unsafe_get str n) n)
+ done;
+- nstr
++ Bytes.unsafe_to_string nstr
+
+ let map_inplace f str =
+- let len = String.length str in
++ let len = Bytes.length str in
+ for n = 0 to len - 1 do
+- String.unsafe_set str n (f (String.unsafe_get str n))
++ Bytes.unsafe_set str n (f (Bytes.unsafe_get str n))
+ done
+
+ let mapi_inplace f str =
+- let len = String.length str in
++ let len = Bytes.length str in
+ for n = 0 to len - 1 do
+- String.unsafe_set str n (f (String.unsafe_get str n) n)
++ Bytes.unsafe_set str n (f (Bytes.unsafe_get str n) n)
+ done
+
+ let iteri f str =
+@@ -194,16 +194,16 @@ let lowercase = map CharExtras.to_lower
+ let capitalize str =
+ if String.length str = 0 then ""
+ else
+- let nstr = String.copy str in
+- String.unsafe_set nstr 0 (CharExtras.to_upper (String.unsafe_get nstr 0));
+- nstr
++ let nstr = Bytes.of_string str in
++ Bytes.unsafe_set nstr 0 (CharExtras.to_upper (Bytes.unsafe_get nstr 0));
++ Bytes.unsafe_to_string nstr
+
+ let uncapitalize str =
+ if String.length str = 0 then ""
+ else
+- let nstr = String.copy str in
+- String.unsafe_set nstr 0 (CharExtras.to_lower (String.unsafe_get nstr 0));
+- nstr
++ let nstr = Bytes.of_string str in
++ Bytes.unsafe_set nstr 0 (CharExtras.to_lower (Bytes.unsafe_get nstr 0));
++ Bytes.unsafe_to_string nstr
+
+
+ let startletter = Pcre.regexp "\\b\\w"
+@@ -281,28 +281,28 @@ let center ?(pad=' ') ?(trunc=false) src width =
+ String.copy src
+ end else
+ let space = (width - len) / 2 in
+- let centered = String.make width pad in
++ let centered = Bytes.make width pad in
+ String.blit src 0 centered space len;
+- centered
++ Bytes.unsafe_to_string centered
+
+ let rev s =
+- let str = String.copy s in
++ let str = Bytes.of_string s in
+ let n = ref 0
+- and p = ref ((String.length str) - 1) in
++ and p = ref ((Bytes.length str) - 1) in
+ while !n < !p do
+- let tmp = String.unsafe_get str !n in
+- String.unsafe_set str !n (String.unsafe_get str !p);
++ let tmp = Bytes.unsafe_get str !n in
++ Bytes.unsafe_set str !n (Bytes.unsafe_get str !p);
+ String.unsafe_set str !p tmp;
+ incr n;
+ decr p;
+ done;
+- str
++ Bytes.unsafe_to_string str
+
+ let implode lst =
+ let str = String.create (List.length lst) in
+ let pos = ref 0 in
+ List.iter (fun c -> str.[!pos] <- c; incr pos) lst;
+- str
++ Bytes.unsafe_to_string str
+
+ let explode str =
+ let res = ref [] in
+@@ -332,9 +332,9 @@ let ljust ?(pad=' ') ?(trunc=false) str n =
+ else
+ String.copy str
+ end else
+- let newstr = String.make n pad in
++ let newstr = Bytes.make n pad in
+ String.blit str 0 newstr 0 len;
+- newstr
++ Bytes.unsafe_to_string newstr
+
+ let rjust ?(pad=' ') ?(trunc=false) str n =
+ let len = String.length str in
+@@ -344,9 +344,9 @@ let rjust ?(pad=' ') ?(trunc=false) str n =
+ else
+ String.copy str
+ end else
+- let newstr = String.make n pad in
++ let newstr = Bytes.make n pad in
+ String.blit str 0 newstr (n - len) len;
+- newstr
++ Bytes.unsafe_to_string newstr
+
+ let subpos str start stop =
+ let len = stop - start + 1 in
+@@ -376,7 +376,7 @@ let repeat str times =
+ for n = 0 to times - 1 do
+ String.unsafe_blit str 0 newstr (n * len) len
+ done;
+- newstr
++ Bytes.unsafe_to_string newstr
+
+ external collate: string -> string -> int = "stew_strcoll"
+
+@@ -463,7 +463,7 @@ let replace str old rep =
+ let of_array arr =
+ let str = String.create (Array.length arr) in
+ Array.iteri (fun i c -> str.[i] <- c) arr;
+- str
++ Bytes.unsafe_to_string str
+
+ let to_array str = Array.init (String.length str) (function i -> str.[i])
+
diff --git a/devel/ocaml-annexlib/files/patch-strExtras.mli b/devel/ocaml-annexlib/files/patch-strExtras.mli
new file mode 100644
index 000000000000..83968c6893f9
--- /dev/null
+++ b/devel/ocaml-annexlib/files/patch-strExtras.mli
@@ -0,0 +1,15 @@
+--- strExtras.mli.orig 2006-02-23 06:34:35 UTC
++++ strExtras.mli
+@@ -105,10 +105,10 @@ type trim_style = [ `Both | `Left | `Right ]
+ val trim: ?style:trim_style -> string -> char -> string
+
+ (** Like [map], but modifies the argument string. *)
+-val map_inplace: (char -> char) -> string -> unit
++val map_inplace: (char -> char) -> bytes -> unit
+
+ (** Like [map_inplace], but passes the index of the character as well. *)
+-val mapi_inplace: (char -> int -> char) -> string -> unit
++val mapi_inplace: (char -> int -> char) -> bytes -> unit
+
+ (** Returns a reversed version of the string *)
+ val rev: string -> string
diff --git a/devel/ocaml-annexlib/files/patch-syslog.ml b/devel/ocaml-annexlib/files/patch-syslog.ml
new file mode 100644
index 000000000000..5b3b57b15b76
--- /dev/null
+++ b/devel/ocaml-annexlib/files/patch-syslog.ml
@@ -0,0 +1,25 @@
+--- syslog.ml.orig 2006-02-23 06:34:35 UTC
++++ syslog.ml
+@@ -142,18 +142,18 @@ let syslog ?fac lev str =
+ let realmsg = ref (Buffer.contents msg) in
+ if String.length !realmsg > 1024 then begin
+ realmsg := String.sub !realmsg 0 1024;
+- String.blit "<truncated>\000" 0 !realmsg 1012 12
++ String.blit "<truncated>\000" 0 (Bytes.unsafe_of_string !realmsg) 1012 12
+ end;
+ begin try
+- ignore (Unix.write loginfo.fd !realmsg 0 (String.length !realmsg))
++ ignore (Unix.write_substring loginfo.fd !realmsg 0 (String.length !realmsg))
+ with
+ | Unix.Unix_error(_,_,_) ->
+ if List.mem `LOG_CONS loginfo.flags then
+ log_console !realmsg
+ end;
+ if List.mem `LOG_PERROR loginfo.flags then begin
+- ignore (Unix.write Unix.stderr !realmsg 0 (String.length !realmsg));
+- ignore (Unix.write Unix.stderr "\n" 0 1)
++ ignore (Unix.write_substring Unix.stderr !realmsg 0 (String.length !realmsg));
++ ignore (Unix.write_substring Unix.stderr "\n" 0 1)
+ end
+
+ let closelog () =
More information about the dev-commits-ports-all
mailing list