2005-03-12 Mike Kestner <mkestner@novell.com>

* 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
This commit is contained in:
Mike Kestner 2005-03-12 18:54:53 +00:00
parent 8983ea960c
commit bd50999b1b
15 changed files with 66 additions and 32 deletions

View file

@ -1,3 +1,13 @@
2005-03-12 Mike Kestner <mkestner@novell.com>
* 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 <mkestner@novell.com>
* glib/DelegateWrapper.cs : call g_object_set_data_full since we are

View file

@ -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);

View file

@ -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);
}

View file

@ -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");

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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) {

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;

View file

@ -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);

View file

@ -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);
}