From 2ed506c010b41c41c01997c81df977831f0fa217 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:53:02 -0700 Subject: [PATCH] [ComInterfaceGenerator] Add Caller Allocated Buffer collection marshaller and interface (#90107) Co-authored-by: Jeremy Koritzinsky --- ...tatelessCollectionCallerAllocatedBuffer.cs | 140 ++++++++++++++++++ .../IStatelessCollectionStatelessElement.cs | 1 - 2 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionCallerAllocatedBuffer.cs diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionCallerAllocatedBuffer.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionCallerAllocatedBuffer.cs new file mode 100644 index 00000000000000..c13caee66fa472 --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionCallerAllocatedBuffer.cs @@ -0,0 +1,140 @@ +// 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.Runtime.InteropServices; +using System.Runtime.InteropServices.Marshalling; + +namespace SharedTypes.ComInterfaces +{ + [GeneratedComInterface(), Guid("0A52B77C-E08B-4274-A1F4-1A2BF2C07E60")] + internal partial interface IStatelessCollectionCallerAllocatedBuffer + { + void Method( + [MarshalUsing(CountElementName = nameof(size))] StatelessCollectionCallerAllocatedBuffer p, + int size); + + void MethodIn( + [MarshalUsing(CountElementName = nameof(size))] in StatelessCollectionCallerAllocatedBuffer pIn, + in int size); + + void MethodRef( + [MarshalUsing(CountElementName = nameof(size))] ref StatelessCollectionCallerAllocatedBuffer pRef, + int size); + + void MethodOut( + [MarshalUsing(CountElementName = nameof(size))] out StatelessCollectionCallerAllocatedBuffer pOut, + out int size); + + [return: MarshalUsing(CountElementName = nameof(size))] + StatelessCollectionCallerAllocatedBuffer Return(int size); + + [PreserveSig] + [return: MarshalUsing(CountElementName = nameof(size))] + StatelessCollectionCallerAllocatedBuffer ReturnPreserveSig(int size); + } + + [NativeMarshalling(typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>))] + internal class StatelessCollectionCallerAllocatedBuffer + { + } + + internal struct StatelessCollectionCallerAllocatedBufferNative + { + + } + + [ContiguousCollectionMarshaller] + [CustomMarshaller(typeof(StatelessCollectionCallerAllocatedBuffer<>), MarshalMode.ManagedToUnmanagedIn, typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>.ManagedToUnmanaged))] + [CustomMarshaller(typeof(StatelessCollectionCallerAllocatedBuffer<>), MarshalMode.UnmanagedToManagedOut, typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>.ManagedToUnmanaged))] + [CustomMarshaller(typeof(StatelessCollectionCallerAllocatedBuffer<>), MarshalMode.ManagedToUnmanagedOut, typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>.UnmanagedToManaged))] + [CustomMarshaller(typeof(StatelessCollectionCallerAllocatedBuffer<>), MarshalMode.UnmanagedToManagedIn, typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>.UnmanagedToManaged))] + [CustomMarshaller(typeof(StatelessCollectionCallerAllocatedBuffer<>), MarshalMode.UnmanagedToManagedRef, typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>.Bidirectional))] + [CustomMarshaller(typeof(StatelessCollectionCallerAllocatedBuffer<>), MarshalMode.ManagedToUnmanagedRef, typeof(StatelessCollectionCallerAllocatedBufferMarshaller<,>.Bidirectional))] + internal static unsafe class StatelessCollectionCallerAllocatedBufferMarshaller where TUnmanagedElement : unmanaged + { + internal static class Bidirectional + { + public static int BufferSize => throw new NotImplementedException(); + public static StatelessCollectionCallerAllocatedBufferNative AllocateContainerForUnmanagedElements(StatelessCollectionCallerAllocatedBuffer managed, Span buffer, out int numElements) + { + throw new NotImplementedException(); + } + + // Bidirectional requires non-buffer version of this method + public static StatelessCollectionCallerAllocatedBufferNative AllocateContainerForUnmanagedElements(StatelessCollectionCallerAllocatedBuffer managed, out int numElements) + { + throw new NotImplementedException(); + } + + public static StatelessCollectionCallerAllocatedBuffer AllocateContainerForManagedElements(StatelessCollectionCallerAllocatedBufferNative unmanaged, int numElements) + { + throw new NotImplementedException(); + } + + public static ReadOnlySpan GetManagedValuesSource(StatelessCollectionCallerAllocatedBuffer managed) + { + throw new NotImplementedException(); + } + + public static Span GetUnmanagedValuesDestination(StatelessCollectionCallerAllocatedBufferNative unmanaged, int numElements) + { + throw new NotImplementedException(); + } + + public static ReadOnlySpan GetUnmanagedValuesSource(StatelessCollectionCallerAllocatedBufferNative unmanaged, int numElements) + { + throw new NotImplementedException(); + } + + public static Span GetManagedValuesDestination(StatelessCollectionCallerAllocatedBuffer managed) + { + throw new NotImplementedException(); + } + + public static void Free(StatelessCollectionCallerAllocatedBufferNative unmanaged) { } + } + + internal static class ManagedToUnmanaged + { + public static int BufferSize => throw new NotImplementedException(); + public static StatelessCollectionCallerAllocatedBufferNative AllocateContainerForUnmanagedElements(StatelessCollectionCallerAllocatedBuffer managed, Span buffer, out int numElements) + { + throw new NotImplementedException(); + } + + public static ReadOnlySpan GetManagedValuesSource(StatelessCollectionCallerAllocatedBuffer managed) + { + throw new NotImplementedException(); + } + + public static Span GetUnmanagedValuesDestination(StatelessCollectionCallerAllocatedBufferNative unmanaged, int numElements) + { + throw new NotImplementedException(); + } + + public static void Free(StatelessCollectionCallerAllocatedBufferNative unmanaged) => throw new NotImplementedException(); + } + + internal static class UnmanagedToManaged + { + public static StatelessCollectionCallerAllocatedBuffer AllocateContainerForManagedElements(StatelessCollectionCallerAllocatedBufferNative unmanaged, int numElements) + { + throw new NotImplementedException(); + } + + public static ReadOnlySpan GetUnmanagedValuesSource(StatelessCollectionCallerAllocatedBufferNative unmanaged, int numElements) + { + throw new NotImplementedException(); + } + + public static Span GetManagedValuesDestination(StatelessCollectionCallerAllocatedBuffer managed) + { + throw new NotImplementedException(); + } + + public static void Free(StatelessCollectionCallerAllocatedBufferNative unmanaged) => throw new NotImplementedException(); + + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionStatelessElement.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionStatelessElement.cs index b295a9adb919b7..68ad9f409b3b84 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionStatelessElement.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IStatelessCollectionStatelessElement.cs @@ -109,7 +109,6 @@ public static Span GetUnmanagedValuesDestination(NativeCollec } public static void Free(NativeCollection unmanaged) => throw new NotImplementedException(); - } internal static class UnmanagedToManaged