2009-01-29 Mike Kestner <mkestner@novell.com>

* 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
This commit is contained in:
Mike Kestner 2009-01-29 16:26:09 +00:00
parent 48da8afce6
commit bc188c9358
3 changed files with 43 additions and 24 deletions

View file

@ -1,3 +1,10 @@
2009-01-29 Mike Kestner <mkestner@novell.com>
* 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 <aaragoneses@novell.com>
* atk/Object.custom: add binding for "focus-event" signal:

View file

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

View file

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