[Unison-hackers] [unison-svn] r502 - trunk/src

vouillon at seas.upenn.edu vouillon at seas.upenn.edu
Tue Aug 7 14:44:28 EDT 2012


Author: vouillon
Date: 2012-08-07 14:44:28 -0400 (Tue, 07 Aug 2012)
New Revision: 502

Modified:
   trunk/src/RECENTNEWS
   trunk/src/external.ml
   trunk/src/mkProjectInfo.ml
Log:
* Function External.readChannelTillEof now tail recursive
  (prevents a crash when the output of the diff program is too large)


Modified: trunk/src/RECENTNEWS
===================================================================
--- trunk/src/RECENTNEWS	2012-08-07 16:57:51 UTC (rev 501)
+++ trunk/src/RECENTNEWS	2012-08-07 18:44:28 UTC (rev 502)
@@ -1,3 +1,9 @@
+CHANGES FROM VERSION 2.45.14
+
+* Function External.readChannelTillEof now tail recursive
+  (prevents a crash when the output of the diff program is too large)
+
+-------------------------------
 CHANGES FROM VERSION 2.45.13
 
 * Fixed Makefile for cross-compiling towards Windows (updated to MinGW-w64)

Modified: trunk/src/external.ml
===================================================================
--- trunk/src/external.ml	2012-08-07 16:57:51 UTC (rev 501)
+++ trunk/src/external.ml	2012-08-07 18:44:28 UTC (rev 502)
@@ -26,35 +26,30 @@
 open Lwt
 
 let readChannelTillEof c =
-  let rec loop lines =
-    try let l = input_line c in
-        (* Util.msg "%s\n" l; *)
-        loop (l::lines)
-    with End_of_file -> lines in
-  String.concat "\n" (Safelist.rev (loop []))
+  let lst = ref [] in
+  let rec loop () =
+    lst := input_line c :: !lst;
+    loop ()
+  in
+  begin try loop () with End_of_file -> () end;
+  String.concat "\n" (Safelist.rev !lst)
 
 let readChannelTillEof_lwt c =
   let rec loop lines =
-    let lo =
-      try
-        Some(Lwt_unix.run (Lwt_unix.input_line c))
-      with End_of_file -> None
-    in
-    match lo with
-      Some l -> loop (l :: lines)
-    | None   -> lines
+    Lwt.try_bind
+      (fun () -> Lwt_unix.input_line c)
+      (fun l  -> loop (l :: lines))
+      (fun e  -> if e = End_of_file then Lwt.return lines else Lwt.fail e)
   in
-  String.concat "\n" (Safelist.rev (loop []))
+  String.concat "\n" (Safelist.rev (Lwt_unix.run (loop [])))
 
 let readChannelsTillEof l =
   let rec suckitdry lines c =
-    Lwt.catch
-      (fun() -> Lwt_unix.input_line c >>= (fun l -> return (Some l)))
-      (fun e -> match e with End_of_file -> return None | _ -> raise e)
-    >>= (fun lo ->
-           match lo with
-             None -> return lines
-           | Some l -> suckitdry (l :: lines) c) in
+    Lwt.try_bind
+      (fun () -> Lwt_unix.input_line c)
+      (fun l -> suckitdry (l :: lines) c)
+      (fun e -> match e with End_of_file -> Lwt.return lines | _ -> raise e)
+  in
   Lwt_util.map
     (fun c ->
        suckitdry [] c

Modified: trunk/src/mkProjectInfo.ml
===================================================================
--- trunk/src/mkProjectInfo.ml	2012-08-07 16:57:51 UTC (rev 501)
+++ trunk/src/mkProjectInfo.ml	2012-08-07 18:44:28 UTC (rev 502)
@@ -76,3 +76,4 @@
 
 
 
+



More information about the Unison-hackers mailing list