diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/printf.ml | 46 | ||||
-rw-r--r-- | stdlib/sys.ml | 2 |
2 files changed, 36 insertions, 12 deletions
diff --git a/stdlib/printf.ml b/stdlib/printf.ml index af54f8cc6..43859d591 100644 --- a/stdlib/printf.ml +++ b/stdlib/printf.ml @@ -210,22 +210,45 @@ let list_iter_i f l = loop 0 l;; (* ``Abstracting'' version of kprintf: returns a (curried) function that - will print when totally applied. *) + will print when totally applied. + Note: in the following, we are careful not to be badly caught + by the compiler optimizations on the representation of arrays. *) let kapr kpr fmt = match nargs_of_format_type fmt with | 0 -> kpr fmt [||] - | 1 -> Obj.magic (fun x -> kpr fmt [|x|]) - | 2 -> Obj.magic (fun x y -> kpr fmt [|x; y|]) - | 3 -> Obj.magic (fun x y z -> kpr fmt [|x; y; z|]) - | 4 -> Obj.magic (fun x y z t -> kpr fmt [|x; y; z; t|]) - | 5 -> Obj.magic (fun x y z t u -> kpr fmt [|x; y; z; t; u|]) - | 6 -> Obj.magic (fun x y z t u v -> kpr fmt [|x; y; z; t; u; v|]) + | 1 -> Obj.magic (fun x -> + let a = Array.make 1 (Obj.repr 0) in + a.(0) <- x; + kpr fmt a) + | 2 -> Obj.magic (fun x y -> + let a = Array.make 2 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; + kpr fmt a) + | 3 -> Obj.magic (fun x y z -> + let a = Array.make 3 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + kpr fmt a) + | 4 -> Obj.magic (fun x y z t -> + let a = Array.make 4 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + a.(3) <- t; + kpr fmt a) + | 5 -> Obj.magic (fun x y z t u -> + let a = Array.make 5 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + a.(3) <- t; a.(4) <- u; + kpr fmt a) + | 6 -> Obj.magic (fun x y z t u v -> + let a = Array.make 6 (Obj.repr 0) in + a.(0) <- x; a.(1) <- y; a.(2) <- z; + a.(3) <- t; a.(4) <- u; a.(5) <- v; + kpr fmt a) | nargs -> let rec loop i args = if i >= nargs then - let v = Array.make nargs (Obj.repr 0) in - list_iter_i (fun i arg -> v.(nargs - i - 1) <- arg) args; - kpr fmt v + let a = Array.make nargs (Obj.repr 0) in + list_iter_i (fun i arg -> a.(nargs - i - 1) <- arg) args; + kpr fmt a else Obj.magic (fun x -> loop (succ i) (x :: args)) in loop 0 [];; @@ -288,7 +311,8 @@ let scan_format fmt args n pos cont_s cont_a cont_t cont_f cont_m = scan_flags n (width :: widths) i | _, _ -> assert false in scan_positional_spec fmt got_positional n (succ i) - | '0'..'9' | '.' | '#' | '-' | ' ' | '+' -> scan_flags n widths (succ i) + | '0'..'9' + | '.' | '#' | '-' | ' ' | '+' -> scan_flags n widths (succ i) | _ -> scan_conv n widths i and scan_conv n widths i = diff --git a/stdlib/sys.ml b/stdlib/sys.ml index 4bed116e7..6492c68bc 100644 --- a/stdlib/sys.ml +++ b/stdlib/sys.ml @@ -78,4 +78,4 @@ let catch_break on = (* OCaml version string, must be in the format described in sys.mli. *) -let ocaml_version = "3.09+dev34 (2005-09-26)";; +let ocaml_version = "3.09+dev35 (2005-09-30)";; |