Protocol environment: remove unsafe functions that have a safe(r) equivalent
This commit is contained in:
parent
e498a15a1a
commit
105d8e3833
@ -56,12 +56,6 @@ val tl : 'a list -> 'a list
|
|||||||
(** Return the given list without its first element. Raise
|
(** Return the given list without its first element. Raise
|
||||||
[Failure "tl"] if the list is empty. *)
|
[Failure "tl"] if the list is empty. *)
|
||||||
|
|
||||||
val nth : 'a list -> int -> 'a
|
|
||||||
(** Return the [n]-th element of the given list.
|
|
||||||
The first element (head of the list) is at position 0.
|
|
||||||
Raise [Failure "nth"] if the list is too short.
|
|
||||||
Raise [Invalid_argument "List.nth"] if [n] is negative. *)
|
|
||||||
|
|
||||||
val nth_opt : 'a list -> int -> 'a option
|
val nth_opt : 'a list -> int -> 'a option
|
||||||
(** Return the [n]-th element of the given list.
|
(** Return the [n]-th element of the given list.
|
||||||
The first element (head of the list) is at position 0.
|
The first element (head of the list) is at position 0.
|
||||||
@ -208,12 +202,6 @@ val memq : 'a -> 'a list -> bool
|
|||||||
(** {1 List searching} *)
|
(** {1 List searching} *)
|
||||||
|
|
||||||
|
|
||||||
val find : ('a -> bool) -> 'a list -> 'a
|
|
||||||
(** [find p l] returns the first element of the list [l]
|
|
||||||
that satisfies the predicate [p].
|
|
||||||
Raise [Not_found] if there is no value that satisfies [p] in the
|
|
||||||
list [l]. *)
|
|
||||||
|
|
||||||
val find_opt: ('a -> bool) -> 'a list -> 'a option
|
val find_opt: ('a -> bool) -> 'a list -> 'a option
|
||||||
(** [find_opt p l] returns the first element of the list [l] that
|
(** [find_opt p l] returns the first element of the list [l] that
|
||||||
satisfies the predicate [p], or [None] if there is no value that
|
satisfies the predicate [p], or [None] if there is no value that
|
||||||
@ -239,14 +227,6 @@ val partition : ('a -> bool) -> 'a list -> 'a list * 'a list
|
|||||||
(** {1 Association lists} *)
|
(** {1 Association lists} *)
|
||||||
|
|
||||||
|
|
||||||
val assoc : 'a -> ('a * 'b) list -> 'b
|
|
||||||
(** [assoc a l] returns the value associated with key [a] in the list of
|
|
||||||
pairs [l]. That is,
|
|
||||||
[assoc a [ ...; (a,b); ...] = b]
|
|
||||||
if [(a,b)] is the leftmost binding of [a] in list [l].
|
|
||||||
Raise [Not_found] if there is no value associated with [a] in the
|
|
||||||
list [l]. *)
|
|
||||||
|
|
||||||
val assoc_opt: 'a -> ('a * 'b) list -> 'b option
|
val assoc_opt: 'a -> ('a * 'b) list -> 'b option
|
||||||
(** [assoc_opt a l] returns the value associated with key [a] in the list of
|
(** [assoc_opt a l] returns the value associated with key [a] in the list of
|
||||||
pairs [l]. That is,
|
pairs [l]. That is,
|
||||||
@ -256,10 +236,6 @@ val assoc_opt: 'a -> ('a * 'b) list -> 'b option
|
|||||||
list [l].
|
list [l].
|
||||||
@since 4.05 *)
|
@since 4.05 *)
|
||||||
|
|
||||||
val assq : 'a -> ('a * 'b) list -> 'b
|
|
||||||
(** Same as {!List.assoc}, but uses physical equality instead of structural
|
|
||||||
equality to compare keys. *)
|
|
||||||
|
|
||||||
val assq_opt : 'a -> ('a * 'b) list -> 'b option
|
val assq_opt : 'a -> ('a * 'b) list -> 'b option
|
||||||
(** Same as {!List.assoc_opt}, but uses physical equality instead of structural
|
(** Same as {!List.assoc_opt}, but uses physical equality instead of structural
|
||||||
equality to compare keys.
|
equality to compare keys.
|
||||||
|
@ -300,11 +300,6 @@ val string_of_bool : bool -> string
|
|||||||
may be shared, the user should not modify them directly.
|
may be shared, the user should not modify them directly.
|
||||||
*)
|
*)
|
||||||
|
|
||||||
val bool_of_string : string -> bool
|
|
||||||
(** Convert the given string to a boolean.
|
|
||||||
Raise [Invalid_argument "bool_of_string"] if the string is not
|
|
||||||
["true"] or ["false"]. *)
|
|
||||||
|
|
||||||
val bool_of_string_opt: string -> bool option
|
val bool_of_string_opt: string -> bool option
|
||||||
(** Convert the given string to a boolean.
|
(** Convert the given string to a boolean.
|
||||||
Return [None] if the string is not
|
Return [None] if the string is not
|
||||||
@ -315,7 +310,7 @@ val bool_of_string_opt: string -> bool option
|
|||||||
val string_of_int : int -> string
|
val string_of_int : int -> string
|
||||||
(** Return the string representation of an integer, in decimal. *)
|
(** Return the string representation of an integer, in decimal. *)
|
||||||
|
|
||||||
external int_of_string : string -> int = "caml_int_of_string"
|
val int_of_string_opt: string -> int option
|
||||||
(** Convert the given string to an integer.
|
(** Convert the given string to an integer.
|
||||||
The string is read in decimal (by default, or if the string
|
The string is read in decimal (by default, or if the string
|
||||||
begins with [0u]), in hexadecimal (if it begins with [0x] or
|
begins with [0u]), in hexadecimal (if it begins with [0x] or
|
||||||
@ -329,13 +324,10 @@ external int_of_string : string -> int = "caml_int_of_string"
|
|||||||
|
|
||||||
The [_] (underscore) character can appear anywhere in the string
|
The [_] (underscore) character can appear anywhere in the string
|
||||||
and is ignored.
|
and is ignored.
|
||||||
Raise [Failure "int_of_string"] if the given string is not
|
|
||||||
a valid representation of an integer, or if the integer represented
|
|
||||||
exceeds the range of integers representable in type [int]. *)
|
|
||||||
|
|
||||||
|
Return [None] if the given string is not a valid representation of
|
||||||
val int_of_string_opt: string -> int option
|
an integer, or if the integer represented exceeds the range of
|
||||||
(** Same as [int_of_string], but returns [None] instead of raising.
|
integers representable in type [int].
|
||||||
@since 4.05
|
@since 4.05
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
@ -149,38 +149,18 @@ val escaped : string -> string
|
|||||||
i.e. [Scanf.unescaped (escaped s) = s] for any string [s] (unless
|
i.e. [Scanf.unescaped (escaped s) = s] for any string [s] (unless
|
||||||
[escape s] fails). *)
|
[escape s] fails). *)
|
||||||
|
|
||||||
val index : string -> char -> int
|
|
||||||
(** [String.index s c] returns the index of the first
|
|
||||||
occurrence of character [c] in string [s].
|
|
||||||
|
|
||||||
Raise [Not_found] if [c] does not occur in [s]. *)
|
|
||||||
|
|
||||||
val index_opt: string -> char -> int option
|
val index_opt: string -> char -> int option
|
||||||
(** [String.index_opt s c] returns the index of the first
|
(** [String.index_opt s c] returns the index of the first
|
||||||
occurrence of character [c] in string [s], or
|
occurrence of character [c] in string [s], or
|
||||||
[None] if [c] does not occur in [s].
|
[None] if [c] does not occur in [s].
|
||||||
@since 4.05 *)
|
@since 4.05 *)
|
||||||
|
|
||||||
val rindex : string -> char -> int
|
|
||||||
(** [String.rindex s c] returns the index of the last
|
|
||||||
occurrence of character [c] in string [s].
|
|
||||||
|
|
||||||
Raise [Not_found] if [c] does not occur in [s]. *)
|
|
||||||
|
|
||||||
val rindex_opt: string -> char -> int option
|
val rindex_opt: string -> char -> int option
|
||||||
(** [String.rindex_opt s c] returns the index of the last occurrence
|
(** [String.rindex_opt s c] returns the index of the last occurrence
|
||||||
of character [c] in string [s], or [None] if [c] does not occur in
|
of character [c] in string [s], or [None] if [c] does not occur in
|
||||||
[s].
|
[s].
|
||||||
@since 4.05 *)
|
@since 4.05 *)
|
||||||
|
|
||||||
val index_from : string -> int -> char -> int
|
|
||||||
(** [String.index_from s i c] returns the index of the
|
|
||||||
first occurrence of character [c] in string [s] after position [i].
|
|
||||||
[String.index s c] is equivalent to [String.index_from s 0 c].
|
|
||||||
|
|
||||||
Raise [Invalid_argument] if [i] is not a valid position in [s].
|
|
||||||
Raise [Not_found] if [c] does not occur in [s] after position [i]. *)
|
|
||||||
|
|
||||||
val index_from_opt: string -> int -> char -> int option
|
val index_from_opt: string -> int -> char -> int option
|
||||||
(** [String.index_from_opt s i c] returns the index of the
|
(** [String.index_from_opt s i c] returns the index of the
|
||||||
first occurrence of character [c] in string [s] after position [i]
|
first occurrence of character [c] in string [s] after position [i]
|
||||||
@ -192,15 +172,6 @@ val index_from_opt: string -> int -> char -> int option
|
|||||||
@since 4.05
|
@since 4.05
|
||||||
*)
|
*)
|
||||||
|
|
||||||
val rindex_from : string -> int -> char -> int
|
|
||||||
(** [String.rindex_from s i c] returns the index of the
|
|
||||||
last occurrence of character [c] in string [s] before position [i+1].
|
|
||||||
[String.rindex s c] is equivalent to
|
|
||||||
[String.rindex_from s (String.length s - 1) c].
|
|
||||||
|
|
||||||
Raise [Invalid_argument] if [i+1] is not a valid position in [s].
|
|
||||||
Raise [Not_found] if [c] does not occur in [s] before position [i+1]. *)
|
|
||||||
|
|
||||||
val rindex_from_opt: string -> int -> char -> int option
|
val rindex_from_opt: string -> int -> char -> int option
|
||||||
(** [String.rindex_from_opt s i c] returns the index of the
|
(** [String.rindex_from_opt s i c] returns the index of the
|
||||||
last occurrence of character [c] in string [s] before position [i+1]
|
last occurrence of character [c] in string [s] before position [i+1]
|
||||||
|
@ -308,16 +308,18 @@ let parse_var_annot
|
|||||||
let split_last_dot = function
|
let split_last_dot = function
|
||||||
| None -> None, None
|
| None -> None, None
|
||||||
| Some `Field_annot s ->
|
| Some `Field_annot s ->
|
||||||
try
|
match String.rindex_opt s '.' with
|
||||||
let i = String.rindex s '.' in
|
| None -> None, Some (`Field_annot s)
|
||||||
let s1 = String.sub s 0 i in
|
| Some i ->
|
||||||
let s2 = String.sub s (i + 1) (String.length s - i - 1) in
|
let s1 = String.sub s 0 i in
|
||||||
let f =
|
let s2 = String.sub s (i + 1) (String.length s - i - 1) in
|
||||||
if Compare.String.equal s2 "car" || Compare.String.equal s2 "cdr"
|
let f =
|
||||||
then None
|
if Compare.String.equal s2 "car"
|
||||||
else Some (`Field_annot s2) in
|
|| Compare.String.equal s2 "cdr" then
|
||||||
Some (`Var_annot s1), f
|
None
|
||||||
with Not_found -> None, Some (`Field_annot s)
|
else
|
||||||
|
Some (`Field_annot s2) in
|
||||||
|
Some (`Var_annot s1), f
|
||||||
|
|
||||||
let common_prefix v1 v2 =
|
let common_prefix v1 v2 =
|
||||||
match v1, v2 with
|
match v1, v2 with
|
||||||
|
@ -30,9 +30,7 @@ module Int_index = struct
|
|||||||
let to_path c l = string_of_int c :: l
|
let to_path c l = string_of_int c :: l
|
||||||
let of_path = function
|
let of_path = function
|
||||||
| [] | _ :: _ :: _ -> None
|
| [] | _ :: _ :: _ -> None
|
||||||
| [ c ] ->
|
| [ c ] -> int_of_string_opt c
|
||||||
try Some (int_of_string c)
|
|
||||||
with _ -> None
|
|
||||||
type 'a ipath = 'a * t
|
type 'a ipath = 'a * t
|
||||||
let args = Storage_description.One {
|
let args = Storage_description.One {
|
||||||
rpc_arg = RPC_arg.int ;
|
rpc_arg = RPC_arg.int ;
|
||||||
@ -330,12 +328,10 @@ module Roll = struct
|
|||||||
match Misc.take Cycle_repr.Index.path_length l with
|
match Misc.take Cycle_repr.Index.path_length l with
|
||||||
| None | Some (_, ([] | _ :: _ :: _ ))-> None
|
| None | Some (_, ([] | _ :: _ :: _ ))-> None
|
||||||
| Some (l1, [l2]) ->
|
| Some (l1, [l2]) ->
|
||||||
match Cycle_repr.Index.of_path l1 with
|
match Cycle_repr.Index.of_path l1, int_of_string_opt l2 with
|
||||||
| None -> None
|
| None, _ | _, None -> None
|
||||||
| Some c -> begin
|
| Some c, Some i -> Some (c, i)
|
||||||
try Some (c, int_of_string l2)
|
|
||||||
with _ -> None
|
|
||||||
end
|
|
||||||
type 'a ipath = ('a * Cycle_repr.t) * int
|
type 'a ipath = ('a * Cycle_repr.t) * int
|
||||||
let left_args =
|
let left_args =
|
||||||
Storage_description.One {
|
Storage_description.One {
|
||||||
|
Loading…
Reference in New Issue
Block a user