+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/gir-files
15 changes: 15 additions & 0 deletions src/Generation/Generator/Fixer/Alias/DisableGObjectGTypeAlias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Generator.Fixer.Record;

/// <summary>
/// The alias is added manually in GLib (as GObject.Type) as GLib needs a GType.
/// </summary>
internal class DisableGObjectGTypeAlias : Fixer<GirModel.Alias>
{
public void Fixup(GirModel.Alias alias)
{
if (alias is { Name: "Type", Namespace.Name: "GObject" })
{
Model.Alias.Disable(alias);
}
}
}
19 changes: 19 additions & 0 deletions src/Generation/Generator/Fixer/Aliases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using Generator.Fixer.Record;

namespace Generator.Fixer;

public static class Aliases
{
private static readonly List<Fixer<GirModel.Alias>> Fixers = new()
{
new DisableGObjectGTypeAlias()
};

public static void Fixup(IEnumerable<GirModel.Alias> aliases)
{
foreach (var alias in aliases)
foreach (var fixer in Fixers)
fixer.Fixup(alias);
}
}
4 changes: 4 additions & 0 deletions src/Generation/Generator/Generator/Public/AliasPointer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Generator.Model;

namespace Generator.Generator.Public;

Expand All @@ -18,6 +19,9 @@ public void Generate(GirModel.Alias obj)
if (obj.Type is not GirModel.Pointer)
return;

if (!Alias.IsEnabled(obj))
return;

var source = Renderer.Public.AliasPointer.Render(obj);
var codeUnit = new CodeUnit(
Project: Model.Namespace.GetCanonicalName(obj.Namespace),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Generator.Model;

namespace Generator.Generator.Public;

Expand All @@ -18,6 +19,9 @@ public void Generate(GirModel.Alias obj)
if (obj.Type is not GirModel.PrimitiveValueType)
return;

if (!Alias.IsEnabled(obj))
return;

var source = Renderer.Public.AliasPrimitiveValueType.Render(obj);
var codeUnit = new CodeUnit(
Project: Model.Namespace.GetCanonicalName(obj.Namespace),
Expand Down
22 changes: 22 additions & 0 deletions src/Generation/Generator/Model/Alias.Disable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;

namespace Generator.Model;

internal static partial class Alias
{
private static readonly HashSet<GirModel.Alias> DisabledAliases = new();

public static void Disable(GirModel.Alias alias)
{
lock (DisabledAliases)
{
DisabledAliases.Add(alias);
}
}

public static bool IsEnabled(GirModel.Alias alias)
{
//Does not need a lock as it is called only after all insertions are done.
return !DisabledAliases.Contains(alias);
}
}
8 changes: 3 additions & 5 deletions src/Generation/GirLoader/Output/GTypeAlias.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
namespace GirLoader.Output;

/// <summary>
/// This is an alias definition for "GType" in the GObject repository. As cairo does not include GObject
/// the alias "GObject.Type" is unknown which leads to missing GetGType methods for cairo. Adding
/// a typ named "GType" results in the alias being available as a global fallback which helps cairo.
///
/// TODO: Only needed until https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/396 is merged
/// This is an alias definition for "GType" in GLib. The GLib package is dependent on this
/// type but the type is only defined in GObject. Thus the alisas is added manually here and
/// the GObject implementation get's disabled in a Generator fixer.
/// </summary>
public class GTypeAlias : Type, GirModel.Alias
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public GlobalTypeCache()
Add(new Output.Utf8String());
Add(new Output.PlatformString());

Add(new Output.GTypeAlias()); //TODO: Only needed until https://gitlab.gnome.org/GNOME/gobject-introspection/-/merge_requests/396 is merged
Add(new Output.GTypeAlias()); //Needed to have GType available in GLib as it is only defined in GObject
}
}
}
1 change: 1 addition & 0 deletions src/Generation/GirTool/PlatformGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void Fixup(Namespace @namespace)
Generator.Fixer.Bitfields.Fixup(@namespace.Bitfields);
Generator.Fixer.Classes.Fixup(@namespace.Classes);
Generator.Fixer.Records.Fixup(@namespace.Records);
Generator.Fixer.Aliases.Fixup(@namespace.Aliases);
}

public static void Generate(Namespace @namespace, string path)
Expand Down
2 changes: 1 addition & 1 deletion src/Libs/GLib-2.0/GLib-2.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GObject-2.0\Internal\ImportResolver.Generated.cs">
<Link>GObject\ImportResolver.Generated.cs</Link>
<Link>GObject\Internal\ImportResolver.Generated.cs</Link>
</Compile>
</ItemGroup>
</Project>
17 changes: 0 additions & 17 deletions src/Libs/GLib-2.0/GObject/Functions.cs

This file was deleted.

27 changes: 27 additions & 0 deletions src/Libs/GLib-2.0/GObject/Internal/BasicType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace GObject.Internal;

