From c44e6f999a4b06a4b0e961e8607ab8c557501a57 Mon Sep 17 00:00:00 2001 From: Damien Doligez Date: Thu, 11 Sep 1997 15:10:23 +0000 Subject: [PATCH] arg.ml, arg.mli, string.mli: amelioration de la doc array.mli, array.ml, random.ml: create -> make (coherence avec String) sys.ml, sys.mli: ajout max_string_length, max_array_length git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1706 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- stdlib/.depend | 4 ++-- stdlib/arg.ml | 2 +- stdlib/arg.mli | 2 +- stdlib/array.ml | 5 ++++- stdlib/array.mli | 6 ++++-- stdlib/random.ml | 2 +- stdlib/string.mli | 14 +++++++------- stdlib/sys.ml | 2 ++ stdlib/sys.mli | 4 ++++ 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/stdlib/.depend b/stdlib/.depend index 4619dc539..8bc43feca 100644 --- a/stdlib/.depend +++ b/stdlib/.depend @@ -12,8 +12,8 @@ digest.cmo: string.cmi digest.cmi digest.cmx: string.cmx digest.cmi filename.cmo: string.cmi sys.cmi filename.cmi filename.cmx: string.cmx sys.cmx filename.cmi -format.cmo: string.cmi format.cmi -format.cmx: string.cmx format.cmi +format.cmo: obj.cmi string.cmi format.cmi +format.cmx: obj.cmx string.cmx format.cmi gc.cmo: printf.cmi gc.cmi gc.cmx: printf.cmx gc.cmi genlex.cmo: char.cmi hashtbl.cmi list.cmi stream.cmi string.cmi genlex.cmi diff --git a/stdlib/arg.ml b/stdlib/arg.ml index c6cb42ed3..8bbb56ffd 100644 --- a/stdlib/arg.ml +++ b/stdlib/arg.ml @@ -12,7 +12,7 @@ (* $Id$ *) type spec = - | Unit of (unit -> unit) (* Call the function with no argument *) + | Unit of (unit -> unit) (* Call the function with unit argument *) | Set of bool ref (* Set the reference to true *) | Clear of bool ref (* Set the reference to false *) | String of (string -> unit) (* Call the function with a string argument *) diff --git a/stdlib/arg.mli b/stdlib/arg.mli index f09a7790d..599524ad6 100644 --- a/stdlib/arg.mli +++ b/stdlib/arg.mli @@ -36,7 +36,7 @@ *) type spec = - | Unit of (unit -> unit) (* Call the function with no argument *) + | Unit of (unit -> unit) (* Call the function with unit argument *) | Set of bool ref (* Set the reference to true *) | Clear of bool ref (* Set the reference to false *) | String of (string -> unit) (* Call the function with a string argument *) diff --git a/stdlib/array.ml b/stdlib/array.ml index 901004de9..7a103f4ea 100644 --- a/stdlib/array.ml +++ b/stdlib/array.ml @@ -18,15 +18,18 @@ external get: 'a array -> int -> 'a = "%array_safe_get" external set: 'a array -> int -> 'a -> unit = "%array_safe_set" external unsafe_get: 'a array -> int -> 'a = "%array_unsafe_get" external unsafe_set: 'a array -> int -> 'a -> unit = "%array_unsafe_set" +external make: int -> 'a -> 'a array = "make_vect" external create: int -> 'a -> 'a array = "make_vect" -let create_matrix sx sy init = +let make_matrix sx sy init = let res = create sx [||] in for x = 0 to pred sx do unsafe_set res x (create sy init) done; res +let create_matrix = make_matrix + let copy a = let l = length a in if l = 0 then [||] else begin diff --git a/stdlib/array.mli b/stdlib/array.mli index 343565f5a..3815161f7 100644 --- a/stdlib/array.mli +++ b/stdlib/array.mli @@ -28,16 +28,18 @@ external set: 'a array -> int -> 'a -> unit = "%array_safe_set" Raise [Invalid_argument "Array.set"] if [n] is outside the range 0 to [Array.length a - 1]. You can also write [a.(n) <- x] instead of [Array.set a n x]. *) +external make: int -> 'a -> 'a array = "make_vect" external create: int -> 'a -> 'a array = "make_vect" - (* [Array.create n x] returns a fresh array of length [n], + (* [Array.make n x] returns a fresh array of length [n], initialized with [x]. All the elements of this new array are initially physically equal to [x] (in the sense of the [==] predicate). Consequently, if [x] is mutable, it is shared among all elements of the array, and modifying [x] through one of the array entries will modify all other entries at the same time. *) +val make_matrix: int -> int -> 'a -> 'a array array val create_matrix: int -> int -> 'a -> 'a array array - (* [Array.create_matrix dimx dimy e] returns a two-dimensional array + (* [Array.make_matrix dimx dimy e] returns a two-dimensional array (an array of arrays) with first dimension [dimx] and second dimension [dimy]. All the elements of this new matrix are initially physically equal to [e]. diff --git a/stdlib/random.ml b/stdlib/random.ml index 57b687b3d..33851b9b1 100644 --- a/stdlib/random.ml +++ b/stdlib/random.ml @@ -133,7 +133,7 @@ let rec sumsq v i0 i1 = let chisquare g n r = if n <= 10 * r then invalid_arg "chisquare"; - let f = Array.create r 0 in + let f = Array.make r 0 in for i = 1 to n do let t = g r in f.(t) <- f.(t) + 1 diff --git a/stdlib/string.mli b/stdlib/string.mli index 4ac2bca81..d12b52180 100644 --- a/stdlib/string.mli +++ b/stdlib/string.mli @@ -52,14 +52,14 @@ val fill : string -> int -> int -> char -> unit Raise [Invalid_argument] if [start] and [len] do not designate a valid substring of [s]. *) val blit : string -> int -> string -> int -> int -> unit - (* [String.blit s1 o1 s2 o2 len] copies [len] characters - from string [s1], starting at character number [o1], to string [s2], - starting at character number [o2]. It works correctly even if - [s1] and [s2] are the same string, + (* [String.blit src srcoff dst dstoff len] copies [len] characters + from string [src], starting at character number [srcoff], to + string [dst], starting at character number [dstoff]. It works + correctly even if [src] and [dst] are the same string, and the source and destination chunks overlap. - Raise [Invalid_argument] if [o1] and [len] do not - designate a valid substring of [s1], or if [o2] and [len] do not - designate a valid substring of [s2]. *) + Raise [Invalid_argument] if [srcoff] and [len] do not + designate a valid substring of [src], or if [dstoff] and [len] + do not designate a valid substring of [dst]. *) val concat : string -> string list -> string (* [String.concat sep sl] catenates the list of strings [sl], diff --git a/stdlib/sys.ml b/stdlib/sys.ml index 0a117bc40..475bacadb 100644 --- a/stdlib/sys.ml +++ b/stdlib/sys.ml @@ -18,6 +18,8 @@ external get_argv: unit -> string array = "sys_get_argv" let argv = get_argv() let (os_type, word_size) = get_config() +let max_array_length = (1 lsl (word_size - 10)) - 1;; +let max_string_length = word_size / 8 * max_array_length - 1;; external file_exists: string -> bool = "sys_file_exists" external remove: string -> unit = "sys_remove" diff --git a/stdlib/sys.mli b/stdlib/sys.mli index e10319ba8..9e081a684 100644 --- a/stdlib/sys.mli +++ b/stdlib/sys.mli @@ -43,6 +43,10 @@ val os_type: string val word_size: int (* Size of one word on the machine currently executing the Caml program, in bits: 32 or 64. *) +val max_string_length: int + (* Maximum length of a string. *) +val max_array_length: int + (* Maximum length of an array. *) (*** Signal handling *)