From 680dd23965b1edb0a667f5425edef39ffd0cc9c9 Mon Sep 17 00:00:00 2001 From: Bertrand Lorentz Date: Sat, 11 Jun 2011 19:08:21 +0200 Subject: [PATCH] Handle floating refs in InitiallyUnowned When Gtk.Object was removed, most of the code was moved to Gtk.Widget. But the part that deals with floating references actually belongs in Glib.InitiallyUnowned. This fixes various issues, in particular crashes in the TreeModelDemo sample. --- glib/InitiallyUnowned.cs | 37 +++++++++++++++++++++++++++++++++++++ gtk/Widget.custom | 29 ----------------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/glib/InitiallyUnowned.cs b/glib/InitiallyUnowned.cs index fcd5e5821..ddca29262 100644 --- a/glib/InitiallyUnowned.cs +++ b/glib/InitiallyUnowned.cs @@ -35,6 +35,43 @@ namespace GLib { } } + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + private static extern void g_object_ref_sink (IntPtr raw); + + protected override IntPtr Raw { + get { + return base.Raw; + } + set { + if (value != IntPtr.Zero) + g_object_ref_sink (value); + base.Raw = value; + } + } + + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern bool g_object_is_floating (IntPtr raw); + + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern void g_object_force_floating (IntPtr raw); + + [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] + static extern void g_object_unref (IntPtr raw); + + public bool IsFloating { + get { + return g_object_is_floating (Handle); + } + set { + if (value == true) { + if (!IsFloating) + g_object_force_floating (Handle); + } else { + g_object_ref_sink (Handle); + g_object_unref (Handle); + } + } + } } } diff --git a/gtk/Widget.custom b/gtk/Widget.custom index b64aafbb9..28dd96b6c 100644 --- a/gtk/Widget.custom +++ b/gtk/Widget.custom @@ -378,16 +378,11 @@ public void Path (out string path, out string path_reversed) base.Dispose (disposing); } - [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - private static extern void g_object_ref_sink (IntPtr raw); - protected override IntPtr Raw { get { return base.Raw; } set { - if (value != IntPtr.Zero) - g_object_ref_sink (value); base.Raw = value; if (value != IntPtr.Zero) InternalDestroyed += NativeDestroyHandler; @@ -404,27 +399,3 @@ public void Path (out string path, out string path_reversed) gtk_widget_destroy (Handle); InternalDestroyed -= NativeDestroyHandler; } - - [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern bool g_object_is_floating (IntPtr raw); - - [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_object_force_floating (IntPtr raw); - - [DllImport ("libgobject-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] - static extern void g_object_unref (IntPtr raw); - - public bool IsFloating { - get { - return g_object_is_floating (Handle); - } - set { - if (value == true) { - if (!IsFloating) - g_object_force_floating (Handle); - } else { - g_object_ref_sink (Handle); - g_object_unref (Handle); - } - } - }