public enum BasicType
{
Invalid = 0 << 2,
None = 1 << 2,
Interface = 2 << 2,
Char = 3 << 2,
UChar = 4 << 2,
Boolean = 5 << 2,
Int = 6 << 2,
UInt = 7 << 2,
Long = 8 << 2,
ULong = 9 << 2,
Int64 = 10 << 2,
UInt64 = 11 << 2,
Enum = 12 << 2,
Flags = 13 << 2,
Float = 14 << 2,
Double = 15 << 2,
String = 16 << 2,
Pointer = 17 << 2,
Boxed = 18 << 2,
Param = 19 << 2,
Object = 20 << 2,
Variant = 21 << 2
}
26 changes: 26 additions & 0 deletions src/Libs/GLib-2.0/GObject/Internal/Functions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Runtime.InteropServices;

/*
* Important: This are functions which are part of GObject but made available manually in GLib
*/

namespace GObject.Internal;

internal static class Functions
{
[DllImport(ImportResolver.Library, EntryPoint = "g_boxed_copy")]
public static extern IntPtr BoxedCopy(nuint boxedType, IntPtr srcBoxed);

[DllImport(ImportResolver.Library, EntryPoint = "g_boxed_free")]
public static extern void BoxedFree(nuint boxedType, IntPtr boxed);

[DllImport(ImportResolver.Library, EntryPoint = "g_type_name")]
public static extern GLib.Internal.NullableUtf8StringUnownedHandle TypeName(GObject.Type type);

// "g_strv_get_type" method is defined in GLib gir file but is
// historically part of the GObject shared library. This is
// why it is defined manually here.
[DllImport(ImportResolver.Library, EntryPoint = "g_strv_get_type")]
public static extern nuint StrvGetType();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
namespace GObject;
using System.Runtime.InteropServices;

public partial struct Type
namespace GObject;

[StructLayout(LayoutKind.Explicit)]
public struct Type
{

//This is a manual implementation of GObject.Type inside GLib project inside the GObject namespace.
//The GType alias definition in GObject is disabled through a fixer and the loader has a manual
//written resolver for this type so that GLib apis can use GObject.Type.

public nuint Value => _value;

#region Statics
Expand Down Expand Up @@ -32,10 +40,20 @@ public partial struct Type

#endregion Statics

//Offsets see: https://gitlab.gnome.org/GNOME/glib/blob/master/gobject/gtype.h

[FieldOffset(0)] private readonly nuint _value;

public Type(nuint value)
{
_value = value;
}

public override string? ToString()
{
return Internal.Functions.TypeName(_value).ConvertToString();
}

//Offsets see: https://gitlab.gnome.org/GNOME/glib/blob/master/gobject/gtype.h
public static implicit operator nuint(Type o) => o._value;
public static implicit operator Type(nuint o) => new Type(o);
}
34 changes: 34 additions & 0 deletions src/Libs/GLib-2.0/Internal/AllocatorHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;

namespace GLib.Internal;

public partial class AllocatorHandle
{
public partial AllocatorOwnedHandle OwnedCopy()
{
throw new NotSupportedException($"Can't create a copy of a {nameof(AllocatorHandle)}.");
}

public partial AllocatorUnownedHandle UnownedCopy()
{
throw new NotSupportedException($"Can't create a copy of a {nameof(AllocatorHandle)}.");
}
}

public partial class AllocatorOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "g_allocator_free")]
private static extern void Free(IntPtr queue);

public static partial AllocatorOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotSupportedException($"Can't create a copy of a {nameof(AllocatorHandle)}.");
}

protected override partial bool ReleaseHandle()
{
Free(handle);
return true;
}
}
36 changes: 36 additions & 0 deletions src/Libs/GLib-2.0/Internal/CacheHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Runtime.InteropServices;

namespace GLib.Internal;

public partial class CacheHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "g_async_queue_ref")]
protected static extern IntPtr Ref(IntPtr queue);

public partial CacheOwnedHandle OwnedCopy()
{
throw new NotSupportedException($"Can't create a copy of a {nameof(CacheHandle)}.");
}

public partial CacheUnownedHandle UnownedCopy()
{
throw new NotSupportedException($"Can't create a copy of a {nameof(CacheHandle)}.");
}
}

public partial class CacheOwnedHandle
{
[DllImport(ImportResolver.Library, EntryPoint = "g_async_queue_unref")]
private static extern void Unref(IntPtr queue);

public static partial CacheOwnedHandle FromUnowned(IntPtr ptr)
{
throw new NotSupportedException($"Can't create a copy of a {nameof(CacheHandle)}.");
}

protected override partial bool ReleaseHandle()
{
throw new NotSupportedException($"Can't release a {nameof(CacheHandle)}.");
}
}
34 changes: 0 additions & 34 deletions src/Libs/GLib-2.0/Internal/DirHandle.cs

This file was deleted.

37 changes: 0 additions & 37 deletions src/Libs/GLib-2.0/Internal/HmacHandle.cs

This file was deleted.

Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载