-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new proposed API to Ancillary.Interop #81063
Conversation
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsAdds the new APIs from Jeremy's proposal to Ancillary.Interop project and makes the minimum changes not break the build and tests of the VTable generator.
|
...aries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/VTableGCHandlePair.cs
Outdated
Show resolved
Hide resolved
...InteropServices/tests/ComInterfaceGenerator.Unit.Tests/GeneratedComInterfaceAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
...aries/System.Runtime.InteropServices/tests/Ancillary.Interop/Marshalling/VTableExtensible.cs
Outdated
Show resolved
Hide resolved
…eGenerator.Tests/VTableGCHandlePair.cs Co-authored-by: Aaron Robinson <arobins@microsoft.com>
- Add license banner to new files - Change count to 0 for null VTables
… into vtableGenUpdate
...stem.Runtime.InteropServices/tests/Ancillary.Interop/IUnmanagedVirtualMethodTableProvider.cs
Show resolved
Hide resolved
...raries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/ImplicitThisTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Marshalling/Base.cs
Outdated
Show resolved
Hide resolved
- Move types to their own file and update comments - Re-add dereference to 'this' pointer for vtable
- Add license banner to new files - Change count to 0 for null VTables
…eGenerator.Tests/VTableGCHandlePair.cs Co-authored-by: Aaron Robinson <arobins@microsoft.com>
- Move types to their own file and update comments - Re-add dereference to 'this' pointer for vtable
… into vtableGenUpdate
ImplicitThisTests.cs generated code: // <auto-generated/> ManagedToNativeStubs.g.cs
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class ImplicitThis
{
internal unsafe partial interface INativeObject
{
internal unsafe partial interface Native
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
[System.Runtime.CompilerServices.SkipLocalsInitAttribute]
int INativeObject.GetData()
{
var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject));
int __retVal;
{
__retVal = ((delegate* unmanaged<void*, int> )__vtable_native[0])(__this);
}
return __retVal;
}
}
}
}
}
}
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class ImplicitThis
{
internal unsafe partial interface INativeObject
{
internal unsafe partial interface Native
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
[System.Runtime.CompilerServices.SkipLocalsInitAttribute]
void INativeObject.SetData(int x)
{
var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject));
{
((delegate* unmanaged<void*, int, void> )__vtable_native[1])(__this, x);
}
}
}
}
}
}
}
// <auto-generated/> NativeInterfaces.g.cs
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class ImplicitThis
{
internal unsafe partial interface INativeObject
{
[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute]
internal partial interface Native : INativeObject
{
}
}
}
}
}
// <auto-generated/> NativeToManagedStubs.g.cs
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class ImplicitThis
{
internal unsafe partial interface INativeObject
{
internal unsafe partial interface Native
{
[System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute]
internal static int ABI_GetData(void* __this_native)
{
global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this;
int __retVal = default;
// Unmarshal - Convert native data to managed data.
@this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper<ComInterfaceGenerator.Tests.VTableGCHandlePair<ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject>>(__this_native);
__retVal = @this.GetData();
return __retVal;
}
}
}
}
}
}
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class ImplicitThis
{
internal unsafe partial interface INativeObject
{
internal unsafe partial interface Native
{
[System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute]
internal static void ABI_SetData(void* __this_native, int x)
{
global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject @this;
// Unmarshal - Convert native data to managed data.
@this = (global::ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject)System.Runtime.InteropServices.Marshalling.UnmanagedObjectUnwrapper.GetObjectForUnmanagedWrapper<ComInterfaceGenerator.Tests.VTableGCHandlePair<ComInterfaceGenerator.Tests.NativeExportsNE.ImplicitThis.INativeObject>>(__this_native);
@this.SetData(x);
}
}
}
}
}
}
// <auto-generated/> PopulateVTable.g.cs
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class ImplicitThis
{
internal unsafe partial interface INativeObject
{
internal unsafe partial interface Native
{
internal static void PopulateUnmanagedVirtualMethodTable(void** vtable)
{
vtable[0] = (void*)(delegate* unmanaged<void*, int> )&ABI_GetData;
vtable[1] = (void*)(delegate* unmanaged<void*, int, void> )&ABI_SetData;
}
}
}
}
}
} NoImplicitThis.cs generated code: // <auto-generated/> NativeInterfaces.g.cs
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class NoImplicitThis
{
internal unsafe partial interface IStaticMethodTable
{
[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute]
internal partial interface Native : IStaticMethodTable
{
}
}
}
}
}
// <auto-generated/> ManagedToNativeStubs.g.cs
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class NoImplicitThis
{
internal unsafe partial interface IStaticMethodTable
{
internal unsafe partial interface Native
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
[System.Runtime.CompilerServices.SkipLocalsInitAttribute]
int IStaticMethodTable.Add(int x, int y)
{
var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.IStaticMethodTable));
int __retVal;
{
__retVal = ((delegate* unmanaged<int, int, int> )__vtable_native[0])(x, y);
}
return __retVal;
}
}
}
}
}
}
namespace ComInterfaceGenerator.Tests
{
internal unsafe partial class NativeExportsNE
{
internal unsafe partial class NoImplicitThis
{
internal unsafe partial interface IStaticMethodTable
{
internal unsafe partial interface Native
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
[System.Runtime.CompilerServices.SkipLocalsInitAttribute]
int IStaticMethodTable.Multiply(int x, int y)
{
var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.NoImplicitThis.IStaticMethodTable));
int __retVal;
{
__retVal = ((delegate* unmanaged<int, int, int> )__vtable_native[1])(x, y);
}
return __retVal;
}
}
}
}
}
} |
src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/InlinedTypes.cs
Outdated
Show resolved
Hide resolved
...nteropServices/gen/ComInterfaceGenerator/Marshallers/NativeToManagedThisMarshallerFactory.cs
Outdated
Show resolved
Hide resolved
...ystem.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
Outdated
Show resolved
Hide resolved
...ystem.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
Show resolved
Hide resolved
...ystem.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/PreserveSigMarshaller.cs
Outdated
Show resolved
Hide resolved
...raries/System.Runtime.InteropServices/tests/Ancillary.Interop/VirtualMethodIndexAttribute.cs
Outdated
Show resolved
Hide resolved
...aries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/VTableGCHandlePair.cs
Show resolved
Hide resolved
…erop.SourceGeneration/TypeSymbolExtensions.cs Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
...nteropServices/gen/ComInterfaceGenerator/Marshallers/NativeToManagedThisMarshallerFactory.cs
Outdated
Show resolved
Hide resolved
…enerator/Marshallers/NativeToManagedThisMarshallerFactory.cs Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more nit.
After that's fixed and the files are moved from file-scoped namespaces back to traditional namespaces, this will be ready to merge!
...nteropServices/gen/ComInterfaceGenerator/Marshallers/NativeToManagedThisMarshallerFactory.cs
Outdated
Show resolved
Hide resolved
…enerator/Marshallers/NativeToManagedThisMarshallerFactory.cs Co-authored-by: Jeremy Koritzinsky <jkoritzinsky@gmail.com>
src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/AssemblyInfo.cs
Outdated
Show resolved
Hide resolved
Looks like there were some conflicts from the COM source generator skeleton PR. Can we resolve those and retrigger CI? |
It looks like you need to build this locally to update the Xlf files. I know it's a pain, I wish we could cloud-automate it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor comments - nothing that I think is worth resetting CI for. Feel free to address in a future change.
@@ -207,6 +207,9 @@ | |||
<data name="InterfaceTypeNotSupportedMessage" xml:space="preserve"> | |||
<value>Using 'GeneratedComInterfaceAttribute' and 'InterfaceTypeAttribute' is not supported with 'ComInterfaceType' value '{0}'.</value> | |||
</data> | |||
<data name="InvalidAttributedMethodContainingTypeMissingUnmanagedObjectUnwrapperAttributeMessage" xml:space="preserve"> | |||
<value>Containing type of method with VirtualMethodIndexAttribute does not have a UnmanagedObjectUnwrapperAttribute. </value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: single quote around type names
@@ -3,6 +3,8 @@ | |||
|
|||
using System; | |||
using System.Diagnostics; | |||
using Microsoft.CodeAnalysis.CSharp.Syntax; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
public static bool IsOfType(this INamedTypeSymbol type, string typeName) | ||
{ | ||
if (typeName.Contains('<') || typeName.Contains('+') || typeName.Contains('/')) | ||
throw new ArgumentException($"Cannot handle type name in the format provided: {typeName}", nameof(typeName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newlines after the single-line blocks
@@ -45,6 +45,16 @@ public class Ids | |||
isEnabledByDefault: true, | |||
description: GetResourceString(nameof(SR.InvalidAttributedMethodDescription))); | |||
|
|||
public static readonly DiagnosticDescriptor InvalidAttributedMethodContainingTypeMissingUnmanagedObjectUnwrapperAttribute = | |||
new DiagnosticDescriptor( | |||
Ids.InvalidLibraryImportAttributeUsage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(for later change) We should probably have a different ID for the diagnostics here.
|
||
namespace Microsoft.Interop | ||
{ | ||
internal static class InlinedTypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is just prep for later? I don't see it used yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is unused but may be needed later.
Adds the new APIs from Jeremy's proposal to Ancillary.Interop project and makes the minimum changes not break the build and tests of the VTable generator.