Permalink
Browse files

Safer fix for Pretty module

Thanks to Xavier Leroy.
  • Loading branch information...
1 parent 6b3638f commit 681f17e618282436b8168278af4464036623aaf1 @kerneis kerneis committed Jul 1, 2014
Showing with 7 additions and 16 deletions.
  1. +2 −9 src/ocamlutil/pretty.ml
  2. +5 −3 src/ocamlutil/util.ml
  3. +0 −4 src/ocamlutil/util.mli
@@ -636,18 +636,11 @@ let sprint ~(width : int) doc : string =
external format_int: string -> int -> string = "caml_format_int"
external format_float: string -> float -> string = "caml_format_float"
-(* Internal representation of format has changed in 4.02. It used to be
- * the raw format string, but it is now a pair, the second member of
- * which is the format string *)
-let unsafe_format_to_string (fmt : ('a,'b,'c,'d) format4) : string =
- match Util.ocaml_major_version, Util.ocaml_minor_version with
- | (maj, min) when maj < 4 || (maj = 4 && min < 2) -> Obj.magic fmt
- | _ -> Obj.obj (Obj.field (Obj.repr fmt) 1)
+
let gprintf (finish : doc -> 'b)
(format : ('a, unit, doc, 'b) format4) : 'a =
-
- let (format:string) = unsafe_format_to_string format in
+ let format = string_of_format format in
(* Record the starting align depth *)
let startAlignDepth = !alignDepth in
@@ -1,3 +1,8 @@
+(** Utility functions for Coolaid *)
+module E = Errormsg
+module H = Hashtbl
+module IH = Inthash
+
(* tail-recursive append: reverses xs twice *)
let list_append (xs: 'a list) (ys: 'a list): 'a list =
match xs with (* optimize some common cases *)
@@ -55,6 +60,3 @@ let list_map_opt f = function
let equals x1 x2 : bool =
(compare x1 x2) = 0
-
-let (ocaml_major_version,ocaml_minor_version) =
- Scanf.sscanf Sys.ocaml_version "%d.%d" (fun x y -> (x,y))
@@ -20,7 +20,3 @@ val list_map_opt : ('a -> 'b) -> 'a list option -> 'b list option
name or id in some field that occurs before any fields that have cyclic
pointers. *)
val equals: 'a -> 'a -> bool
-
-(** Convenient access to components of Sys.ocaml_version. *)
-val ocaml_major_version: int
-val ocaml_minor_version: int

0 comments on commit 681f17e

Please sign in to comment.