From 32ae593a0e0e50470acf37fc4f906669d1fe14bb Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Thu, 12 Sep 2002 05:21:16 +0000 Subject: [PATCH] 2002-09-11 Rachel Hestilow * glib/Object.cs (Ref): Added. * gtk/Object.custom (Ref): Overload. Note that we were reffed. (DisposeNative): Unref if we were explicitly reffed. * generator/Method.cs: Call Ref if needs_ret is set. * generator/StructBase.cs: Call Ref on all object accessors. * glue/style.c: Ref returned GCs. * sources/Gtk.metadata: Set needs_ret on various gdk-related accessors in GtkWidget. Hide Ref/Unref methods on Widget and RcStyle as these ought to be deprecated anyway. svn path=/trunk/gtk-sharp/; revision=7380 --- ChangeLog | 16 ++++++++++++++++ api/gtk-api.xml | 24 ++++++++++++------------ generator/Method.cs | 7 +++++++ generator/StructBase.cs | 13 +++++++++++-- glib/Object.cs | 20 ++++++++++++++++++++ glue/style.c | 4 ++++ gtk/Object.custom | 13 ++++++++++++- sources/Gtk.metadata | 28 ++++++++++++++++++++++++++++ 8 files changed, 110 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e47de4c3..b01e9289f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2002-09-11 Rachel Hestilow + + * glib/Object.cs (Ref): Added. + + * gtk/Object.custom (Ref): Overload. Note that we were reffed. + (DisposeNative): Unref if we were explicitly reffed. + + * generator/Method.cs: Call Ref if needs_ret is set. + * generator/StructBase.cs: Call Ref on all object accessors. + + * glue/style.c: Ref returned GCs. + + * sources/Gtk.metadata: Set needs_ret on various gdk-related + accessors in GtkWidget. Hide Ref/Unref methods on Widget and + RcStyle as these ought to be deprecated anyway. + 2002-09-11 Rodrigo Moya * gnomedb/Makefile.in: diff --git a/api/gtk-api.xml b/api/gtk-api.xml index b891aee94..51b6c07ab 100644 --- a/api/gtk-api.xml +++ b/api/gtk-api.xml @@ -5453,10 +5453,10 @@ - + - + @@ -9420,22 +9420,22 @@ - + - + - + - + @@ -9447,7 +9447,7 @@ - + @@ -9459,7 +9459,7 @@ - + @@ -9479,7 +9479,7 @@ - + @@ -9488,7 +9488,7 @@ - + @@ -9625,7 +9625,7 @@ - + @@ -9863,7 +9863,7 @@ - + diff --git a/generator/Method.cs b/generator/Method.cs index 61772a417..d1c7e6d86 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -25,6 +25,7 @@ namespace GtkSharp.Generation { private string name, cname, safety; private string protection = "public"; private bool is_get, is_set; + private bool needs_ref = false; public Method (string libname, XmlElement elem, ClassBase container_type) { @@ -40,6 +41,10 @@ namespace GtkSharp.Generation { this.libname = elem.GetAttribute ("library"); else this.libname = libname; + + // caller does not own reference? + if (elem.HasAttribute ("needs_ref")) + this.needs_ref = (elem.GetAttribute ("needs_ref") == "1"); } public bool IsGetter { @@ -387,6 +392,8 @@ namespace GtkSharp.Generation { { sw.WriteLine(m_ret + " raw_ret = " + cname + call + ";"); sw.WriteLine(indent +"\t\t\t" + s_ret + " ret = " + SymbolTable.FromNativeReturn(rettype, "raw_ret") + ";"); + if (needs_ref) + sw.WriteLine(indent + "\t\t\tret.Ref ();"); if (SymbolTable.IsOpaque (rettype)) sw.WriteLine(indent + "\t\t\tif (ret == null) ret = new " + s_ret + "(raw_ret);"); } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index f6ff864b3..ea3bc894c 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -152,8 +152,17 @@ namespace GtkSharp.Generation { string wrapped = SymbolTable.GetCSType (c_type); string wrapped_name = MangleName (field.GetAttribute ("cname")); - if (SymbolTable.IsObject (c_type) || SymbolTable.IsOpaque (c_type)) { - // FIXME: cut n paste code, remove after introspection completed + if (SymbolTable.IsObject (c_type)) { + sw.WriteLine (); + sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); + sw.WriteLine ("\t\t\tget { "); + sw.WriteLine ("\t\t\t\t" + wrapped + " ret = " + SymbolTable.FromNativeReturn(c_type, name) + ";"); + sw.WriteLine ("\t\t\t\tret.Ref ();"); + sw.WriteLine ("\t\t\t\treturn ret;"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine ("\t\t\tset { " + name + " = " + SymbolTable.CallByName (c_type, "value") + "; }"); + sw.WriteLine ("\t\t}"); + } else if (SymbolTable.IsOpaque (c_type)) { sw.WriteLine (); sw.WriteLine ("\t\tpublic " + wrapped + " " + wrapped_name + " {"); sw.WriteLine ("\t\t\tget { "); diff --git a/glib/Object.cs b/glib/Object.cs index 09d4ff1c1..25e09f6f8 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -64,6 +64,26 @@ namespace GLib { g_object_unref (_obj); } + [DllImport("gobject-2.0")] + static extern void g_object_ref (IntPtr raw); + + /// + /// Ref Method + /// + /// + /// + /// Increases the reference count on the native object. + /// This method is used by generated classes and structs, + /// and should not be used in user code. + /// + public virtual void Ref () + { + if (_obj == IntPtr.Zero) + return; + + g_object_ref (_obj); + } + /// /// GetObject Shared Method /// diff --git a/glue/style.c b/glue/style.c index 02d800862..60cd2cb1d 100644 --- a/glue/style.c +++ b/glue/style.c @@ -12,24 +12,28 @@ GdkGC* gtksharp_gtk_style_get_white_gc (GtkStyle *style) { + g_object_ref (G_OBJECT (style->white_gc)); return style->white_gc; } GdkGC* gtksharp_gtk_style_get_black_gc (GtkStyle *style) { + g_object_ref (G_OBJECT (style->black_gc)); return style->black_gc; } GdkGC** gtksharp_gtk_style_get_fg_gc (GtkStyle *style) { + g_object_ref (G_OBJECT (style->fg_gc)); return style->fg_gc; } GdkGC** gtksharp_gtk_style_get_bg_gc (GtkStyle *style) { + g_object_ref (G_OBJECT (style->bg_gc)); return style->bg_gc; } diff --git a/gtk/Object.custom b/gtk/Object.custom index d53d9a960..c121d571d 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -12,6 +12,17 @@ protected override void DisposeNative () { - gtksharp_object_unref_if_floating (Handle); + if (_needs_unref) + base.DisposeNative (); + else + gtksharp_object_unref_if_floating (Handle); } + private bool _needs_unref = false; + + public override void Ref () + { + _needs_unref = true; + base.Ref (); + } + diff --git a/sources/Gtk.metadata b/sources/Gtk.metadata index 08b20c88d..5706daf07 100644 --- a/sources/Gtk.metadata +++ b/sources/Gtk.metadata @@ -1254,6 +1254,12 @@ Destroyed + Ref + Unref + + + Ref + Unref @@ -1834,4 +1840,26 @@ + + + + + GetStyle + GetModifierStyle + GetDefaultStyle + GetParentWindow + GetColormap + GetVisual + GetDefaultColormap + GetDefaultVisual + + + + needs_ref + 1 + + + + +