2c180f62d9
- Moves interop functions to UnmanagedCallbacks struct that contains the function pointers and is passed to C#. - Implements UnmanagedCallbacksGenerator, a C# source generator that generates the UnmanagedCallbacks struct in C# and the body for the NativeFuncs methods (their implementation just calls the function pointer in the UnmanagedCallbacks). The generated methods are needed because .NET pins byref parameters of native calls, even if they are 'ref struct's, which don't need pinning. The generated methods use `Unsafe.AsPointer` so that we can benefit from byref parameters without suffering overhead of pinning. Co-authored-by: Raul Santos <raulsntos@gmail.com>
25 lines
730 B
C#
25 lines
730 B
C#
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using Microsoft.CodeAnalysis;
|
|
|
|
namespace Godot.SourceGenerators.Internal;
|
|
|
|
internal struct CallbacksData
|
|
{
|
|
public CallbacksData(INamedTypeSymbol nativeTypeSymbol, INamedTypeSymbol funcStructSymbol)
|
|
{
|
|
NativeTypeSymbol = nativeTypeSymbol;
|
|
FuncStructSymbol = funcStructSymbol;
|
|
Methods = NativeTypeSymbol.GetMembers()
|
|
.Where(symbol => symbol is IMethodSymbol { IsPartialDefinition: true })
|
|
.Cast<IMethodSymbol>()
|
|
.ToImmutableArray();
|
|
}
|
|
|
|
public INamedTypeSymbol NativeTypeSymbol { get; }
|
|
|
|
public INamedTypeSymbol FuncStructSymbol { get; }
|
|
|
|
public ImmutableArray<IMethodSymbol> Methods { get; }
|
|
}
|