From 9d9f7096008b2d6998644d7930ca7a642c3167c1 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 22 Apr 2016 14:22:15 +0200 Subject: [PATCH] bugfix in `CCFormat.to_file` (fd was closed too early) --- src/core/CCFormat.ml | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index 01a1fdcd..c7b82288 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -130,22 +130,12 @@ let fprintf = Format.fprintf let stdout = Format.std_formatter let stderr = Format.err_formatter -let _with_file_out filename f = +let to_file filename format = let oc = open_out filename in let fmt = Format.formatter_of_out_channel oc in - begin try - let x = f fmt in - Format.pp_print_flush fmt (); - close_out oc; - x - with e -> - Format.pp_print_flush fmt (); - close_out_noerr oc; - raise e - end - -let to_file filename format = - _with_file_out filename (fun fmt -> Format.fprintf fmt format) + Format.kfprintf + (fun fmt -> Format.pp_print_flush fmt (); close_out_noerr oc) + fmt format type color = [ `Black