Author: mkestner
Date: 2007-03-06 16:45:51 -0500 (Tue, 06 Mar 2007)
New Revision: 73849

Modified:
   trunk/gtk-sharp/ChangeLog
   trunk/gtk-sharp/generator/Signal.cs
Log:

2007-03-06  Mike Kestner  <[EMAIL PROTECTED]>

        * generator/Signal.cs : add try/catch blocks to native callback
        virtual method delegate too.


Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog   2007-03-06 21:42:52 UTC (rev 73848)
+++ trunk/gtk-sharp/ChangeLog   2007-03-06 21:45:51 UTC (rev 73849)
@@ -1,6 +1,11 @@
 2007-03-06  Mike Kestner  <[EMAIL PROTECTED]>
 
        * generator/Signal.cs : add try/catch blocks to native callback
+       virtual method delegate too.
+
+2007-03-06  Mike Kestner  <[EMAIL PROTECTED]>
+
+       * generator/Signal.cs : add try/catch blocks to native callback
        delegates so that exceptions are not propagated across the native
        boundary.  Now raises GLib.ExceptionManager.UnhandledException.
        * glib/ExceptionManager.cs : new class with UnhandledException

Modified: trunk/gtk-sharp/generator/Signal.cs
===================================================================
--- trunk/gtk-sharp/generator/Signal.cs 2007-03-06 21:42:52 UTC (rev 73848)
+++ trunk/gtk-sharp/generator/Signal.cs 2007-03-06 21:45:51 UTC (rev 73849)
@@ -4,6 +4,7 @@
 //
 // Copyright (c) 2001-2003 Mike Kestner 
 // Copyright (c) 2003-2005 Novell, Inc.
+// Copyright (c) 2007 Novell, Inc.
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of version 2 of the GNU General Public
@@ -154,6 +155,16 @@
                         }
                 }
 
+               private bool HasOutParams {
+                       get {
+                               foreach (Parameter p in parms) {
+                                       if (p.PassAs == "out")
+                                               return true;
+                               }
+                               return false;
+                       }
+               }
+
                public bool IsEventHandler {
                        get {
                                return retval.CSType == "void" && parms.Count 
== 1 && (parms [0].Generatable is ObjectGen || parms [0].Generatable is 
InterfaceGen);
@@ -368,13 +379,22 @@
                        sw.WriteLine ("\t\tstatic {0} {1};\n", Name + 
"VMDelegate", Name + "VMCallback");
                        sw.WriteLine ("\t\tstatic " + retval.ToNativeType + " " 
+ Name.ToLower() + "_cb (" + isig.ToString () + ")");
                        sw.WriteLine ("\t\t{");
-                       sw.WriteLine ("\t\t\t{0} {1}_managed = 
GLib.Object.GetObject ({1}, false) as {0};", implementor != null ? 
implementor.Name : container_type.Name, parms[0].Name);
-                       sw.Write (call.Setup ("\t\t\t"));
-                       sw.Write ("\t\t\t{0}", IsVoid ? "" : retval.CSType == 
retval.ToNativeType ? "return " : retval.CSType + " raw_ret = ");
+                       sw.WriteLine ("\t\t\ttry {");
+                       sw.WriteLine ("\t\t\t\t{0} {1}_managed = 
GLib.Object.GetObject ({1}, false) as {0};", implementor != null ? 
implementor.Name : container_type.Name, parms[0].Name);
+                       sw.Write (call.Setup ("\t\t\t\t"));
+                       sw.Write ("\t\t\t\t{0}", IsVoid ? "" : retval.CSType == 
retval.ToNativeType ? "return " : retval.CSType + " raw_ret = ");
                        sw.WriteLine ("{2}_managed.{0} ({1});", "On" + Name, 
call.ToString (), parms[0].Name);
-                       sw.Write (call.Finish ("\t\t\t"));
+                       sw.Write (call.Finish ("\t\t\t\t"));
                        if (!IsVoid && retval.CSType != retval.ToNativeType)
-                               sw.WriteLine ("\t\t\treturn {0};", 
SymbolTable.Table.ToNativeReturn (retval.CType, "raw_ret"));
+                               sw.WriteLine ("\t\t\t\treturn {0};", 
SymbolTable.Table.ToNativeReturn (retval.CType, "raw_ret"));
+                       sw.WriteLine ("\t\t\t} catch (Exception e) {");
+                       bool fatal = HasOutParams || !IsVoid;
+                       sw.WriteLine 
("\t\t\t\tGLib.ExceptionManager.RaiseUnhandledException (e, " + (fatal ? "true" 
: "false") + ");");
+                       if (fatal) {
+                               sw.WriteLine ("\t\t\t\t// NOTREACHED: above 
call doesn't return");
+                               sw.WriteLine ("\t\t\t\tthrow e;");
+                       }
+                       sw.WriteLine ("\t\t\t}");
                        sw.WriteLine ("\t\t}\n");
                        sw.WriteLine ("\t\tprivate static void Override" + Name 
+ " (GLib.GType gtype)");
                        sw.WriteLine ("\t\t{");

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to