From b2f421f751daad266fc83d9d4a29c1295864b7ab Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 3 Apr 2023 16:06:26 -0700 Subject: [PATCH] Prepare ComInterfaceGenerator for going into the public API (#83894) --- .../ComInterfaceGenerator.cs | 2 +- .../ComInterfaceGeneratorHelpers.cs | 2 +- .../IncrementalMethodStubGenerationContext.cs | 2 +- .../ComInterfaceDispatchMarshallerFactory.cs | 69 +++++++++++++++++++ ...cs => ObjectUnwrapperMarshallerFactory.cs} | 12 ++-- .../VirtualMethodPointerStubGenerator.cs | 2 +- .../VtableIndexStubGenerator.cs | 6 +- .../VtableIndexStubGeneratorHelpers.cs | 66 ++++++++++++++++++ .../MarshallingAttributeInfo.cs | 12 ++-- .../TypeNames.cs | 8 +-- ...ler.cs => ExceptionAsDefaultMarshaller.cs} | 4 +- ...ler.cs => ExceptionAsHResultMarshaller.cs} | 4 +- ...shaller.cs => ExceptionAsNaNMarshaller.cs} | 4 +- ...haller.cs => ExceptionAsVoidMarshaller.cs} | 4 +- .../Compiles.cs | 2 +- 15 files changed, 167 insertions(+), 32 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs rename src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/{NativeToManagedThisMarshallerFactory.cs => ObjectUnwrapperMarshallerFactory.cs} (84%) create mode 100644 src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGeneratorHelpers.cs rename src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/{ExceptionDefaultMarshaller.cs => ExceptionAsDefaultMarshaller.cs} (91%) rename src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/{ExceptionHResultMarshaller.cs => ExceptionAsHResultMarshaller.cs} (95%) rename src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/{ExceptionNaNMarshaller.cs => ExceptionAsNaNMarshaller.cs} (92%) rename src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/{SwallowExceptionMarshaller.cs => ExceptionAsVoidMarshaller.cs} (90%) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs index 17704038a19bc..fc0d4c9c0ab7e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGenerator.cs @@ -456,7 +456,7 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M ComInterfaceGeneratorHelpers.CreateGeneratorFactory(environment, MarshalDirection.UnmanagedToManaged), typeKeyOwner, new SequenceEqualImmutableArray(generatorDiagnostics.Diagnostics.ToImmutableArray()), - ParseTypeName(TypeNames.ComWrappersUnwrapper)); + ComInterfaceDispatchMarshallingInfo.Instance); } private static Diagnostic? GetDiagnosticIfInvalidTypeForGeneration(InterfaceDeclarationSyntax syntax, INamedTypeSymbol type) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGeneratorHelpers.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGeneratorHelpers.cs index be826c0684d2e..e192fcd02d8fe 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGeneratorHelpers.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceGeneratorHelpers.cs @@ -58,7 +58,7 @@ internal static class ComInterfaceGeneratorHelpers generatorFactory = new ManagedHResultExceptionMarshallerFactory(generatorFactory, direction); - generatorFactory = new NativeToManagedThisMarshallerFactory(generatorFactory); + generatorFactory = new ComInterfaceDispatchMarshallerFactory(generatorFactory); generatorFactory = new ByValueContentsMarshalKindValidator(generatorFactory); diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/IncrementalMethodStubGenerationContext.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/IncrementalMethodStubGenerationContext.cs index 94f094ad5473b..7cd5842ba47c7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/IncrementalMethodStubGenerationContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/IncrementalMethodStubGenerationContext.cs @@ -22,5 +22,5 @@ internal sealed record IncrementalMethodStubGenerationContext( MarshallingGeneratorFactoryKey<(TargetFramework TargetFramework, Version TargetFrameworkVersion)> UnmanagedToManagedGeneratorFactory, ManagedTypeInfo TypeKeyOwner, SequenceEqualImmutableArray Diagnostics, - TypeSyntax UnwrapperSyntax) : GeneratedMethodContextBase(TypeKeyOwner, Diagnostics); + MarshallingInfo ManagedThisMarshallingInfo) : GeneratedMethodContextBase(TypeKeyOwner, Diagnostics); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs new file mode 100644 index 0000000000000..dc8dbe2de5fda --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ComInterfaceDispatchMarshallerFactory.cs @@ -0,0 +1,69 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +namespace Microsoft.Interop +{ + internal sealed record ComInterfaceDispatchMarshallingInfo : MarshallingInfo + { + public static readonly ComInterfaceDispatchMarshallingInfo Instance = new(); + } + + internal sealed class ComInterfaceDispatchMarshallerFactory : IMarshallingGeneratorFactory + { + private readonly IMarshallingGeneratorFactory _inner; + public ComInterfaceDispatchMarshallerFactory(IMarshallingGeneratorFactory inner) + { + _inner = inner; + } + + public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) + => info.MarshallingAttributeInfo is ComInterfaceDispatchMarshallingInfo ? new Marshaller() : _inner.Create(info, context); + + private sealed class Marshaller : IMarshallingGenerator + { + public ManagedTypeInfo AsNativeType(TypePositionInfo info) => + new PointerTypeInfo( + $"{TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch}*", + $"{TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch}*", + IsFunctionPointer: false); + public IEnumerable Generate(TypePositionInfo info, StubCodeContext context) + { + if (context.CurrentStage != StubCodeContext.Stage.Unmarshal) + { + yield break; + } + + var (managed, native) = context.GetIdentifiers(info); + + // = ComWrappers.ComInterfaceDispatch.GetInstance<>(); + yield return ExpressionStatement( + AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, + IdentifierName(managed), + InvocationExpression( + MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, + ParseName(TypeNames.System_Runtime_InteropServices_ComWrappers_ComInterfaceDispatch), + GenericName( + Identifier("GetInstance"), + TypeArgumentList(SingletonSeparatedList(info.ManagedType.Syntax)))), + ArgumentList( + SingletonSeparatedList( + Argument( + IdentifierName(native))))))); + } + + public SignatureBehavior GetNativeSignatureBehavior(TypePositionInfo info) => SignatureBehavior.NativeType; + public ValueBoundaryBehavior GetValueBoundaryBehavior(TypePositionInfo info, StubCodeContext context) => ValueBoundaryBehavior.NativeIdentifier; + public bool IsSupported(TargetFramework target, Version version) + => target == TargetFramework.Net && version >= new Version(5, 0); + public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) => false; + public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) => true; + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/NativeToManagedThisMarshallerFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs similarity index 84% rename from src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/NativeToManagedThisMarshallerFactory.cs rename to src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs index 66e07ead04b52..babd013163b8a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/NativeToManagedThisMarshallerFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Marshallers/ObjectUnwrapperMarshallerFactory.cs @@ -10,26 +10,26 @@ namespace Microsoft.Interop { - internal sealed record NativeThisInfo(TypeSyntax UnwrapperType) : MarshallingInfo; + internal sealed record ObjectUnwrapperInfo(TypeSyntax UnwrapperType) : MarshallingInfo; - internal sealed class NativeToManagedThisMarshallerFactory : IMarshallingGeneratorFactory + internal sealed class ObjectUnwrapperMarshallerFactory : IMarshallingGeneratorFactory { private readonly IMarshallingGeneratorFactory _inner; - public NativeToManagedThisMarshallerFactory(IMarshallingGeneratorFactory inner) + public ObjectUnwrapperMarshallerFactory(IMarshallingGeneratorFactory inner) { _inner = inner; } public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) - => info.MarshallingAttributeInfo is NativeThisInfo ? new Marshaller() : _inner.Create(info, context); + => info.MarshallingAttributeInfo is ObjectUnwrapperInfo ? new Marshaller() : _inner.Create(info, context); private sealed class Marshaller : IMarshallingGenerator { public ManagedTypeInfo AsNativeType(TypePositionInfo info) => new PointerTypeInfo("void*", "void*", false); public IEnumerable Generate(TypePositionInfo info, StubCodeContext context) { - Debug.Assert(info.MarshallingAttributeInfo is NativeThisInfo); - TypeSyntax unwrapperType = ((NativeThisInfo)info.MarshallingAttributeInfo).UnwrapperType; + Debug.Assert(info.MarshallingAttributeInfo is ObjectUnwrapperInfo); + TypeSyntax unwrapperType = ((ObjectUnwrapperInfo)info.MarshallingAttributeInfo).UnwrapperType; if (context.CurrentStage != StubCodeContext.Stage.Unmarshal) { yield break; diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs index c8786169bc4ff..a007784bfdc53 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VirtualMethodPointerStubGenerator.cs @@ -121,7 +121,7 @@ private static ImmutableArray AddImplicitElementInfos(Incremen var elements = ImmutableArray.CreateBuilder(originalElements.Length + 2); - elements.Add(new TypePositionInfo(methodStub.TypeKeyOwner, new NativeThisInfo(methodStub.UnwrapperSyntax)) + elements.Add(new TypePositionInfo(methodStub.TypeKeyOwner, methodStub.ManagedThisMarshallingInfo) { InstanceIdentifier = ThisParameterIdentifier, NativeIndex = 0, diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs index dda84734a0139..e564364f883ca 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGenerator.cs @@ -337,11 +337,11 @@ private static IncrementalMethodStubGenerationContext CalculateStubInformation(M new SequenceEqualImmutableArray(callConv, SyntaxEquivalentComparer.Instance), VirtualMethodIndexData.From(virtualMethodIndexData), exceptionMarshallingInfo, - ComInterfaceGeneratorHelpers.CreateGeneratorFactory(environment, MarshalDirection.ManagedToUnmanaged), - ComInterfaceGeneratorHelpers.CreateGeneratorFactory(environment, MarshalDirection.UnmanagedToManaged), + VtableIndexStubGeneratorHelpers.CreateGeneratorFactory(environment, MarshalDirection.ManagedToUnmanaged), + VtableIndexStubGeneratorHelpers.CreateGeneratorFactory(environment, MarshalDirection.UnmanagedToManaged), interfaceType, new SequenceEqualImmutableArray(generatorDiagnostics.Diagnostics.ToImmutableArray()), - unwrapperSyntax); + new ObjectUnwrapperInfo(unwrapperSyntax)); } private static MarshallingInfo CreateExceptionMarshallingInfo(AttributeData virtualMethodIndexAttr, ISymbol symbol, Compilation compilation, GeneratorDiagnostics diagnostics, VirtualMethodIndexCompilationData virtualMethodIndexData) diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGeneratorHelpers.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGeneratorHelpers.cs new file mode 100644 index 0000000000000..a421cd26e7e15 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/VtableIndexStubGeneratorHelpers.cs @@ -0,0 +1,66 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.CodeAnalysis; + +namespace Microsoft.Interop +{ + internal static class VtableIndexStubGeneratorHelpers + { + public static MarshallingGeneratorFactoryKey<(TargetFramework, Version)> CreateGeneratorFactory(StubEnvironment env, MarshalDirection direction) + { + IMarshallingGeneratorFactory generatorFactory; + + // If we're in a "supported" scenario, then emit a diagnostic as our final fallback. + generatorFactory = new UnsupportedMarshallingFactory(); + + generatorFactory = new NoMarshallingInfoErrorMarshallingFactory(generatorFactory); + + // The presence of System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute is tied to TFM, + // so we use TFM in the generator factory key instead of the Compilation as the compilation changes on every keystroke. + IAssemblySymbol coreLibraryAssembly = env.Compilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly; + ITypeSymbol? disabledRuntimeMarshallingAttributeType = coreLibraryAssembly.GetTypeByMetadataName(TypeNames.System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute); + bool runtimeMarshallingDisabled = disabledRuntimeMarshallingAttributeType is not null + && env.Compilation.Assembly.GetAttributes().Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, disabledRuntimeMarshallingAttributeType)); + + // Since the char type can go into the P/Invoke signature here, we can only use it when + // runtime marshalling is disabled. + generatorFactory = new CharMarshallingGeneratorFactory(generatorFactory, useBlittableMarshallerForUtf16: runtimeMarshallingDisabled); + + InteropGenerationOptions interopGenerationOptions = new(UseMarshalType: true); + generatorFactory = new MarshalAsMarshallingGeneratorFactory(interopGenerationOptions, generatorFactory); + + IMarshallingGeneratorFactory elementFactory = new AttributedMarshallingModelGeneratorFactory( + // Since the char type in an array will not be part of the P/Invoke signature, we can + // use the regular blittable marshaller in all cases. + new CharMarshallingGeneratorFactory(generatorFactory, useBlittableMarshallerForUtf16: true), + new AttributedMarshallingModelOptions(runtimeMarshallingDisabled, MarshalMode.ElementIn, MarshalMode.ElementRef, MarshalMode.ElementOut)); + // We don't need to include the later generator factories for collection elements + // as the later generator factories only apply to parameters. + generatorFactory = new AttributedMarshallingModelGeneratorFactory( + generatorFactory, + elementFactory, + new AttributedMarshallingModelOptions( + runtimeMarshallingDisabled, + direction == MarshalDirection.ManagedToUnmanaged + ? MarshalMode.ManagedToUnmanagedIn + : MarshalMode.UnmanagedToManagedOut, + direction == MarshalDirection.ManagedToUnmanaged + ? MarshalMode.ManagedToUnmanagedRef + : MarshalMode.UnmanagedToManagedRef, + direction == MarshalDirection.ManagedToUnmanaged + ? MarshalMode.ManagedToUnmanagedOut + : MarshalMode.UnmanagedToManagedIn)); + + generatorFactory = new ObjectUnwrapperMarshallerFactory(generatorFactory); + + generatorFactory = new ByValueContentsMarshalKindValidator(generatorFactory); + + return MarshallingGeneratorFactoryKey.Create((env.TargetFramework, env.TargetFrameworkVersion), generatorFactory); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs index 675a37230a1bd..89c85ee235a34 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs @@ -155,12 +155,12 @@ internal static MarshallingInfo CreateSpecificMarshallingInfo(ManagedTypeInfo un { return unmanagedReturnType switch { - SpecialTypeInfo(_, _, SpecialType.System_Void) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.SwallowExceptionMarshaller}", unmanagedReturnType), - SpecialTypeInfo(_, _, SpecialType.System_Int32) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionHResultMarshaller}", unmanagedReturnType), - SpecialTypeInfo(_, _, SpecialType.System_UInt32) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionHResultMarshaller}", unmanagedReturnType), - SpecialTypeInfo(_, _, SpecialType.System_Single) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionNaNMarshaller}", unmanagedReturnType), - SpecialTypeInfo(_, _, SpecialType.System_Double) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionNaNMarshaller}", unmanagedReturnType), - _ => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionDefaultMarshaller}<{MarshallerHelpers.GetCompatibleGenericTypeParameterSyntax(SyntaxFactory.ParseTypeName(unmanagedReturnType.FullTypeName))}>", unmanagedReturnType), + SpecialTypeInfo(_, _, SpecialType.System_Void) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsVoidMarshaller}", unmanagedReturnType), + SpecialTypeInfo(_, _, SpecialType.System_Int32) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsHResultMarshaller}", unmanagedReturnType), + SpecialTypeInfo(_, _, SpecialType.System_UInt32) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsHResultMarshaller}", unmanagedReturnType), + SpecialTypeInfo(_, _, SpecialType.System_Single) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsNaNMarshaller}", unmanagedReturnType), + SpecialTypeInfo(_, _, SpecialType.System_Double) => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsNaNMarshaller}", unmanagedReturnType), + _ => CreateWellKnownComExceptionMarshallingData($"{TypeNames.ExceptionAsDefaultMarshaller}<{MarshallerHelpers.GetCompatibleGenericTypeParameterSyntax(SyntaxFactory.ParseTypeName(unmanagedReturnType.FullTypeName))}>", unmanagedReturnType), }; static NativeMarshallingAttributeInfo CreateWellKnownComExceptionMarshallingData(string marshallerName, ManagedTypeInfo unmanagedType) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs index fa271c817da5e..dd9c0edf3b21f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs @@ -21,10 +21,10 @@ public static class TypeNames public const string BStrStringMarshaller = "System.Runtime.InteropServices.Marshalling.BStrStringMarshaller"; public const string Utf16StringMarshaller = "System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller"; public const string Utf8StringMarshaller = "System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller"; - public const string SwallowExceptionMarshaller = "System.Runtime.InteropServices.Marshalling.SwallowExceptionMarshaller"; - public const string ExceptionHResultMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionHResultMarshaller"; - public const string ExceptionNaNMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionNaNMarshaller"; - public const string ExceptionDefaultMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionDefaultMarshaller"; + public const string ExceptionAsVoidMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionAsVoidMarshaller"; + public const string ExceptionAsHResultMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller"; + public const string ExceptionAsNaNMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionAsNaNMarshaller"; + public const string ExceptionAsDefaultMarshaller = "System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller"; public const string LCIDConversionAttribute = "System.Runtime.InteropServices.LCIDConversionAttribute"; diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionDefaultMarshaller.cs b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsDefaultMarshaller.cs similarity index 91% rename from src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionDefaultMarshaller.cs rename to src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsDefaultMarshaller.cs index 9133ee6829317..5580b3500d78b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionDefaultMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsDefaultMarshaller.cs @@ -14,8 +14,8 @@ namespace System.Runtime.InteropServices.Marshalling /// Converts the exception to the default value of the unmanaged type. /// /// The unmanaged type - [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionDefaultMarshaller<>))] - public static class ExceptionDefaultMarshaller + [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionAsDefaultMarshaller<>))] + public static class ExceptionAsDefaultMarshaller where T : unmanaged { /// diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionHResultMarshaller.cs b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsHResultMarshaller.cs similarity index 95% rename from src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionHResultMarshaller.cs rename to src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsHResultMarshaller.cs index 34f9685ed5aee..f1ffcf97cb11c 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionHResultMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsHResultMarshaller.cs @@ -22,8 +22,8 @@ namespace System.Runtime.InteropServices.Marshalling /// We can skip the exposing the exception marshallers if we decide to not expose the VTable source generator. /// In that case, we'd hard-code the implementations of these marshallers into the COM source generator. /// - [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionHResultMarshaller<>))] - public static class ExceptionHResultMarshaller + [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionAsHResultMarshaller<>))] + public static class ExceptionAsHResultMarshaller where T : unmanaged, INumber { /// diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionNaNMarshaller.cs b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsNaNMarshaller.cs similarity index 92% rename from src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionNaNMarshaller.cs rename to src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsNaNMarshaller.cs index cc00a72966189..c261eb4cb6978 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionNaNMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsNaNMarshaller.cs @@ -14,8 +14,8 @@ namespace System.Runtime.InteropServices.Marshalling /// Converts all exceptions to . /// /// The unmanaged type to return the NaN value for. - [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionNaNMarshaller<>))] - public static class ExceptionNaNMarshaller + [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionAsNaNMarshaller<>))] + public static class ExceptionAsNaNMarshaller where T : unmanaged, IFloatingPointIeee754 { /// diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/SwallowExceptionMarshaller.cs b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsVoidMarshaller.cs similarity index 90% rename from src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/SwallowExceptionMarshaller.cs rename to src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsVoidMarshaller.cs index 0c886ca53afba..9fc5b8e9699b3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/SwallowExceptionMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/ExceptionAsVoidMarshaller.cs @@ -13,8 +13,8 @@ namespace System.Runtime.InteropServices.Marshalling /// /// Marshaller that swallows the exception. /// - [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(SwallowExceptionMarshaller))] - public static class SwallowExceptionMarshaller + [CustomMarshaller(typeof(Exception), MarshalMode.UnmanagedToManagedOut, typeof(ExceptionAsVoidMarshaller))] + public static class ExceptionAsVoidMarshaller { /// /// Swallow the exception and return nothing. diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs index 1f4e361b2b700..e6448b6972859 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/Compiles.cs @@ -353,7 +353,7 @@ public async Task ValidateComInterfaceSnippets(string id, string source) // Cannot use 'ref', 'in', or 'out' in the signature of a method attributed with 'UnmanagedCallersOnly'. "CS8977", // The type 'SafeFileHandle' must be a non-nullable value type, along with all fields at any level of nesting, - // in order to use it as parameter 'T' in the generic type or method 'ExceptionDefaultMarshaller' + // in order to use it as parameter 'T' in the generic type or method 'ExceptionAsDefaultMarshaller' "CS8377", // Argument N may not be passed with the 'in' keyword "CS1615"