diff --git a/fuzz/fuzz.ml b/fuzz/fuzz.ml index 75d2cfd..4eca505 100644 --- a/fuzz/fuzz.ml +++ b/fuzz/fuzz.ml @@ -83,10 +83,10 @@ let () = ); add_test ~name:"shiftv" [list cstruct; int] (fun ts n -> match Cstruct.shiftv ts n with - | exception Invalid_argument _ -> check (n < 0 || n > Cstruct.lenv ts) + | exception Invalid_argument _ -> check (n < 0 || n > Cstruct.lengthv ts) | ts' -> assert (Cstruct.equal (Cstruct.concat ts') (Cstruct.shift (Cstruct.concat ts) n)); - assert ((Cstruct.lenv ts = n) = (ts' = [])); + assert ((Cstruct.lengthv ts = n) = (ts' = [])); match ts' with | hd :: _ -> assert (not (Cstruct.is_empty hd)) | [] -> () @@ -142,21 +142,21 @@ let () = | () -> check in_range | exception Invalid_argument _ -> check (not in_range) ); - add_test ~name:"lenv" [list cstruct] (fun cs -> - check (Cstruct.lenv cs >= 0) + add_test ~name:"lengthv" [list cstruct] (fun cs -> + check (Cstruct.lengthv cs >= 0) ); add_test ~name:"copyv" [list cstruct] (fun cs -> check (String.equal (Cstruct.copyv cs) (Cstruct.concat cs |> Cstruct.to_string)) ); add_test ~name:"fillv" [list cstruct; cstruct] (fun src dst -> let copied, rest = Cstruct.fillv ~src ~dst in - check (copied + Cstruct.lenv rest = Cstruct.lenv src); + check (copied + Cstruct.lengthv rest = Cstruct.lengthv src); (* OCaml tends to underestimate how much space bigarrays are using: *) Gc.minor () ); add_test ~name:"concat" [list cstruct] (fun cs -> let x = Cstruct.concat cs in - check (Cstruct.length x = Cstruct.lenv cs) + check (Cstruct.length x = Cstruct.lengthv cs) ); add_test ~name:"span" [ cstruct; list char ] (fun cs p -> let sat chr = List.exists ((=) chr) p in diff --git a/lib/cstruct.ml b/lib/cstruct.ml index 5c4b871..903bac4 100644 --- a/lib/cstruct.ml +++ b/lib/cstruct.ml @@ -369,6 +369,7 @@ let rec sum_lengths_aux ~caller acc = function let sum_lengths ~caller l = sum_lengths_aux ~caller 0 l let lenv l = sum_lengths ~caller:"Cstruct.lenv" l +let lengthv l = sum_lengths ~caller:"Cstruct.lengthv" l let copyv ts = let sz = sum_lengths ~caller:"Cstruct.copyv" ts in diff --git a/lib/cstruct.mli b/lib/cstruct.mli index fd5b081..04e8114 100644 --- a/lib/cstruct.mli +++ b/lib/cstruct.mli @@ -504,10 +504,14 @@ val debug: t -> string (** {2 List of buffers} *) -val lenv: t list -> int -(** [lenv cstrs] is the combined length of all cstructs in [cstrs]. +val lengthv: t list -> int +(** [lengthv cstrs] is the combined length of all cstructs in [cstrs]. @raise Invalid_argument if computing the sum overflows. *) +val lenv : t list -> int +[@@ocaml.alert deprecated "use lengthv instead"] +(** [lenv] is deprecated in favor of [lengthv]. *) + val copyv: t list -> string (** [copyv cstrs] is the string representation of the concatenation of all cstructs in [cstrs]. @@ -524,7 +528,7 @@ val shiftv: t list -> int -> t list It has the property that [equal (concat (shiftv ts n)) (shift (concat ts) n)]. This operation is fairly fast, as it will share the tail of the list. The first item in the returned list is never an empty cstruct, - so you'll get [[]] if and only if [lenv ts = n]. *) + so you'll get [[]] if and only if [lengthv ts = n]. *) (** {2 Iterations} *) diff --git a/lib/cstruct_cap.mli b/lib/cstruct_cap.mli index cc73438..7c93097 100644 --- a/lib/cstruct_cap.mli +++ b/lib/cstruct_cap.mli @@ -114,11 +114,15 @@ val check_alignment : 'a t -> int -> bool @raise Invalid_argument if [alignment] is not a positive integer. *) -val lenv : 'a t list -> int -(** [lenv vs] is the combined length of all {!t} in [vs]. +val lengthv : 'a t list -> int +(** [lengthv vs] is the combined length of all {!t} in [vs]. @raise Invalid_argument if computing the sum overflows. *) +val lenv : 'a t list -> int +[@@ocaml.alert deprecated "use lengthv instead"] +(** [lenv] is deprecated in favor of [lengthv]. *) + (** {2 Constructors} *) val create : int -> rdwr t @@ -166,7 +170,7 @@ val shiftv: 'a t list -> int -> 'a t list It has the property that [equal (concat (shiftv ts n)) (shift (concat ts) n)]. This operation is fairly fast, as it will share the tail of the list. The first item in the returned list is never an empty cstruct, - so you'll get [[]] if and only if [lenv ts = n]. *) + so you'll get [[]] if and only if [lengthv ts = n]. *) val split : ?start:int -> 'a t -> int -> 'a t * 'a t (** [split ~start t len] returns two proxies extracted from [t]. The first @@ -190,7 +194,7 @@ val append : 'a rd t -> 'b rd t -> rdwr t the returned value has both read and write capabilities. *) val concat : 'a rd t list -> rdwr t -(** [concat vss] allocates a buffer [r] of size [lenv vss]. Each [v] of [vss] +(** [concat vss] allocates a buffer [r] of size [lengthv vss]. Each [v] of [vss] is copied into the buffer [r]. Each [v] of [vss] need at least read capability {!rd}, the returned value has both read and write capabilities. *) diff --git a/lib_test/bounds.ml b/lib_test/bounds.ml index 71cbb3b..8c3e545 100644 --- a/lib_test/bounds.ml +++ b/lib_test/bounds.ml @@ -347,14 +347,14 @@ let test_view_bounds_too_small_get_he64 () = with Invalid_argument _ -> () -let test_lenv_overflow () = +let test_lengthv_overflow () = if Sys.word_size = 32 then ( (* free-up some space *) Gc.major (); let b = Cstruct.create max_int and c = Cstruct.create 3 in try - let _ = Cstruct.lenv [b; b; c] in - failwith "test_lenv_overflow" + let _ = Cstruct.lengthv [b; b; c] in + failwith "test_lengthv_overflow" with Invalid_argument _ -> ()) @@ -494,7 +494,7 @@ let suite = [ "test_view_bounds_too_small_get_he16" , `Quick, test_view_bounds_too_small_get_he16; "test_view_bounds_too_small_get_he32" , `Quick, test_view_bounds_too_small_get_he32; "test_view_bounds_too_small_get_he64" , `Quick, test_view_bounds_too_small_get_he64; - "test_lenv_overflow", `Quick, test_lenv_overflow; + "test_lengthv_overflow", `Quick, test_lengthv_overflow; "test_copyv_overflow", `Quick, test_copyv_overflow; "test_subview_containment_get_char", `Quick, test_subview_containment_get_char; "test_subview_containment_get_8" , `Quick, test_subview_containment_get_8; diff --git a/lib_test/tests.ml b/lib_test/tests.ml index be57b9b..f0cd723 100644 --- a/lib_test/tests.ml +++ b/lib_test/tests.ml @@ -88,7 +88,7 @@ let append_is_concat ~n () = let fillv () = let test src buf_size = let dst = Cstruct.create buf_size in - let src_len = Cstruct.lenv src in + let src_len = Cstruct.lengthv src in let len, remaining = Cstruct.fillv ~src ~dst in assert (len = min src_len buf_size); let whole = Cstruct.concat (Cstruct.sub dst 0 len :: remaining) in