From bd50999b1bc9e41f52a995e77fc34c99ea28a22a Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Sat, 12 Mar 2005 18:54:53 +0000 Subject: [PATCH] 2005-03-12 Mike Kestner * generator/CallbackGen.cs : don't derive Wrappers from DelegateWrapper any more. It leaks delegates like crazy. We effectively now use call scope as the default for delegate parameters. * generator/MethodBody.cs : use new simpler Wrapper ctor. * glib/DelegateWrapper.cs : mark the ctor obsolete so people know to update any manually coded wrappers out there. * */*.custom : use new simpler Callback Wrapper ctors. svn path=/trunk/gtk-sharp/; revision=41738 --- ChangeLog | 10 ++++++++++ gdk/Pixbuf.custom | 4 ++-- gdk/Window.custom | 2 +- generator/CallbackGen.cs | 18 +++++++++--------- generator/MethodBody.cs | 3 ++- glade/XML.custom | 2 +- glib/DelegateWrapper.cs | 1 + gnome/PanelAppletFactory.cs | 24 +++++++++++++++++++++++- gtk/Accel.custom | 4 ++-- gtk/CellView.custom | 2 +- gtk/ComboBox.custom | 2 +- gtk/EntryCompletion.custom | 2 +- gtk/NodeCellDataFunc.cs | 4 ++-- gtk/Toolbar.custom | 14 +++++++------- gtk/TreeViewColumn.custom | 6 +++--- 15 files changed, 66 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5779b7eea..43eb8bceb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-03-12 Mike Kestner + + * generator/CallbackGen.cs : don't derive Wrappers from DelegateWrapper + any more. It leaks delegates like crazy. We effectively now use call + scope as the default for delegate parameters. + * generator/MethodBody.cs : use new simpler Wrapper ctor. + * glib/DelegateWrapper.cs : mark the ctor obsolete so people know to + update any manually coded wrappers out there. + * */*.custom : use new simpler Callback Wrapper ctors. + 2005-03-11 Mike Kestner * glib/DelegateWrapper.cs : call g_object_set_data_full since we are diff --git a/gdk/Pixbuf.custom b/gdk/Pixbuf.custom index eee561166..bac0d33a3 100644 --- a/gdk/Pixbuf.custom +++ b/gdk/Pixbuf.custom @@ -171,7 +171,7 @@ public Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn) : base (IntPtr.Zero) { GdkSharp.PixbufDestroyNotifyWrapper destroy_fn_wrapper = null; - destroy_fn_wrapper = new GdkSharp.PixbufDestroyNotifyWrapper (destroy_fn, this); + destroy_fn_wrapper = new GdkSharp.PixbufDestroyNotifyWrapper (destroy_fn); Raw = gdk_pixbuf_new_from_data(data, (int) Gdk.Colorspace.Rgb, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn_wrapper.NativeDelegate, IntPtr.Zero); } @@ -318,7 +318,7 @@ public unsafe void SaveToCallback (PixbufSaveFunc save_func, string type, string[] option_keys, string[] option_values) { GdkSharp.PixbufSaveFuncWrapper save_func_wrapper = null; - save_func_wrapper = new GdkSharp.PixbufSaveFuncWrapper (save_func, this); + save_func_wrapper = new GdkSharp.PixbufSaveFuncWrapper (save_func); IntPtr error = IntPtr.Zero; IntPtr ntype = GLib.Marshaller.StringToPtrGStrdup (type); IntPtr[] nkeys = NullTerm (option_keys); diff --git a/gdk/Window.custom b/gdk/Window.custom index 5d77fc632..8281a471f 100644 --- a/gdk/Window.custom +++ b/gdk/Window.custom @@ -115,7 +115,7 @@ public static void AddFilterForAll (FilterFunc func) { - GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (func, null); + GdkSharp.FilterFuncWrapper wrapper = new GdkSharp.FilterFuncWrapper (func); FilterAllHash [func] = wrapper; gdk_window_add_filter (IntPtr.Zero, wrapper.NativeDelegate, IntPtr.Zero); } diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index 85c186752..e93590b92 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -69,11 +69,11 @@ namespace GtkSharp.Generation { sw.WriteLine ("\tusing System;"); sw.WriteLine (); sw.WriteLine ("#region Autogenerated code"); - sw.WriteLine ("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + isig.ToString() + ");"); + sw.WriteLine ("\tinternal delegate " + retval.MarshalType + " " + wrapper + "(" + isig + ");"); sw.WriteLine (); - sw.WriteLine ("\tinternal class " + Name + "Wrapper : GLib.DelegateWrapper {"); + sw.WriteLine ("\tinternal class " + Name + "Wrapper {"); sw.WriteLine (); - sw.WriteLine ("\t\tpublic " + retval.MarshalType + " NativeCallback (" + isig.ToString() + ")"); + sw.WriteLine ("\t\tpublic " + retval.MarshalType + " NativeCallback (" + isig + ")"); sw.WriteLine ("\t\t{"); bool need_sep = false; @@ -112,7 +112,7 @@ namespace GtkSharp.Generation { } sw.Write ("\t\t\t"); - string invoke = "_managed (" + call_str + ")"; + string invoke = "managed (" + call_str + ")"; if (retval.MarshalType != "void") { if (cleanup_str == "") sw.Write ("return "); @@ -141,15 +141,15 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t}"); sw.WriteLine (); - sw.WriteLine ("\t\tinternal {0} NativeDelegate;", wrapper); - sw.WriteLine ("\t\tprotected {0} _managed;", NS + "." + Name); + sw.WriteLine ("\t\tinternal " + wrapper + " NativeDelegate;"); + sw.WriteLine ("\t\t" + NS + "." + Name + " managed;"); sw.WriteLine (); - sw.WriteLine ("\t\tpublic {0} ({1} managed, object o) : base (o)", Name + "Wrapper", NS + "." + Name); + sw.WriteLine ("\t\tpublic " + Name + "Wrapper (" + NS + "." + Name + " managed)"); sw.WriteLine ("\t\t{"); - sw.WriteLine ("\t\t\tNativeDelegate = new {0} (NativeCallback);", wrapper); - sw.WriteLine ("\t\t\t_managed = managed;"); + sw.WriteLine ("\t\t\tNativeDelegate = new " + wrapper + " (NativeCallback);"); + sw.WriteLine ("\t\t\tthis.managed = managed;"); sw.WriteLine ("\t\t}"); sw.WriteLine ("\t}"); sw.WriteLine ("#endregion"); diff --git a/generator/MethodBody.cs b/generator/MethodBody.cs index b3a1c6ad4..eb8fdcf92 100644 --- a/generator/MethodBody.cs +++ b/generator/MethodBody.cs @@ -137,13 +137,14 @@ namespace GtkSharp.Generation { if (gen is CallbackGen) { + //Console.WriteLine ("***Callback parameter " + gen.Name + " generated in method***" ); CallbackGen cbgen = gen as CallbackGen; string wrapper = cbgen.GenWrapper(impl_ns, gen_info); sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = null;", wrapper, name); sw.Write (indent + "\t\t\t"); if (p.NullOk) sw.Write ("if ({0} != null) ", name); - sw.WriteLine ("{1}_wrapper = new {0} ({1}, {2});", wrapper, p.Name, parameters.Static ? "null" : "this"); + sw.WriteLine ("{1}_wrapper = new {0} ({1});", wrapper, p.Name); } } diff --git a/glade/XML.custom b/glade/XML.custom index 0e0e8d7d5..dbfb53196 100644 --- a/glade/XML.custom +++ b/glade/XML.custom @@ -32,7 +32,7 @@ static public void SetCustomHandler (Glade.XMLCustomWidgetHandler handler) { - callback_wrapper = new GladeSharp.XMLCustomWidgetHandlerWrapper (handler, null); + callback_wrapper = new GladeSharp.XMLCustomWidgetHandlerWrapper (handler); glade_set_custom_handler (callback_wrapper.NativeDelegate, IntPtr.Zero); } diff --git a/glib/DelegateWrapper.cs b/glib/DelegateWrapper.cs index 4bd8fc227..1b3f16c49 100644 --- a/glib/DelegateWrapper.cs +++ b/glib/DelegateWrapper.cs @@ -44,6 +44,7 @@ namespace GLib { // derived class or null if created from a static method. // Note that the instances will never be disposed if they are created in a static // method. + [Obsolete ("Callback wrappers should be manually managed for persistence.")] protected DelegateWrapper (object o) { if (o != null) { diff --git a/gnome/PanelAppletFactory.cs b/gnome/PanelAppletFactory.cs index f90ac37b0..395c9eb42 100644 --- a/gnome/PanelAppletFactory.cs +++ b/gnome/PanelAppletFactory.cs @@ -1,3 +1,25 @@ +// Gnome.PanelAppletFactory.cs - PanelAppletFactory class impl +// +// Copyright (c) 2004-2005 Novell, Inc. +// +// This code is inserted after the automatically generated code. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the Lesser GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + + using System; using System.Reflection; using System.Runtime.InteropServices; @@ -16,7 +38,7 @@ namespace Gnome { PanelApplet applet = (PanelApplet) Activator.CreateInstance (applet_type, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null, new object[] {IntPtr.Zero}, null); - cb_wrapper = new GnomeSharp.PanelAppletFactoryCallbackWrapper (new PanelAppletFactoryCallback (Creation), null); + cb_wrapper = new GnomeSharp.PanelAppletFactoryCallbackWrapper (new PanelAppletFactoryCallback (Creation)); _IID = applet.IID; _factoryIID = applet.FactoryIID; IntPtr native_iid = GLib.Marshaller.StringToPtrGStrdup (_factoryIID); diff --git a/gtk/Accel.custom b/gtk/Accel.custom index e2d13bcff..44482bea2 100644 --- a/gtk/Accel.custom +++ b/gtk/Accel.custom @@ -44,7 +44,7 @@ [Obsolete("Moved to AccelMap class. Use AccelMap.ForeachUnfiltered instead")] public static void MapForeachUnfiltered(IntPtr data, Gtk.AccelMapForeach foreach_func) { GtkSharp.AccelMapForeachWrapper foreach_func_wrapper = null; - foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func, null); + foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func); gtk_accel_map_foreach_unfiltered(data, foreach_func_wrapper.NativeDelegate); } @@ -112,7 +112,7 @@ [Obsolete("Moved to AccelMap class. Use AccelMap.Foreach instead")] public static void MapForeach(IntPtr data, Gtk.AccelMapForeach foreach_func) { GtkSharp.AccelMapForeachWrapper foreach_func_wrapper = null; - foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func, null); + foreach_func_wrapper = new GtkSharp.AccelMapForeachWrapper (foreach_func); gtk_accel_map_foreach(data, foreach_func_wrapper.NativeDelegate); } diff --git a/gtk/CellView.custom b/gtk/CellView.custom index e2f72c852..edaef28f5 100644 --- a/gtk/CellView.custom +++ b/gtk/CellView.custom @@ -54,7 +54,7 @@ gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } else { - GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func, this); + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); DataFuncs [renderer] = func_wrapper; gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); } diff --git a/gtk/ComboBox.custom b/gtk/ComboBox.custom index fafc87f2f..c366d0029 100644 --- a/gtk/ComboBox.custom +++ b/gtk/ComboBox.custom @@ -54,7 +54,7 @@ gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } else { - GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func, this); + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); DataFuncs [renderer] = func_wrapper; gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); } diff --git a/gtk/EntryCompletion.custom b/gtk/EntryCompletion.custom index 6d434961a..29ad95253 100644 --- a/gtk/EntryCompletion.custom +++ b/gtk/EntryCompletion.custom @@ -54,7 +54,7 @@ gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } else { - GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func, this); + GtkSharp.CellLayoutDataFuncWrapper func_wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); DataFuncs [renderer] = func_wrapper; gtk_cell_layout_set_cell_data_func (Handle, renderer.Handle, func_wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); } diff --git a/gtk/NodeCellDataFunc.cs b/gtk/NodeCellDataFunc.cs index a1f8405a4..e79bcf3d9 100644 --- a/gtk/NodeCellDataFunc.cs +++ b/gtk/NodeCellDataFunc.cs @@ -26,7 +26,7 @@ namespace Gtk { public delegate void NodeCellDataFunc (TreeViewColumn tree_column, CellRenderer cell, ITreeNode node); - internal class NodeCellDataFuncWrapper : GLib.DelegateWrapper { + internal class NodeCellDataFuncWrapper { public void NativeCallback (IntPtr tree_column, IntPtr cell, IntPtr tree_model, ref Gtk.TreeIter iter, IntPtr data) { @@ -39,7 +39,7 @@ namespace Gtk { internal GtkSharp.CellLayoutDataFuncNative NativeDelegate; protected NodeCellDataFunc managed; - public NodeCellDataFuncWrapper (NodeCellDataFunc managed, object o) : base (o) + public NodeCellDataFuncWrapper (NodeCellDataFunc managed) { NativeDelegate = new GtkSharp.CellLayoutDataFuncNative (NativeCallback); this.managed = managed; diff --git a/gtk/Toolbar.custom b/gtk/Toolbar.custom index 0b7c2f694..4e0d06fd3 100644 --- a/gtk/Toolbar.custom +++ b/gtk/Toolbar.custom @@ -47,7 +47,7 @@ public Gtk.Widget AppendElement (Gtk.ToolbarChildType type, Gtk.Widget widget, string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -72,7 +72,7 @@ public Gtk.Widget InsertElement (Gtk.ToolbarChildType type, Gtk.Widget widget, string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb, IntPtr user_data, int position) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -98,7 +98,7 @@ public Gtk.Widget PrependElement (Gtk.ToolbarChildType type, Gtk.Widget widget, string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -123,7 +123,7 @@ public Gtk.Widget AppendItem (string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -148,7 +148,7 @@ public Gtk.Widget InsertItem (string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb, IntPtr user_data, int position) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -173,7 +173,7 @@ public Gtk.Widget PrependItem (string text, string tooltip_text, string tooltip_private_text, Gtk.Widget icon, Gtk.SignalFunc cb) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr ntext = GLib.Marshaller.StringToPtrGStrdup (text); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); @@ -204,7 +204,7 @@ public Gtk.Widget InsertStock (string stock_id, string tooltip_text, string tooltip_private_text, Gtk.SignalFunc cb, IntPtr user_data, int position) { GtkSharp.SignalFuncWrapper cb_wrapper = null; - cb_wrapper = new GtkSharp.SignalFuncWrapper (cb, this); + cb_wrapper = new GtkSharp.SignalFuncWrapper (cb); IntPtr nstock = GLib.Marshaller.StringToPtrGStrdup (stock_id); IntPtr ntiptext = GLib.Marshaller.StringToPtrGStrdup (tooltip_text); IntPtr ntipprivtext = GLib.Marshaller.StringToPtrGStrdup (tooltip_private_text); diff --git a/gtk/TreeViewColumn.custom b/gtk/TreeViewColumn.custom index 6b71830e7..abc8c37c4 100644 --- a/gtk/TreeViewColumn.custom +++ b/gtk/TreeViewColumn.custom @@ -98,7 +98,7 @@ return; } ; - GtkSharp.TreeCellDataFuncWrapper wrapper = new GtkSharp.TreeCellDataFuncWrapper (func, this); + GtkSharp.TreeCellDataFuncWrapper wrapper = new GtkSharp.TreeCellDataFuncWrapper (func); CellDataFuncs [cell_renderer.Handle] = wrapper; gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); } @@ -109,7 +109,7 @@ return; } ; - GtkSharp.CellLayoutDataFuncWrapper wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func, this); + GtkSharp.CellLayoutDataFuncWrapper wrapper = new GtkSharp.CellLayoutDataFuncWrapper (func); CellDataFuncs [cell_renderer.Handle] = wrapper; gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); } @@ -121,7 +121,7 @@ return; } ; - NodeCellDataFuncWrapper wrapper = new NodeCellDataFuncWrapper (func, this); + NodeCellDataFuncWrapper wrapper = new NodeCellDataFuncWrapper (func); CellDataFuncs [cell_renderer.Handle] = wrapper; gtk_tree_view_column_set_cell_data_func(Handle, cell_renderer.Handle, wrapper.NativeDelegate, IntPtr.Zero, IntPtr.Zero); }