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.
This commit is contained in:
Bertrand Lorentz 2011-06-11 19:08:21 +02:00
parent f3c7384701
commit 680dd23965
2 changed files with 37 additions and 29 deletions

View File

@ -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);
}
}
}
}
}

View File

@ -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);
}
}
}