2007-03-08 Mike Kestner <mkestner@novell.com>

* glib/Signal.cs : guard against NULL gchandles.
	* gdk/Input.custom : add try/catch blocks to native callbacks.
	* gtk/*.custom : ditto
	* gtk/NodeStore.cs : ditto

svn path=/trunk/gtk-sharp/; revision=74004
This commit is contained in:
Mike Kestner 2007-03-09 14:22:43 +00:00
parent 57810954a3
commit fd01afc12b
9 changed files with 261 additions and 152 deletions

View file

@ -1,3 +1,10 @@
2007-03-08 Mike Kestner <mkestner@novell.com>
* glib/Signal.cs : guard against NULL gchandles.
* gdk/Input.custom : add try/catch blocks to native callbacks.
* gtk/*.custom : ditto
* gtk/NodeStore.cs : ditto
2007-03-08 Mike Kestner <mkestner@novell.com> 2007-03-08 Mike Kestner <mkestner@novell.com>
* glib/*.cs : add try/catch blocks to native callback * glib/*.cs : add try/catch blocks to native callback

View file

@ -2,7 +2,7 @@
// //
// Author: Mike Kestner <mkestner@ximian.com> // Author: Mike Kestner <mkestner@ximian.com>
// //
// Copyright (C) 2005 Novell, Inc. // Copyright (C) 2005, 2007 Novell, Inc.
// //
// This code is inserted after the automatically generated code. // This code is inserted after the automatically generated code.
// //
@ -25,11 +25,15 @@
static void ReleaseGCHandle (IntPtr data) static void ReleaseGCHandle (IntPtr data)
{ {
try {
if (data == IntPtr.Zero) if (data == IntPtr.Zero)
return; return;
GCHandle gch = (GCHandle) data; GCHandle gch = (GCHandle) data;
gch.Free (); gch.Free ();
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static InputDestroyNotify release_gchandle; static InputDestroyNotify release_gchandle;

View file

@ -178,6 +178,8 @@ namespace GLib {
static void voidObjectCallback (IntPtr handle, IntPtr gch) static void voidObjectCallback (IntPtr handle, IntPtr gch)
{ {
try { try {
if (gch == IntPtr.Zero)
return;
Signal sig = ((GCHandle) gch).Target as Signal; Signal sig = ((GCHandle) gch).Target as Signal;
if (sig == null) { if (sig == null) {
ExceptionManager.RaiseUnhandledException (new Exception ("Unknown signal class GC handle received."), false); ExceptionManager.RaiseUnhandledException (new Exception ("Unknown signal class GC handle received."), false);

View file

@ -38,6 +38,7 @@
static void GetSize_cb (IntPtr item, IntPtr widget, IntPtr cell_area_ptr, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height) static void GetSize_cb (IntPtr item, IntPtr widget, IntPtr cell_area_ptr, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height)
{ {
try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer; CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget; Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr); Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr);
@ -52,6 +53,9 @@
Marshal.WriteInt32 (width, c); Marshal.WriteInt32 (width, c);
if (height != IntPtr.Zero) if (height != IntPtr.Zero)
Marshal.WriteInt32 (height, d); Marshal.WriteInt32 (height, d);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static void OverrideGetSize (GLib.GType gtype) static void OverrideGetSize (GLib.GType gtype)
@ -88,10 +92,14 @@
static void Render_cb (IntPtr item, IntPtr window, IntPtr widget, ref Gdk.Rectangle background_area, ref Gdk.Rectangle cell_area, ref Gdk.Rectangle expose_area, Gtk.CellRendererState flags) static void Render_cb (IntPtr item, IntPtr window, IntPtr widget, ref Gdk.Rectangle background_area, ref Gdk.Rectangle cell_area, ref Gdk.Rectangle expose_area, Gtk.CellRendererState flags)
{ {
try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer; CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gdk.Drawable wind = GLib.Object.GetObject (window, false) as Gdk.Drawable; Gdk.Drawable wind = GLib.Object.GetObject (window, false) as Gdk.Drawable;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget; Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
obj.Render (wind, widg, background_area, cell_area, expose_area, flags); obj.Render (wind, widg, background_area, cell_area, expose_area, flags);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static void OverrideRender (GLib.GType gtype) static void OverrideRender (GLib.GType gtype)
@ -125,6 +133,7 @@
static IntPtr StartEditing_cb (IntPtr raw, IntPtr evnt, IntPtr widget, IntPtr path, ref Gdk.Rectangle background_area, ref Gdk.Rectangle cell_area, Gtk.CellRendererState flags) static IntPtr StartEditing_cb (IntPtr raw, IntPtr evnt, IntPtr widget, IntPtr path, ref Gdk.Rectangle background_area, ref Gdk.Rectangle cell_area, Gtk.CellRendererState flags)
{ {
try {
CellRenderer obj = GLib.Object.GetObject (raw, false) as CellRenderer; CellRenderer obj = GLib.Object.GetObject (raw, false) as CellRenderer;
Gdk.Event _event = new Gdk.Event (evnt); Gdk.Event _event = new Gdk.Event (evnt);
Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget; Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
@ -132,6 +141,11 @@
if (retval == null) if (retval == null)
return IntPtr.Zero; return IntPtr.Zero;
return retval.Handle; return retval.Handle;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return IntPtr.Zero;
} }
static void OverrideStartEditing (GLib.GType gtype) static void OverrideStartEditing (GLib.GType gtype)

View file

@ -94,6 +94,7 @@
void RichTextReceivedCallback (IntPtr clipboard_ptr, IntPtr format_ptr, IntPtr text_ptr, UIntPtr length, IntPtr data) void RichTextReceivedCallback (IntPtr clipboard_ptr, IntPtr format_ptr, IntPtr text_ptr, UIntPtr length, IntPtr data)
{ {
try {
Gtk.Clipboard clipboard = GLib.Object.GetObject(clipboard_ptr) as Gtk.Clipboard; Gtk.Clipboard clipboard = GLib.Object.GetObject(clipboard_ptr) as Gtk.Clipboard;
Gdk.Atom format = format_ptr == IntPtr.Zero ? null : (Gdk.Atom) GLib.Opaque.GetOpaque (format_ptr, typeof (Gdk.Atom), false); Gdk.Atom format = format_ptr == IntPtr.Zero ? null : (Gdk.Atom) GLib.Opaque.GetOpaque (format_ptr, typeof (Gdk.Atom), false);
int sz = (int) (uint) length; int sz = (int) (uint) length;
@ -103,6 +104,9 @@
RichTextReceivedFunc cb = gch.Target as RichTextReceivedFunc; RichTextReceivedFunc cb = gch.Target as RichTextReceivedFunc;
cb (clipboard, format, text); cb (clipboard, format, text);
gch.Free (); gch.Free ();
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
[DllImport("libgtk-win32-2.0-0.dll")] [DllImport("libgtk-win32-2.0-0.dll")]

View file

@ -145,9 +145,13 @@ public struct CallbackInvoker {
static void ForallOld_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data) static void ForallOld_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data)
{ {
try {
Container obj = GLib.Object.GetObject (container, false) as Container; Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data); CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, invoker); obj.ForAll (include_internals, invoker);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static void OverrideForallOld (GLib.GType gtype) static void OverrideForallOld (GLib.GType gtype)
@ -166,9 +170,13 @@ protected virtual void ForAll (bool include_internals, CallbackInvoker invoker)
static void Forall_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data) static void Forall_cb (IntPtr container, bool include_internals, IntPtr cb, IntPtr data)
{ {
try {
Container obj = GLib.Object.GetObject (container, false) as Container; Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data); CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, new Gtk.Callback (invoker.Invoke)); obj.ForAll (include_internals, new Gtk.Callback (invoker.Invoke));
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static void OverrideForall (GLib.GType gtype) static void OverrideForall (GLib.GType gtype)
@ -203,9 +211,15 @@ static ChildTypeDelegate ChildTypeCallback;
static IntPtr ChildType_cb (IntPtr raw) static IntPtr ChildType_cb (IntPtr raw)
{ {
try {
Container obj = GLib.Object.GetObject (raw, false) as Container; Container obj = GLib.Object.GetObject (raw, false) as Container;
GLib.GType gtype = obj.ChildType (); GLib.GType gtype = obj.ChildType ();
return gtype.Val; return gtype.Val;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return GLib.GType.Invalid.Val;
} }
static void OverrideChildType (GLib.GType gtype) static void OverrideChildType (GLib.GType gtype)

View file

@ -29,10 +29,14 @@
public void NativeCallback (IntPtr data, int source, int condition) public void NativeCallback (IntPtr data, int source, int condition)
{ {
try {
IntPtr _arg0 = data; IntPtr _arg0 = data;
int _arg1 = source; int _arg1 = source;
Gdk.InputCondition _arg2 = (Gdk.InputCondition) condition; Gdk.InputCondition _arg2 = (Gdk.InputCondition) condition;
managed ( _arg0, _arg1, _arg2); managed ( _arg0, _arg1, _arg2);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
internal InputFunctionNative NativeDelegate; internal InputFunctionNative NativeDelegate;

View file

@ -113,11 +113,18 @@ namespace Gtk {
IntPtr get_column_type_cb (int col) IntPtr get_column_type_cb (int col)
{ {
try {
return ctypes [col].Val; return ctypes [col].Val;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return IntPtr.Zero;
} }
bool get_node_cb (out int node_idx, IntPtr path) bool get_node_cb (out int node_idx, IntPtr path)
{ {
try {
if (path == IntPtr.Zero) if (path == IntPtr.Zero)
throw new ArgumentNullException ("path"); throw new ArgumentNullException ("path");
@ -131,14 +138,24 @@ namespace Gtk {
node_idx = node.ID; node_idx = node.ID;
node_hash [node.ID] = node; node_hash [node.ID] = node;
return true; return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
node_idx = -1;
return false;
} }
IntPtr get_path_cb (int node_idx) IntPtr get_path_cb (int node_idx)
{ {
try {
ITreeNode node = node_hash [node_idx] as ITreeNode; ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null) throw new Exception ("Invalid Node ID"); if (node == null) throw new Exception ("Invalid Node ID");
return GetPath (node).Handle; return GetPath (node).Handle;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return IntPtr.Zero;
} }
[DllImport("libgobject-2.0-0.dll")] [DllImport("libgobject-2.0-0.dll")]
@ -146,6 +163,7 @@ namespace Gtk {
void get_value_cb (int node_idx, int col, ref GLib.Value val) void get_value_cb (int node_idx, int col, ref GLib.Value val)
{ {
try {
ITreeNode node = node_hash [node_idx] as ITreeNode; ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null) if (node == null)
return; return;
@ -156,10 +174,14 @@ namespace Gtk {
else else
col_val = ((FieldInfo) getters [col]).GetValue (node); col_val = ((FieldInfo) getters [col]).GetValue (node);
val.Val = col_val; val.Val = col_val;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
bool next_cb (ref int node_idx) bool next_cb (ref int node_idx)
{ {
try {
ITreeNode node = node_hash [node_idx] as ITreeNode; ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null) if (node == null)
return false; return false;
@ -184,10 +206,15 @@ namespace Gtk {
node_hash [node.ID] = node; node_hash [node.ID] = node;
node_idx = node.ID; node_idx = node.ID;
return true; return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
} }
bool children_cb (out int child_idx, int parent) bool children_cb (out int child_idx, int parent)
{ {
try {
child_idx = -1; child_idx = -1;
ITreeNode node; ITreeNode node;
@ -208,19 +235,30 @@ namespace Gtk {
node_hash [child.ID] = child; node_hash [child.ID] = child;
child_idx = child.ID; child_idx = child.ID;
return true; return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
child_idx = -1;
return false;
} }
bool has_child_cb (int node_idx) bool has_child_cb (int node_idx)
{ {
try {
ITreeNode node = node_hash [node_idx] as ITreeNode; ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null || node.ChildCount <= 0) if (node == null || node.ChildCount <= 0)
return false; return false;
return true; return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
} }
int n_children_cb (int node_idx) int n_children_cb (int node_idx)
{ {
try {
if (node_idx == -1) if (node_idx == -1)
return Nodes.Count; return Nodes.Count;
@ -229,11 +267,16 @@ namespace Gtk {
return 0; return 0;
return node.ChildCount; return node.ChildCount;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return 0;
} }
bool nth_child_cb (out int child_idx, int parent, int n) bool nth_child_cb (out int child_idx, int parent, int n)
{ {
child_idx = -1; child_idx = -1;
try {
ITreeNode node; ITreeNode node;
if (parent == -1) { if (parent == -1) {
@ -253,11 +296,16 @@ namespace Gtk {
node_hash [child.ID] = child; node_hash [child.ID] = child;
child_idx = child.ID; child_idx = child.ID;
return true; return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
} }
bool parent_cb (out int parent_idx, int child) bool parent_cb (out int parent_idx, int child)
{ {
parent_idx = -1; parent_idx = -1;
try {
ITreeNode node = node_hash [child] as ITreeNode; ITreeNode node = node_hash [child] as ITreeNode;
if (node == null || node.Parent == null) if (node == null || node.Parent == null)
return false; return false;
@ -265,6 +313,10 @@ namespace Gtk {
node_hash [node.Parent.ID] = node.Parent; node_hash [node.Parent.ID] = node.Parent;
parent_idx = node.Parent.ID; parent_idx = node.Parent.ID;
return true; return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
} }
[DllImport("gtksharpglue-2")] [DllImport("gtksharpglue-2")]

View file

@ -198,10 +198,14 @@ static SetScrollAdjustmentsDelegate SetScrollAdjustmentsCallback;
static void SetScrollAdjustments_cb (IntPtr widget, IntPtr hadj, IntPtr vadj) static void SetScrollAdjustments_cb (IntPtr widget, IntPtr hadj, IntPtr vadj)
{ {
try {
Widget obj = GLib.Object.GetObject (widget, false) as Widget; Widget obj = GLib.Object.GetObject (widget, false) as Widget;
Gtk.Adjustment h = GLib.Object.GetObject (hadj, false) as Gtk.Adjustment; Gtk.Adjustment h = GLib.Object.GetObject (hadj, false) as Gtk.Adjustment;
Gtk.Adjustment v = GLib.Object.GetObject (vadj, false) as Gtk.Adjustment; Gtk.Adjustment v = GLib.Object.GetObject (vadj, false) as Gtk.Adjustment;
obj.OnSetScrollAdjustments (h, v); obj.OnSetScrollAdjustments (h, v);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static void ConnectSetScrollAdjustments (GLib.GType gtype) static void ConnectSetScrollAdjustments (GLib.GType gtype)
@ -237,9 +241,13 @@ private delegate void BindingHandler (IntPtr handle, IntPtr user_data);
private static void BindingCallback (IntPtr handle, IntPtr user_data) private static void BindingCallback (IntPtr handle, IntPtr user_data)
{ {
try {
Widget w = GLib.Object.GetObject (handle, false) as Widget; Widget w = GLib.Object.GetObject (handle, false) as Widget;
BindingInvoker invoker = ((GCHandle) user_data).Target as BindingInvoker; BindingInvoker invoker = ((GCHandle) user_data).Target as BindingInvoker;
invoker.Invoke (w); invoker.Invoke (w);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
} }
static BindingHandler binding_delegate; static BindingHandler binding_delegate;