From 0daa9853166a886005a6219862da5a4c9ce1c296 Mon Sep 17 00:00:00 2001 From: Mads Kruse Johnsen Date: Mon, 25 Jan 2021 12:29:04 +0100 Subject: [PATCH] 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. --- Source/Libs/GtkSharp/Builder.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Libs/GtkSharp/Builder.cs b/Source/Libs/GtkSharp/Builder.cs index c09fff6cd..9e6234d5c 100644 --- a/Source/Libs/GtkSharp/Builder.cs +++ b/Source/Libs/GtkSharp/Builder.cs @@ -151,6 +151,16 @@ namespace Gtk { GLib.Marshaller.Free (native_name); return raw_ret; } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate IntPtr d_g_object_ref(IntPtr raw); + static d_g_object_ref g_object_ref = FuncLoader.LoadFunction(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) {