Add method GetRawOwnedObject to Builder.

This method performs a GetRawObject, but also increases the refcount.

This is (at least) needed in cases where you wish to have a class inherting a widget,
and use a builder in the constructor : base (builder.GetRawObject("name"))
Because no ref is taken the eventual freeing of the builder will cause the our object (this)
to have a refcount 0.
This is an issue since the freeing of our ToggleRef (which should happen later) performs an unref.
This commit is contained in:
Mads Kruse Johnsen 2021-01-25 12:29:04 +01:00
parent 41d6f0bf28
commit 0daa985316

View file

@ -151,6 +151,16 @@ namespace Gtk {
GLib.Marshaller.Free (native_name); GLib.Marshaller.Free (native_name);
return raw_ret; return raw_ret;
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate IntPtr d_g_object_ref(IntPtr raw);
static d_g_object_ref g_object_ref = FuncLoader.LoadFunction<d_g_object_ref>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GObject), "g_object_ref"));
public IntPtr GetRawOwnedObject(string name) {
IntPtr raw_ret = GetRawObject (name);
g_object_ref (raw_ret);
return raw_ret;
}
public Builder (System.IO.Stream s) : this (s, null) public Builder (System.IO.Stream s) : this (s, null)
{ {