2005-09-27 Mike Kestner <mkestner@novell.com>

* glib/Opaque.cs : remove the Opaques hash.  As f-spot demonstrated,
	we cannot rely on a pointer continuing to point at the same type in
	memory, since there is no destroy notification for most opaques.
	* glib/Value.cs : use more explicit GetOpaque overload.
	* gtk/Style.custom : use more explicit GetOpaque overload.

svn path=/trunk/gtk-sharp/; revision=50884
This commit is contained in:
Mike Kestner 2005-09-27 19:12:43 +00:00
parent a02ae2bfd6
commit fede690a37
4 changed files with 14 additions and 28 deletions

View File

@ -1,3 +1,11 @@
2005-09-27 Mike Kestner <mkestner@novell.com>
* glib/Opaque.cs : remove the Opaques hash. As f-spot demonstrated,
we cannot rely on a pointer continuing to point at the same type in
memory, since there is no destroy notification for most opaques.
* glib/Value.cs : use more explicit GetOpaque overload.
* gtk/Style.custom : use more explicit GetOpaque overload.
2005-09-24 Christian Hergert <christian.hergert@gmail.com> 2005-09-24 Christian Hergert <christian.hergert@gmail.com>
* vte/Vte.metadata: Fix Vte.Terminal.SetColors to reflect proper mapping * vte/Vte.metadata: Fix Vte.Terminal.SetColors to reflect proper mapping

View File

@ -36,35 +36,15 @@ namespace GLib {
IntPtr _obj; IntPtr _obj;
bool owned; bool owned;
// We don't have to do as much work here as GLib.Object.GetObject [Obsolete ("Use more explicit overload. This method always returns null")]
// does; users can't subclass opaque types, so nothing bad will happen
// if we accidentally end up creating two wrappers for the same object.
static Hashtable Opaques = new Hashtable();
public static Opaque GetOpaque (IntPtr o) public static Opaque GetOpaque (IntPtr o)
{ {
WeakReference reference = (WeakReference) Opaques[o]; return null;
if (reference == null) }
return null;
if (!reference.IsAlive) {
Opaques.Remove (o);
return null;
}
return (Opaque) reference.Target;
}
public static Opaque GetOpaque (IntPtr o, Type type, bool owned) public static Opaque GetOpaque (IntPtr o, Type type, bool owned)
{ {
Opaque opaque = GetOpaque (o); Opaque opaque = (Opaque)Activator.CreateInstance (type, new object[] { o });
if (opaque != null) {
if (owned)
opaque.owned = true;
return opaque;
}
opaque = (Opaque)Activator.CreateInstance (type, new object[] { o });
if (owned) { if (owned) {
if (opaque.owned) { if (opaque.owned) {
// The constructor took a Ref it shouldn't have, so undo it // The constructor took a Ref it shouldn't have, so undo it
@ -92,7 +72,6 @@ namespace GLib {
} }
set { set {
if (_obj != IntPtr.Zero) { if (_obj != IntPtr.Zero) {
Opaques.Remove (_obj);
Unref (_obj); Unref (_obj);
if (owned) if (owned)
Free (_obj); Free (_obj);
@ -100,7 +79,6 @@ namespace GLib {
_obj = value; _obj = value;
if (_obj != IntPtr.Zero) { if (_obj != IntPtr.Zero) {
Ref (_obj); Ref (_obj);
Opaques [_obj] = new WeakReference (this);
} }
} }
} }

View File

@ -269,7 +269,7 @@ namespace GLib {
public static explicit operator GLib.Opaque (Value val) public static explicit operator GLib.Opaque (Value val)
{ {
return GLib.Opaque.GetOpaque (g_value_get_boxed (ref val)); return GLib.Opaque.GetOpaque (g_value_get_boxed (ref val), (Type) new GType (val.type), false);
} }
public static explicit operator GLib.Boxed (Value val) public static explicit operator GLib.Boxed (Value val)

View File

@ -363,7 +363,7 @@ public Pango.FontDescription FontDescription {
if (Raw == IntPtr.Zero) if (Raw == IntPtr.Zero)
return null; return null;
Pango.FontDescription ret = (Pango.FontDescription) GLib.Opaque.GetOpaque (Raw); Pango.FontDescription ret = (Pango.FontDescription) GLib.Opaque.GetOpaque (Raw, typeof (Pango.FontDescription), false);
if (ret == null) if (ret == null)
ret = new Pango.FontDescription (Raw); ret = new Pango.FontDescription (Raw);
return ret; return ret;