From 6d71c665cdfb6344d16e5dbd10c97bf7c20f5e0f Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Sat, 21 Sep 2024 22:36:29 +0200 Subject: [PATCH 1/2] GObject.Type: Add IsFundamental method --- src/Libs/GObject-2.0/Internal/Functions.cs | 10 ++++++++++ .../Libs/GObject-2.0.Tests/Records/TypeTest.cs | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Libs/GObject-2.0/Internal/Functions.cs b/src/Libs/GObject-2.0/Internal/Functions.cs index 909f167c8..2a027e4a3 100644 --- a/src/Libs/GObject-2.0/Internal/Functions.cs +++ b/src/Libs/GObject-2.0/Internal/Functions.cs @@ -9,4 +9,14 @@ public partial class Functions // why it is defined manually here. [DllImport(ImportResolver.Library, EntryPoint = "g_strv_get_type")] internal static extern nuint StrvGetType(); + + /// + /// Returns whether the given type is a fundamental type. + /// + /// True if the type is fundamental otherwise false. + public static bool IsFundamental(nuint type) + { + //255 << 2 corresponds to G_TYPE_FUNDAMENTAL_MAX + return type <= (255 << 2); + } } diff --git a/src/Tests/Libs/GObject-2.0.Tests/Records/TypeTest.cs b/src/Tests/Libs/GObject-2.0.Tests/Records/TypeTest.cs index 8710a9768..2ca4b1a40 100644 --- a/src/Tests/Libs/GObject-2.0.Tests/Records/TypeTest.cs +++ b/src/Tests/Libs/GObject-2.0.Tests/Records/TypeTest.cs @@ -14,4 +14,17 @@ public void SizeOfTypeIs8() sizeof(Type).Should().Be(8); } } + + [TestMethod] + public void FundamentalTypesCanBeDetected() + { + //(255 << 2) => G_TYPE_FUNDAMENTAL_MAX + Internal.Functions.IsFundamental(255 << 2).Should().BeTrue(); + + //Fundamental types + Internal.Functions.IsFundamental(Object.GetGType().Value).Should().BeTrue(); + + //Non fundamental types + Internal.Functions.IsFundamental(Binding.GetGType().Value).Should().BeFalse(); + } } From 357a6bd0009fef430d9577d6f366f3fa95b6a171 Mon Sep 17 00:00:00 2001 From: badcel <1218031+badcel@users.noreply.github.com> Date: Sun, 22 Sep 2024 20:37:31 +0200 Subject: [PATCH 2/2] Internal functions: Make class static --- src/Generation/Generator/Renderer/Internal/GlobalFunctions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generation/Generator/Renderer/Internal/GlobalFunctions.cs b/src/Generation/Generator/Renderer/Internal/GlobalFunctions.cs index 492afd128..f811a4bc8 100644 --- a/src/Generation/Generator/Renderer/Internal/GlobalFunctions.cs +++ b/src/Generation/Generator/Renderer/Internal/GlobalFunctions.cs @@ -19,7 +19,7 @@ namespace {Namespace.GetInternalName(functions.First().Namespace)}; // AUTOGENERATED FILE - DO NOT MODIFY -public partial class Functions +public static partial class Functions {{ {Functions.Render(functions)} }}";