[Unison-hackers] [unison-svn] r397 - in trunk/src: . uimacnew uimacnew09

vouillon@seas.upenn.edu vouillon at seas.upenn.edu
Fri Jan 8 05:51:57 EST 2010


Author: vouillon
Date: 2010-01-08 05:51:56 -0500 (Fri, 08 Jan 2010)
New Revision: 397

Modified:
   trunk/src/RECENTNEWS
   trunk/src/mkProjectInfo.ml
   trunk/src/uimacbridgenew.ml
   trunk/src/uimacnew/MyController.m
   trunk/src/uimacnew09/MyController.m
Log:
* MacOS GUI:
  - improved exception handling (untested code, might not even compile)


Modified: trunk/src/RECENTNEWS
===================================================================
--- trunk/src/RECENTNEWS	2010-01-07 19:16:05 UTC (rev 396)
+++ trunk/src/RECENTNEWS	2010-01-08 10:51:56 UTC (rev 397)
@@ -1,5 +1,11 @@
 CHANGES FROM VERSION 2.39.0
 
+* MacOS GUI:
+  - improved exception handling (untested code, might not even compile)
+
+-------------------------------
+CHANGES FROM VERSION 2.39.0
+
 * Bumped version number: incompatible protocol changes
 
 * Resume copy of partially transferred files.

Modified: trunk/src/mkProjectInfo.ml
===================================================================
--- trunk/src/mkProjectInfo.ml	2010-01-07 19:16:05 UTC (rev 396)
+++ trunk/src/mkProjectInfo.ml	2010-01-08 10:51:56 UTC (rev 397)
@@ -87,3 +87,4 @@
 Printf.printf "VERSION=%d.%d.%d\n" majorVersion minorVersion pointVersion;;
 Printf.printf "NAME=%s\n" projectName;;
 
+

Modified: trunk/src/uimacbridgenew.ml
===================================================================
--- trunk/src/uimacbridgenew.ml	2010-01-07 19:16:05 UTC (rev 396)
+++ trunk/src/uimacbridgenew.ml	2010-01-08 10:51:56 UTC (rev 397)
@@ -76,6 +76,22 @@
 ;;
 Callback.register "callbackThreadCreate" callbackThreadCreate;;
 
+(* Defined in MyController.m; display the error message and exit *)
+external displayFatalError : string -> unit = "fatalError";;
+
+let fatalError message =
+  Trace.log (message ^ "\n");
+  displayFatalError message
+
+let doInOtherThread f =
+  Thread.create
+    (fun () ->
+       try
+         f ()
+       with
+         Util.Transient s | Util.Fatal s -> fatalError s
+       | exn -> fatalError (Uicommon.exn2string exn))
+
 (* Defined in MyController.m, used to redisplay the table
    when the status for a row changes *)
 external reloadTable : int -> unit = "reloadTable";;
@@ -225,11 +241,10 @@
 
 (* Do this in another thread and return immedidately to free up main thread in cocoa *)
 let unisonInit1 profileName =
-	let doIt () =
-		let r =  do_unisonInit1 profileName in 
-		unisonInit1Complete r;
-	in
-	Thread.create doIt();
+  doInOtherThread
+    (fun () ->
+       let r = do_unisonInit1 profileName in
+       unisonInit1Complete r)
 ;;
 Callback.register "unisonInit1" unisonInit1;;
 Callback.register "openConnectionPrompt" Remote.openConnectionPrompt;;
@@ -337,11 +352,10 @@
 
 (* Do this in another thread and return immedidately to free up main thread in cocoa *)
 let unisonInit2 () =
-	let doIt () =
-		let r =  do_unisonInit2 () in 
-		unisonInit2Complete r;
-	in
-	Thread.create doIt();
+  doInOtherThread
+    (fun () ->
+       let r = do_unisonInit2 () in
+       unisonInit2Complete r)
 ;;
 Callback.register "unisonInit2" unisonInit2;;
 
@@ -377,7 +391,7 @@
 Callback.register "unisonRiToRight" unisonRiToRight;;
 
 let unisonRiToFileSize ri =
-  (*FIX: will not work with files and directory larger than 1 GiB on
+  (*FIX: will not work with files and directories larger than 1 GiB on
     32bit machines! *)
   Uutil.Filesize.toInt (riLength ri.ri);;
 Callback.register "unisonRiToFileSize" unisonRiToFileSize;;
@@ -604,11 +618,10 @@
 
 (* Do this in another thread and return immedidately to free up main thread in cocoa *)
 let unisonSynchronize () =
-	let doIt () =
-		do_unisonSynchronize ();
-		syncComplete ();
-	in 
-	Thread.create doIt();
+  doInOtherThread
+    (fun () ->
+       do_unisonSynchronize ();
+       syncComplete ())
 ;;
 Callback.register "unisonSynchronize" unisonSynchronize;;
 

Modified: trunk/src/uimacnew/MyController.m
===================================================================
--- trunk/src/uimacnew/MyController.m	2010-01-07 19:16:05 UTC (rev 396)
+++ trunk/src/uimacnew/MyController.m	2010-01-08 10:51:56 UTC (rev 397)
@@ -999,6 +999,20 @@
     return toolbarHeight;
 }
 
+CAMLprim value fatalError(value s)
+{
+	NSString *str = [[NSString alloc] initWithUTF8String:String_val(s)];
+
+        [me performSelectorOnMainThread:@selector(fatalError:) withObject:str waitUntilDone:FALSE];
+	[str release];
+    return Val_unit;
+}
+
+- (void)fatalError:(NSString *)msg {
+        NSRunAlertPanel(@"Fatal error", msg, @"Exit", nil, nil);
+        exit(1);
+}
+
 @end
 
 @implementation NSString (_UnisonUtil)

Modified: trunk/src/uimacnew09/MyController.m
===================================================================
--- trunk/src/uimacnew09/MyController.m	2010-01-07 19:16:05 UTC (rev 396)
+++ trunk/src/uimacnew09/MyController.m	2010-01-08 10:51:56 UTC (rev 397)
@@ -1081,6 +1081,20 @@
     return toolbarHeight;
 }
 
+CAMLprim value fatalError(value s)
+{
+	NSString *str = [[NSString alloc] initWithUTF8String:String_val(s)];
+
+        [me performSelectorOnMainThread:@selector(fatalError:) withObject:str waitUntilDone:FALSE];
+	[str release];
+    return Val_unit;
+}
+
+- (void)fatalError:(NSString *)msg {
+        NSRunAlertPanel(@"Fatal error", msg, @"Exit", nil, nil);
+        exit(1);
+}
+
 @end
 
 @implementation NSString (_UnisonUtil)



More information about the Unison-hackers mailing list