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>
* glib/*.cs : add try/catch blocks to native callback

View file

@ -2,7 +2,7 @@
//
// 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.
//
@ -25,11 +25,15 @@
static void ReleaseGCHandle (IntPtr data)
{
if (data == IntPtr.Zero)
return;
try {
if (data == IntPtr.Zero)
return;
GCHandle gch = (GCHandle) data;
gch.Free ();
GCHandle gch = (GCHandle) data;
gch.Free ();
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static InputDestroyNotify release_gchandle;

View file

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

View file

@ -38,20 +38,24 @@
static void GetSize_cb (IntPtr item, IntPtr widget, IntPtr cell_area_ptr, IntPtr x_offset, IntPtr y_offset, IntPtr width, IntPtr height)
{
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr);
int a, b, c, d;
try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
Gdk.Rectangle cell_area = Gdk.Rectangle.New (cell_area_ptr);
int a, b, c, d;
obj.GetSize (widg, ref cell_area, out a, out b, out c, out d);
if (x_offset != IntPtr.Zero)
Marshal.WriteInt32 (x_offset, a);
if (y_offset != IntPtr.Zero)
Marshal.WriteInt32 (y_offset, b);
if (width != IntPtr.Zero)
Marshal.WriteInt32 (width, c);
if (height != IntPtr.Zero)
Marshal.WriteInt32 (height, d);
obj.GetSize (widg, ref cell_area, out a, out b, out c, out d);
if (x_offset != IntPtr.Zero)
Marshal.WriteInt32 (x_offset, a);
if (y_offset != IntPtr.Zero)
Marshal.WriteInt32 (y_offset, b);
if (width != IntPtr.Zero)
Marshal.WriteInt32 (width, c);
if (height != IntPtr.Zero)
Marshal.WriteInt32 (height, d);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
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)
{
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gdk.Drawable wind = GLib.Object.GetObject (window, false) as Gdk.Drawable;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
obj.Render (wind, widg, background_area, cell_area, expose_area, flags);
try {
CellRenderer obj = GLib.Object.GetObject (item, false) as CellRenderer;
Gdk.Drawable wind = GLib.Object.GetObject (window, false) as Gdk.Drawable;
Gtk.Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
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)
@ -125,13 +133,19 @@
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)
{
CellRenderer obj = GLib.Object.GetObject (raw, false) as CellRenderer;
Gdk.Event _event = new Gdk.Event (evnt);
Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
CellEditable retval = obj.StartEditing (_event, widg, GLib.Marshaller.Utf8PtrToString (path), background_area, cell_area, flags);
if (retval == null)
return IntPtr.Zero;
return retval.Handle;
try {
CellRenderer obj = GLib.Object.GetObject (raw, false) as CellRenderer;
Gdk.Event _event = new Gdk.Event (evnt);
Widget widg = GLib.Object.GetObject (widget, false) as Gtk.Widget;
CellEditable retval = obj.StartEditing (_event, widg, GLib.Marshaller.Utf8PtrToString (path), background_area, cell_area, flags);
if (retval == null)
return IntPtr.Zero;
return retval.Handle;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return IntPtr.Zero;
}
static void OverrideStartEditing (GLib.GType gtype)

View file

@ -94,15 +94,19 @@
void RichTextReceivedCallback (IntPtr clipboard_ptr, IntPtr format_ptr, IntPtr text_ptr, UIntPtr length, IntPtr data)
{
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);
int sz = (int) (uint) length;
byte[] text = new byte [sz];
Marshal.Copy (text, 0, text_ptr, sz);
GCHandle gch = (GCHandle) data;
RichTextReceivedFunc cb = gch.Target as RichTextReceivedFunc;
cb (clipboard, format, text);
gch.Free ();
try {
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);
int sz = (int) (uint) length;
byte[] text = new byte [sz];
Marshal.Copy (text, 0, text_ptr, sz);
GCHandle gch = (GCHandle) data;
RichTextReceivedFunc cb = gch.Target as RichTextReceivedFunc;
cb (clipboard, format, text);
gch.Free ();
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
[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)
{
Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, invoker);
try {
Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, invoker);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
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)
{
Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, new Gtk.Callback (invoker.Invoke));
try {
Container obj = GLib.Object.GetObject (container, false) as Container;
CallbackInvoker invoker = new CallbackInvoker (cb, data);
obj.ForAll (include_internals, new Gtk.Callback (invoker.Invoke));
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static void OverrideForall (GLib.GType gtype)
@ -203,9 +211,15 @@ static ChildTypeDelegate ChildTypeCallback;
static IntPtr ChildType_cb (IntPtr raw)
{
Container obj = GLib.Object.GetObject (raw, false) as Container;
GLib.GType gtype = obj.ChildType ();
return gtype.Val;
try {
Container obj = GLib.Object.GetObject (raw, false) as Container;
GLib.GType gtype = obj.ChildType ();
return gtype.Val;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return GLib.GType.Invalid.Val;
}
static void OverrideChildType (GLib.GType gtype)

View file

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

View file

@ -113,32 +113,49 @@ namespace Gtk {
IntPtr get_column_type_cb (int col)
{
return ctypes [col].Val;
try {
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)
{
if (path == IntPtr.Zero)
throw new ArgumentNullException ("path");
try {
if (path == IntPtr.Zero)
throw new ArgumentNullException ("path");
TreePath treepath = new TreePath (path);
TreePath treepath = new TreePath (path);
node_idx = -1;
ITreeNode node = GetNodeAtPath (treepath);
if (node == null)
return false;
node_idx = node.ID;
node_hash [node.ID] = node;
return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
node_idx = -1;
ITreeNode node = GetNodeAtPath (treepath);
if (node == null)
return false;
node_idx = node.ID;
node_hash [node.ID] = node;
return true;
return false;
}
IntPtr get_path_cb (int node_idx)
{
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null) throw new Exception ("Invalid Node ID");
try {
ITreeNode node = node_hash [node_idx] as ITreeNode;
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")]
@ -146,125 +163,160 @@ namespace Gtk {
void get_value_cb (int node_idx, int col, ref GLib.Value val)
{
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null)
return;
g_value_init (ref val, ctypes [col].Val);
object col_val;
if (getters [col] is PropertyInfo)
col_val = ((PropertyInfo) getters [col]).GetValue (node, null);
else
col_val = ((FieldInfo) getters [col]).GetValue (node);
val.Val = col_val;
try {
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null)
return;
g_value_init (ref val, ctypes [col].Val);
object col_val;
if (getters [col] is PropertyInfo)
col_val = ((PropertyInfo) getters [col]).GetValue (node, null);
else
col_val = ((FieldInfo) getters [col]).GetValue (node);
val.Val = col_val;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
bool next_cb (ref int node_idx)
{
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null)
return false;
try {
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null)
return false;
int idx;
if (node.Parent == null)
idx = Nodes.IndexOf (node);
else
idx = node.Parent.IndexOf (node);
int idx;
if (node.Parent == null)
idx = Nodes.IndexOf (node);
else
idx = node.Parent.IndexOf (node);
if (idx < 0) throw new Exception ("Node not found in Nodes list");
if (idx < 0) throw new Exception ("Node not found in Nodes list");
if (node.Parent == null) {
if (++idx >= Nodes.Count)
return false;
node = Nodes [idx] as ITreeNode;
} else {
if (++idx >= node.Parent.ChildCount)
return false;
node = node.Parent [idx];
if (node.Parent == null) {
if (++idx >= Nodes.Count)
return false;
node = Nodes [idx] as ITreeNode;
} else {
if (++idx >= node.Parent.ChildCount)
return false;
node = node.Parent [idx];
}
node_hash [node.ID] = node;
node_idx = node.ID;
return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
node_hash [node.ID] = node;
node_idx = node.ID;
return true;
return false;
}
bool children_cb (out int child_idx, int parent)
{
child_idx = -1;
ITreeNode node;
try {
child_idx = -1;
ITreeNode node;
if (parent == -1) {
if (Nodes.Count <= 0)
return false;
node = Nodes [0] as ITreeNode;
child_idx = node.ID;
node_hash [node.ID] = node;
return true;
}
if (parent == -1) {
if (Nodes.Count <= 0)
return false;
node = Nodes [0] as ITreeNode;
child_idx = node.ID;
node_hash [node.ID] = node;
return true;
}
node = node_hash [parent] as ITreeNode;
if (node == null || node.ChildCount <= 0)
return false;
node = node_hash [parent] as ITreeNode;
if (node == null || node.ChildCount <= 0)
return false;
ITreeNode child = node [0];
node_hash [child.ID] = child;
child_idx = child.ID;
return true;
ITreeNode child = node [0];
node_hash [child.ID] = child;
child_idx = child.ID;
return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
child_idx = -1;
return false;
}
bool has_child_cb (int node_idx)
{
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null || node.ChildCount <= 0)
return false;
try {
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null || node.ChildCount <= 0)
return false;
return true;
return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
}
int n_children_cb (int node_idx)
{
if (node_idx == -1)
return Nodes.Count;
try {
if (node_idx == -1)
return Nodes.Count;
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null || node.ChildCount <= 0)
return 0;
ITreeNode node = node_hash [node_idx] as ITreeNode;
if (node == null || node.ChildCount <= 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)
{
child_idx = -1;
ITreeNode node;
try {
ITreeNode node;
if (parent == -1) {
if (Nodes.Count <= n)
return false;
node = Nodes [n] as ITreeNode;
child_idx = node.ID;
node_hash [node.ID] = node;
return true;
}
if (parent == -1) {
if (Nodes.Count <= n)
return false;
node = Nodes [n] as ITreeNode;
child_idx = node.ID;
node_hash [node.ID] = node;
return true;
}
node = node_hash [parent] as ITreeNode;
if (node == null || node.ChildCount <= n)
return false;
node = node_hash [parent] as ITreeNode;
if (node == null || node.ChildCount <= n)
return false;
ITreeNode child = node [n];
node_hash [child.ID] = child;
child_idx = child.ID;
return true;
ITreeNode child = node [n];
node_hash [child.ID] = child;
child_idx = child.ID;
return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
}
bool parent_cb (out int parent_idx, int child)
{
parent_idx = -1;
ITreeNode node = node_hash [child] as ITreeNode;
if (node == null || node.Parent == null)
return false;
try {
ITreeNode node = node_hash [child] as ITreeNode;
if (node == null || node.Parent == null)
return false;
node_hash [node.Parent.ID] = node.Parent;
parent_idx = node.Parent.ID;
return true;
node_hash [node.Parent.ID] = node.Parent;
parent_idx = node.Parent.ID;
return true;
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
return false;
}
[DllImport("gtksharpglue-2")]

View file

@ -198,10 +198,14 @@ static SetScrollAdjustmentsDelegate SetScrollAdjustmentsCallback;
static void SetScrollAdjustments_cb (IntPtr widget, IntPtr hadj, IntPtr vadj)
{
Widget obj = GLib.Object.GetObject (widget, false) as Widget;
Gtk.Adjustment h = GLib.Object.GetObject (hadj, false) as Gtk.Adjustment;
Gtk.Adjustment v = GLib.Object.GetObject (vadj, false) as Gtk.Adjustment;
obj.OnSetScrollAdjustments (h, v);
try {
Widget obj = GLib.Object.GetObject (widget, false) as Widget;
Gtk.Adjustment h = GLib.Object.GetObject (hadj, false) as Gtk.Adjustment;
Gtk.Adjustment v = GLib.Object.GetObject (vadj, false) as Gtk.Adjustment;
obj.OnSetScrollAdjustments (h, v);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
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)
{
Widget w = GLib.Object.GetObject (handle, false) as Widget;
BindingInvoker invoker = ((GCHandle) user_data).Target as BindingInvoker;
invoker.Invoke (w);
try {
Widget w = GLib.Object.GetObject (handle, false) as Widget;
BindingInvoker invoker = ((GCHandle) user_data).Target as BindingInvoker;
invoker.Invoke (w);
} catch (Exception e) {
GLib.ExceptionManager.RaiseUnhandledException (e, false);
}
}
static BindingHandler binding_delegate;