未验证 提交 f1e6a83b 编写于 作者: J Jackson Schuster 提交者: GitHub

Rename ManagedVirtualMethodTable and adjust VTable indices (#83158)

上级 a92ed6e2
......@@ -134,7 +134,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
var syntax = (MethodDeclarationSyntax)interfaceData.Syntax.FindNode(locationInAttributeSyntax.SourceSpan);
var method = (IMethodSymbol)member;
Diagnostic? diagnostic = GetDiagnosticIfInvalidMethodForGeneration(syntax, method);
methods.Add((syntax, method, diagnostic is not null ? methodVtableOffset++ : 0, diagnostic));
methods.Add((syntax, method, diagnostic is null ? methodVtableOffset++ : 0, diagnostic));
}
}
}
......@@ -313,7 +313,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
private static void** m_vtable;
public static void* VirtualMethodTableManagedImplementation
public static void** ManagedVirtualMethodTable
{
get
{
......@@ -555,7 +555,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(Immutable
ReturnStatement(LiteralExpression(SyntaxKind.NullLiteralExpression)))));
}
// void** vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(<interfaceType>, sizeof(void*) * <interfaceMethodStubs.Array.Length>);
// void** vtable = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(<interfaceType>, sizeof(void*) * <max(vtableIndex) + 1>);
var vtableDeclarationStatement =
LocalDeclarationStatement(
VariableDeclaration(
......@@ -575,7 +575,7 @@ private static InterfaceDeclarationSyntax GenerateImplementationVTable(Immutable
BinaryExpression(
SyntaxKind.MultiplyExpression,
SizeOfExpression(PointerType(PredefinedType(Token(SyntaxKind.VoidKeyword)))),
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(interfaceMethodStubs.Length)))))))))));
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(1 + interfaceMethodStubs.Max(x => x.VtableIndexData.Index))))))))))));
var fillIUnknownSlots = Block()
.AddStatements(
......@@ -680,7 +680,7 @@ private static ClassDeclarationSyntax GenerateInterfaceInformation(ComInterfaceC
FieldDeclaration(VariableDeclaration(VoidStarStarSyntax, SingletonSeparatedList(VariableDeclarator(vtableFieldName))))
.AddModifiers(Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.StaticKeyword)),
// public static void* VirtualMethodTableManagedImplementation => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualMethodTable());
PropertyDeclaration(PointerType(PredefinedType(Token(SyntaxKind.VoidKeyword))), "VirtualMethodTableManagedImplementation")
PropertyDeclaration(VoidStarStarSyntax, "ManagedVirtualMethodTable")
.AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword))
.WithExpressionBody(
ArrowExpressionClause(
......
......@@ -6,8 +6,9 @@
namespace System.Runtime.InteropServices.Marshalling
{
public interface IIUnknownInterfaceType : IUnmanagedInterfaceType
public unsafe interface IIUnknownInterfaceType
{
public abstract static Guid Iid { get; }
public abstract static void** ManagedVirtualMethodTable { get; }
}
}
......@@ -21,6 +21,6 @@ public IUnknownDerivedAttribute()
public Type Implementation => typeof(TImpl);
/// <inheritdoc />
public unsafe void* VirtualMethodTableManagedImplementation => T.VirtualMethodTableManagedImplementation;
public unsafe void* VirtualMethodTableManagedImplementation => T.ManagedVirtualMethodTable;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册