From c70614ef45ba1768f44a601406d6db6d4800e22d Mon Sep 17 00:00:00 2001 From: Andoni Morales Alastruey Date: Wed, 26 Feb 2025 11:50:18 +0100 Subject: [PATCH 1/2] Add a configuration to disable finalization on main thread Some users of the bindings like GStreamer might not be running a main loop at all. This add a way to disable running the finalizers on the main thread. --- Source/glib/Object.cs | 6 ++++-- Source/glib/Opaque.cs | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/glib/Object.cs b/Source/glib/Object.cs index 3d3b29725..88454dbc7 100644 --- a/Source/glib/Object.cs +++ b/Source/glib/Object.cs @@ -8,7 +8,7 @@ // Copyright (c) 2013 Andres G. Aragoneses // // This program is free software; you can redistribute it and/or -// modify it under the terms of version 2 of the Lesser GNU General +// modify it under the terms of version 2 of the Lesser GNU General // Public License as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, @@ -66,7 +66,7 @@ protected virtual void Dispose(bool disposing) { if (tref == null) return; - if (disposing) + if (disposing || !FinalizeOnMainThread) tref.Dispose(); else tref.QueueUnref(); @@ -76,6 +76,8 @@ protected virtual void Dispose(bool disposing) { public static bool WarnOnFinalize { get; set; } + public static bool FinalizeOnMainThread { get; set; } = true; + [DllImport(Global.GObjectNativeDll, CallingConvention = CallingConvention.Cdecl)] static extern IntPtr g_object_ref(IntPtr raw); diff --git a/Source/glib/Opaque.cs b/Source/glib/Opaque.cs index 26593fae7..6a856bf4c 100644 --- a/Source/glib/Opaque.cs +++ b/Source/glib/Opaque.cs @@ -130,8 +130,12 @@ protected virtual void DisposeManagedResources() { protected virtual void DisposeUnmanagedResources() { if (!Owned || DisposeUnmanagedFunc == null) return; - FinalizerInfo info = new FinalizerInfo(DisposeUnmanagedFunc, Handle); - Timeout.Add(50, new TimeoutHandler(info.Handler)); + if (Object.FinalizeOnMainThread) { + FinalizerInfo info = new FinalizerInfo(DisposeUnmanagedFunc, Handle); + Timeout.Add(50, new TimeoutHandler(info.Handler)); + } else { + DisposeUnmanagedFunc(Handle); + } } protected internal bool Disposed { get; private set; } = false; From 500a53c0fcdc27d8894bbda55a5fbc7f6c965c34 Mon Sep 17 00:00:00 2001 From: Andoni Morales Alastruey Date: Wed, 26 Feb 2025 11:55:30 +0100 Subject: [PATCH 2/2] ci: fix pip deps installation --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dde212b46..4128707de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: if: matrix.config.os == 'ubuntu-latest' run: dotnet format Source/gtk-sharp.sln --verify-no-changes --no-restore - name: Install Deps - run: pip3 install meson ninja + run: pip3 install meson ninja --break-system-packages - name: Install Windows Deps if: matrix.config.os == 'windows-latest' run: choco install winflexbison3 pkgconfiglite -y --allow-empty-checksum