From bc188c935838225ef866968bb2cbd48b8533c10e Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 29 Jan 2009 16:26:09 +0000 Subject: [PATCH] 2009-01-29 Mike Kestner * generator/OpaqueGen.cs: generate a finalizer for classes which have free or unref methods and ensure it runs on the gui thread. * glib/Opaque.cs: remove finalize handling. Fixes a 'resurrection' issue with the previous 419777 fix. svn path=/trunk/gtk-sharp/; revision=124940 --- ChangeLog | 7 +++++++ generator/OpaqueGen.cs | 34 ++++++++++++++++++++++++++++++++++ glib/Opaque.cs | 26 ++------------------------ 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index ffb13799a..69cef9253 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-01-29 Mike Kestner + + * generator/OpaqueGen.cs: generate a finalizer for classes which + have free or unref methods and ensure it runs on the gui thread. + * glib/Opaque.cs: remove finalize handling. + Fixes a 'resurrection' issue with the previous 419777 fix. + 2009-01-29 Andrés G. Aragoneses * atk/Object.custom: add binding for "focus-event" signal: diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index 6c2af67d1..ca5bf8627 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -96,6 +96,9 @@ namespace GtkSharp.Generation { sw.WriteLine (); } } + + bool finalizer_needed = false; + if (unref != null) { unref.GenerateImport (sw); sw.WriteLine ("\t\tprotected override void Unref (IntPtr raw)"); @@ -112,6 +115,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\tpublic void Unref () {}"); sw.WriteLine (); } + finalizer_needed = true; } if (dispose != null) { @@ -127,6 +131,36 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\tpublic void " + dispose.Name + " () {}"); sw.WriteLine (); } + finalizer_needed = true; + } + + if (finalizer_needed) { + sw.WriteLine ("\t\tclass FinalizerInfo {"); + sw.WriteLine ("\t\t\tIntPtr handle;"); + sw.WriteLine (); + sw.WriteLine ("\t\t\tpublic FinalizerInfo (IntPtr handle)"); + sw.WriteLine ("\t\t\t{"); + sw.WriteLine ("\t\t\t\tthis.handle = handle;"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine (); + sw.WriteLine ("\t\t\tpublic bool Handler ()"); + sw.WriteLine ("\t\t\t{"); + if (dispose != null) + sw.WriteLine ("\t\t\t\t{0} (handle);", dispose.CName); + else if (unref != null) + sw.WriteLine ("\t\t\t\t{0} (handle);", unref.CName); + sw.WriteLine ("\t\t\t\treturn false;"); + sw.WriteLine ("\t\t\t}"); + sw.WriteLine ("\t\t}"); + sw.WriteLine (); + sw.WriteLine ("\t\t~{0} ()", Name); + sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\tif (!Owned)"); + sw.WriteLine ("\t\t\t\treturn;"); + sw.WriteLine ("\t\t\tFinalizerInfo info = new FinalizerInfo (Handle);"); + sw.WriteLine ("\t\t\tGLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));"); + sw.WriteLine ("\t\t}"); + sw.WriteLine (); } #if false diff --git a/glib/Opaque.cs b/glib/Opaque.cs index 9b4e4bba8..4f37283bb 100644 --- a/glib/Opaque.cs +++ b/glib/Opaque.cs @@ -88,32 +88,10 @@ namespace GLib { } } - class FinalizeInfo { - Type type; - IntPtr native; - bool owned; - - public FinalizeInfo (Type type, IntPtr native, bool owned) - { - this.type = type; - this.native = native; - this.owned = owned; - } - - public bool Handler () - { - Opaque inst = GetOpaque (native, type, owned); - inst.Dispose (); - return false; - } - } - ~Opaque () { - if (_obj == IntPtr.Zero) - return; - FinalizeInfo info = new FinalizeInfo (GetType(), _obj, owned); - Timeout.Add (50, new TimeoutHandler (info.Handler)); + // for compat. All subclasses should have + // generated finalizers if needed now. } public virtual void Dispose ()