diff --git a/ChangeLog b/ChangeLog index c76bbd5f3..f6cc88b10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-09-27 Mike Kestner + + * 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 * vte/Vte.metadata: Fix Vte.Terminal.SetColors to reflect proper mapping diff --git a/glib/Opaque.cs b/glib/Opaque.cs index 2c44f389d..5b268407e 100644 --- a/glib/Opaque.cs +++ b/glib/Opaque.cs @@ -36,35 +36,15 @@ namespace GLib { IntPtr _obj; bool owned; - // We don't have to do as much work here as GLib.Object.GetObject - // 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(); - + [Obsolete ("Use more explicit overload. This method always returns null")] public static Opaque GetOpaque (IntPtr o) { - WeakReference reference = (WeakReference) Opaques[o]; - if (reference == null) - return null; - if (!reference.IsAlive) { - Opaques.Remove (o); - return null; - } + return null; + } - return (Opaque) reference.Target; - } - public static Opaque GetOpaque (IntPtr o, Type type, bool owned) { - Opaque opaque = GetOpaque (o); - if (opaque != null) { - if (owned) - opaque.owned = true; - return opaque; - } - - opaque = (Opaque)Activator.CreateInstance (type, new object[] { o }); + Opaque opaque = (Opaque)Activator.CreateInstance (type, new object[] { o }); if (owned) { if (opaque.owned) { // The constructor took a Ref it shouldn't have, so undo it @@ -92,7 +72,6 @@ namespace GLib { } set { if (_obj != IntPtr.Zero) { - Opaques.Remove (_obj); Unref (_obj); if (owned) Free (_obj); @@ -100,7 +79,6 @@ namespace GLib { _obj = value; if (_obj != IntPtr.Zero) { Ref (_obj); - Opaques [_obj] = new WeakReference (this); } } } diff --git a/glib/Value.cs b/glib/Value.cs index 0cba5b834..e6791a703 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -269,7 +269,7 @@ namespace GLib { 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) diff --git a/gtk/Style.custom b/gtk/Style.custom index 63cb26764..1fe9be6a9 100644 --- a/gtk/Style.custom +++ b/gtk/Style.custom @@ -363,7 +363,7 @@ public Pango.FontDescription FontDescription { if (Raw == IntPtr.Zero) 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) ret = new Pango.FontDescription (Raw); return ret;