From 925a2b63c36e7d69de42e6f8cc8c4241ced533b1 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 4 Oct 2007 17:52:35 +0000 Subject: [PATCH] 2007-10-04 Mike Kestner * glib/DestroyNotify.cs: add CDeclCallback to the delegate. * glib/Signal.cs: use DestroyHelper. * gdk/Input.custom: use DestroyHelper. * gtk/Quit.custom: remove new on DestroyHelper handler. * gtk/TreeModelFilter.custom: remove new on DestroyHelper handler. * gtk/TreeViewColumn.custom: remove new on DestroyHelper handler. svn path=/trunk/gtk-sharp/; revision=86897 --- ChangeLog | 9 +++++++++ gdk/Input.custom | 28 +++------------------------- glib/DestroyNotify.cs | 1 + glib/Signal.cs | 20 ++------------------ gtk/Quit.custom | 2 +- gtk/TreeModelFilter.custom | 2 +- gtk/TreeViewColumn.custom | 2 +- 7 files changed, 18 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 749489e57..f28b3a57c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-10-04 Mike Kestner + + * glib/DestroyNotify.cs: add CDeclCallback to the delegate. + * glib/Signal.cs: use DestroyHelper. + * gdk/Input.custom: use DestroyHelper. + * gtk/Quit.custom: remove new on DestroyHelper handler. + * gtk/TreeModelFilter.custom: remove new on DestroyHelper handler. + * gtk/TreeViewColumn.custom: remove new on DestroyHelper handler. + 2007-10-02 Mike Kestner * generator/*.cs: implement the interfaces on the adapters too. diff --git a/gdk/Input.custom b/gdk/Input.custom index bf9443e7d..e183fce76 100644 --- a/gdk/Input.custom +++ b/gdk/Input.custom @@ -20,43 +20,21 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. - [GLib.CDeclCallback] - delegate void InputDestroyNotify (IntPtr data); - - static void ReleaseGCHandle (IntPtr data) - { - try { - if (data == IntPtr.Zero) - return; - - GCHandle gch = (GCHandle) data; - gch.Free (); - } catch (Exception e) { - GLib.ExceptionManager.RaiseUnhandledException (e, false); - } - } - - static InputDestroyNotify release_gchandle; - [DllImport("libgdk-win32-2.0-0.dll")] - static extern int gdk_input_add_full (int source, int condition, GdkSharp.InputFunctionNative function, IntPtr data, InputDestroyNotify destroy); + static extern int gdk_input_add_full (int source, int condition, GdkSharp.InputFunctionNative function, IntPtr data, GLib.DestroyNotify destroy); [Obsolete] public static int AddFull (int source, Gdk.InputCondition condition, Gdk.InputFunction function, IntPtr data, Gdk.DestroyNotify destroy) { - if (release_gchandle == null) - release_gchandle = new InputDestroyNotify (ReleaseGCHandle); GdkSharp.InputFunctionWrapper function_wrapper = new GdkSharp.InputFunctionWrapper (function); GCHandle gch = GCHandle.Alloc (function_wrapper); - return gdk_input_add_full (source, (int) condition, function_wrapper.NativeDelegate, (IntPtr) gch, release_gchandle); + return gdk_input_add_full (source, (int) condition, function_wrapper.NativeDelegate, (IntPtr) gch, GLib.DestroyHelper.NotifyHandler); } [Obsolete] public static int Add (int source, Gdk.InputCondition condition, Gdk.InputFunction function) { - if (release_gchandle == null) - release_gchandle = new InputDestroyNotify (ReleaseGCHandle); GdkSharp.InputFunctionWrapper function_wrapper = new GdkSharp.InputFunctionWrapper (function); GCHandle gch = GCHandle.Alloc (function_wrapper); - return gdk_input_add_full (source, (int) condition, function_wrapper.NativeDelegate, (IntPtr) gch, release_gchandle); + return gdk_input_add_full (source, (int) condition, function_wrapper.NativeDelegate, (IntPtr) gch, GLib.DestroyHelper.NotifyHandler); } diff --git a/glib/DestroyNotify.cs b/glib/DestroyNotify.cs index 0f09ee13e..820c6f573 100644 --- a/glib/DestroyNotify.cs +++ b/glib/DestroyNotify.cs @@ -23,6 +23,7 @@ namespace GLib { using System; using System.Runtime.InteropServices; + [GLib.CDeclCallback] public delegate void DestroyNotify (IntPtr data); public class DestroyHelper { diff --git a/glib/Signal.cs b/glib/Signal.cs index 58beb146a..8d6e785df 100644 --- a/glib/Signal.cs +++ b/glib/Signal.cs @@ -51,22 +51,6 @@ namespace GLib { uint after_id = UInt32.MaxValue; Delegate marshaler; - static SignalDestroyNotify notify = new SignalDestroyNotify (OnNativeDestroy); - [CDeclCallback] - delegate void SignalDestroyNotify (IntPtr data, IntPtr obj); - static void OnNativeDestroy (IntPtr data, IntPtr obj) - { - try { - GCHandle gch = (GCHandle) data; - Signal s = gch.Target as Signal; - s.DisconnectHandler (s.before_id); - s.DisconnectHandler (s.after_id); - gch.Free (); - } catch (Exception e) { - ExceptionManager.RaiseUnhandledException (e, false); - } - } - private Signal (GLib.Object obj, string signal_name, Delegate marshaler) { handle = obj.Handle; @@ -75,7 +59,7 @@ namespace GLib { gc_handle = GCHandle.Alloc (this); IntPtr native_key = GLib.Marshaller.StringToPtrGStrdup (name + "_signal_marshaler"); if (handle != IntPtr.Zero) - g_object_set_data_full (handle, native_key, (IntPtr) gc_handle, notify); + g_object_set_data_full (handle, native_key, (IntPtr) gc_handle, DestroyHelper.NotifyHandler); GLib.Marshaller.Free (native_key); } @@ -209,7 +193,7 @@ namespace GLib { static extern void g_object_set_data (IntPtr instance, IntPtr key, IntPtr data); [DllImport("libgobject-2.0-0.dll")] - static extern void g_object_set_data_full (IntPtr instance, IntPtr key, IntPtr data, SignalDestroyNotify notify); + static extern void g_object_set_data_full (IntPtr instance, IntPtr key, IntPtr data, DestroyNotify notify); [DllImport("libgobject-2.0-0.dll")] static extern uint g_signal_connect_data(IntPtr obj, IntPtr name, Delegate cb, IntPtr gc_handle, IntPtr dummy, int flags); diff --git a/gtk/Quit.custom b/gtk/Quit.custom index eedc6590b..68f1e7038 100644 --- a/gtk/Quit.custom +++ b/gtk/Quit.custom @@ -69,6 +69,6 @@ { GtkSharp.FunctionWrapper function_wrapper = new GtkSharp.FunctionWrapper (function); GCHandle gch = GCHandle.Alloc (function_wrapper); - return gtk_quit_add_full (main_level, function_wrapper.NativeDelegate, null, (IntPtr) gch, new GLib.DestroyNotify (GLib.DestroyHelper.NotifyHandler)); + return gtk_quit_add_full (main_level, function_wrapper.NativeDelegate, null, (IntPtr) gch, GLib.DestroyHelper.NotifyHandler); } diff --git a/gtk/TreeModelFilter.custom b/gtk/TreeModelFilter.custom index 3a56c45f4..5e8bb6bc4 100644 --- a/gtk/TreeModelFilter.custom +++ b/gtk/TreeModelFilter.custom @@ -66,7 +66,7 @@ for (int i = 0; i < types.Length; i++) native_types [i] = types [i].Val; GCHandle gch = GCHandle.Alloc (func_wrapper); - gtk_tree_model_filter_set_modify_func (Handle, n_columns, native_types, func_wrapper.NativeDelegate, (IntPtr) gch, new GLib.DestroyNotify (GLib.DestroyHelper.NotifyHandler)); + gtk_tree_model_filter_set_modify_func (Handle, n_columns, native_types, func_wrapper.NativeDelegate, (IntPtr) gch, GLib.DestroyHelper.NotifyHandler); } [DllImport("libgtk-win32-2.0-0.dll")] diff --git a/gtk/TreeViewColumn.custom b/gtk/TreeViewColumn.custom index 581ff2633..9d4f577a5 100644 --- a/gtk/TreeViewColumn.custom +++ b/gtk/TreeViewColumn.custom @@ -75,7 +75,7 @@ NodeCellDataFuncWrapper func_wrapper = new NodeCellDataFuncWrapper (func); GCHandle gch = GCHandle.Alloc (func_wrapper); - gtk_cell_layout_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, new GLib.DestroyNotify (GLib.DestroyHelper.NotifyHandler)); + gtk_cell_layout_set_cell_data_func (Handle, cell_renderer == null ? IntPtr.Zero : cell_renderer.Handle, func_wrapper.NativeDelegate, (IntPtr) gch, GLib.DestroyHelper.NotifyHandler); } [Obsolete ("Replaced by SetCellDataFunc (CellRenderer, TreeCellDataFunc) overload")]