From 7e023df4bd2339d3c8e621f11e354e37ea1f1a02 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 8 Aug 2023 02:01:47 +0000 Subject: [PATCH 1/2] Latest chanages --- ...terfaceGenerator.Tests.DerivedComObject.cs | 8 +- ...nerator.Tests.IDerivedTests.DerivedImpl.cs | 8 +- ...nerator.Tests.ManagedObjectExposedToCom.cs | 8 +- ...hallingTests.CustomUtf16MarshalledClass.cs | 8 +- ...ngMarshallingTests.Utf16MarshalledClass.cs | 8 +- ...ingMarshallingTests.Utf8MarshalledClass.cs | 8 +- ....ComInterfaces.ArrayOfStatelessElements.cs | 8 +- ...terfaces.ArrayOfStatelessElementsThrows.cs | 31 + .../SharedTypes.ComInterfaces.Derived.cs | 8 +- .../SharedTypes.ComInterfaces.GetAndSetInt.cs | 8 +- .../SharedTypes.ComInterfaces.IBoolImpl.cs | 8 +- .../SharedTypes.ComInterfaces.IFloatImpl.cs | 8 +- ...SharedTypes.ComInterfaces.IIntArrayImpl.cs | 8 +- .../SharedTypes.ComInterfaces.IIntImpl.cs | 8 +- ...haredTypes.ComInterfaces.IInterfaceImpl.cs | 8 +- ...Types.ComInterfaces.IJaggedIntArrayImpl.cs | 8 +- ...ngFails.ICollectionMarshallingFailsImpl.cs | 8 +- ...ils.IJaggedIntArrayMarshallingFailsImpl.cs | 8 +- ...gFails.IStringArrayMarshallingFailsImpl.cs | 8 +- ...omInterfaces.StatefulFinallyMarshalling.cs | 8 +- ...atelessCallerAllocatedBufferMarshalling.cs | 8 +- ...mInterfaces.StatelessFinallyMarshalling.cs | 8 +- ...ypes.ComInterfaces.StatelessMarshalling.cs | 8 +- ...omInterfaces.StatelessPinnedMarshalling.cs | 8 +- ...ComInterfaces.IArrayOfStatelessElements.cs | 121 +- .../SharedTypes.ComInterfaces.IBool.cs | 30 +- ...nterfaces.ICustomStringMarshallingUtf16.cs | 39 +- .../SharedTypes.ComInterfaces.IDerived.cs | 39 +- .../SharedTypes.ComInterfaces.IEmpty.cs | 24 +- .../SharedTypes.ComInterfaces.IEnumUnknown.cs | 59 +- .../SharedTypes.ComInterfaces.IFloat.cs | 30 +- ...SharedTypes.ComInterfaces.IGetAndSetInt.cs | 30 +- .../SharedTypes.ComInterfaces.IGetIntArray.cs | 37 +- .../SharedTypes.ComInterfaces.IInt.cs | 39 +- .../SharedTypes.ComInterfaces.IIntArray.cs | 71 +- .../SharedTypes.ComInterfaces.IInterface.cs | 65 +- ...aredTypes.ComInterfaces.IJaggedIntArray.cs | 97 +- ...haredTypes.ComInterfaces.IPointProvider.cs | 27 +- .../SharedTypes.ComInterfaces.IRefStrings.cs | 48 +- ...aredTypes.ComInterfaces.ISafeFileHandle.cs | 39 +- ...tatefulCallerAllocatedBufferMarshalling.cs | 84 +- ...ces.IStatefulCollectionBlittableElement.cs | 84 +- ...ces.IStatefulCollectionStatelessElement.cs | 132 +- ...mInterfaces.IStatefulFinallyMarshalling.cs | 69 +- ...ypes.ComInterfaces.IStatefulMarshalling.cs | 81 +- ...omInterfaces.IStatefulPinnedMarshalling.cs | 81 +- ...tatelessCallerAllocateBufferMarshalling.cs | 74 +- ...es.IStatelessCollectionBlittableElement.cs | 81 +- ...es.IStatelessCollectionStatelessElement.cs | 109 +- ...Interfaces.IStatelessFinallyMarshalling.cs | 62 +- ...pes.ComInterfaces.IStatelessMarshalling.cs | 74 +- ...lessPinnableCollectionBlittableElements.cs | 853 +- ...mInterfaces.IStatelessPinnedMarshalling.cs | 72 +- ...omInterfaces.IStringMarshallingOverride.cs | 62 +- ...faces.IStringMarshallingOverrideDerived.cs | 91 +- ...edTypes.ComInterfaces.IUTF16Marshalling.cs | 39 +- ...redTypes.ComInterfaces.IUTF8Marshalling.cs | 41 +- ...allingFails.ICollectionMarshallingFails.cs | 79 +- ...ngFails.IJaggedIntArrayMarshallingFails.cs | 155 +- ...llingFails.IStringArrayMarshallingFails.cs | 101 +- .../ManagedToNativeStubs.g.cs | 78 +- .../NativeInterfaces.g.cs | 10 +- .../NativeToManagedStubs.g.cs | 44 +- .../PopulateVTable.g.cs | 8 +- .../LibraryImports.g.cs | 85 +- .../LibraryImports.g.cs | 1589 +++ .../LibraryImports.g.cs | 8823 +++++++++++++++++ 67 files changed, 12547 insertions(+), 1524 deletions(-) create mode 100644 ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElementsThrows.cs create mode 100644 LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs index 64e10f2..c6f2b71 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.DerivedComObject.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace ComInterfaceGenerator.Tests { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] partial class DerivedComObject { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs index deaf259..f057232 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.IDerivedTests.DerivedImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -26,8 +26,8 @@ return s_vtables; } -} - +} + namespace ComInterfaceGenerator.Tests { public unsafe partial class IDerivedTests @@ -37,4 +37,4 @@ partial class DerivedImpl { } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs index 0fc2e9e..3db9392 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.ManagedObjectExposedToCom.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace ComInterfaceGenerator.Tests { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] partial class ManagedObjectExposedToCom { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs index 82bfd89..4ec58a7 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.CustomUtf16MarshalledClass.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,8 +20,8 @@ return s_vtables; } -} - +} + namespace ComInterfaceGenerator.Tests { public unsafe partial class StringMarshallingTests @@ -31,4 +31,4 @@ internal partial class CustomUtf16MarshalledClass { } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs index fdfe9df..16af57e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf16MarshalledClass.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,8 +20,8 @@ return s_vtables; } -} - +} + namespace ComInterfaceGenerator.Tests { public unsafe partial class StringMarshallingTests @@ -31,4 +31,4 @@ internal partial class Utf16MarshalledClass { } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs index 3525541..d0fd8ae 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/ComInterfaceGenerator.Tests.StringMarshallingTests.Utf8MarshalledClass.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,8 +20,8 @@ return s_vtables; } -} - +} + namespace ComInterfaceGenerator.Tests { public unsafe partial class StringMarshallingTests @@ -31,4 +31,4 @@ internal partial class Utf8MarshalledClass { } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs index 0ade01c..8a079fa 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElements.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class ArrayOfStatelessElements { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElementsThrows.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElementsThrows.cs new file mode 100644 index 0000000..e2563f8 --- /dev/null +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.ArrayOfStatelessElementsThrows.cs @@ -0,0 +1,31 @@ +// +file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass +{ + private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; + public static System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* GetComInterfaceEntries(out int count) + { + count = 1; + if (s_vtables == null) + { + System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* vtables = (System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry*)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ComClassInformation), sizeof(System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry) * 1); + System.Runtime.InteropServices.Marshalling.IIUnknownDerivedDetails details; + details = System.Runtime.InteropServices.Marshalling.StrategyBasedComWrappers.DefaultIUnknownInterfaceDetailsStrategy.GetIUnknownDerivedDetails(typeof(SharedTypes.ComInterfaces.IArrayOfStatelessElements).TypeHandle); + vtables[0] = new() + { + IID = details.Iid, + Vtable = (nint)details.ManagedVirtualMethodTable + }; + s_vtables = vtables; + } + + return s_vtables; + } +} + +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] + internal partial class ArrayOfStatelessElementsThrows + { + } +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs index c4d7431..8714f5c 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.Derived.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -26,12 +26,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class Derived { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs index cda8421..b07aefa 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.GetAndSetInt.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class GetAndSetInt { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs index 867e228..bec4508 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IBoolImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IBoolImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs index 0f874db..75d34e1 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IFloatImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IFloatImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs index 3fd965d..54224c8 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntArrayImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IIntArrayImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs index 563469a..b8e69d1 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IIntImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IIntImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs index 8e2d048..299cd79 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IInterfaceImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IInterfaceImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs index e05f617..6cc208d 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.IJaggedIntArrayImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IJaggedIntArrayImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs index 8165c4d..f143c8a 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFailsImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class ICollectionMarshallingFailsImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs index 2cf5a32..3e510f1 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFailsImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IJaggedIntArrayMarshallingFailsImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs index 3db32a6..bb1bd14 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFailsImpl.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class IStringArrayMarshallingFailsImpl { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatefulFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatefulFinallyMarshalling.cs index 4b28658..0cc61a8 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatefulFinallyMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatefulFinallyMarshalling.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class StatefulFinallyMarshalling { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs index ffb1974..7d63c39 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferMarshalling.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class StatelessCallerAllocatedBufferMarshalling { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs index 05cfde7..bcea489 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessFinallyMarshalling.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class StatelessFinallyMarshalling { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs index e0c887f..054af61 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessMarshalling.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class StatelessMarshalling { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs index a2dfcab..2089aa4 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComClassGenerator/SharedTypes.ComInterfaces.StatelessPinnedMarshalling.cs @@ -1,4 +1,4 @@ -// +// file sealed unsafe class ComClassInformation : System.Runtime.InteropServices.Marshalling.IComExposedClass { private static volatile System.Runtime.InteropServices.ComWrappers.ComInterfaceEntry* s_vtables; @@ -20,12 +20,12 @@ return s_vtables; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.ComExposedClassAttribute] internal partial class StatelessPinnedMarshalling { } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs index 422578f..ca2d14b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IArrayOfStatelessElements.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 191, 60, 150, 244, 175, 16, 11, 70, 132, 149, 16, 119, 130, 24, 119, 5 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IArrayOfStatelessElements { @@ -16,6 +16,7 @@ void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.Method(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + bool __invokeSucceeded = default; nint* __param_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -46,11 +47,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __param_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) @@ -68,6 +76,7 @@ void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodIn(in global::SharedTypes.ComInterfaces.StatelessType[] param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + bool __invokeSucceeded = default; nint* __param_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -98,11 +107,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __param_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) @@ -120,6 +136,7 @@ void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType[] param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint* __param_native = default; int __invokeRetVal = default; @@ -134,6 +151,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __param_native__numElements = size; @@ -149,17 +167,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); - for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__param_native__nativeSpan[__i0]); + System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__param_native__nativeSpan[__i0]); + } } - } - __param_native__numElements = size; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__param_native); + } } } @@ -208,7 +228,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __param_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__param_native, __param_native__numElements); for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) @@ -227,6 +247,7 @@ void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsIn(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + bool __invokeSucceeded = default; nint* __param_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -257,11 +278,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __param_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) @@ -279,6 +307,7 @@ void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsOut(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + bool __invokeSucceeded = default; nint* __param_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -300,6 +329,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. { @@ -314,15 +344,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__param_native__nativeSpan[__i0]); + System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __param_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__param_native__nativeSpan[__i0]); + } } } + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -332,6 +366,7 @@ void global::SharedTypes.ComInterfaces.IArrayOfStatelessElements.MethodContentsInOut(global::SharedTypes.ComInterfaces.StatelessType[] param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IArrayOfStatelessElements)); + bool __invokeSucceeded = default; nint* __param_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -362,6 +397,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. { @@ -376,7 +412,13 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __param_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __param_native__nativeSpan = __param_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __param_native__lastIndexMarshalled; ++__i0) @@ -388,8 +430,8 @@ __param_native__marshaller.Free(); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -404,7 +446,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __param_native__numElements = size; param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); { @@ -418,6 +459,8 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -440,7 +483,6 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __param_native__numElements = size; param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); { @@ -454,6 +496,8 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -476,9 +520,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); { @@ -515,7 +560,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __param_native__numElements = size; param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); { @@ -529,6 +573,8 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(param, out __param_native__numElements); __param_native__ownOriginal = true; @@ -547,7 +593,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__param_native__ownOriginal) { { @@ -578,7 +624,6 @@ internal static int ABI_MethodContentsIn(System.Runtime.InteropServices.ComWrapp try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __param_native__numElements = size; param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); { @@ -592,6 +637,8 @@ internal static int ABI_MethodContentsIn(System.Runtime.InteropServices.ComWrapp @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodContentsIn(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -613,10 +660,11 @@ internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrap try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Clear(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodContentsOut(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. { __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; @@ -650,7 +698,6 @@ internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWr try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __param_native__numElements = size; param = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__param_native, __param_native__numElements); { @@ -664,6 +711,8 @@ internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWr @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodContentsInOut(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. { __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(param).Length; @@ -684,8 +733,8 @@ internal static int ABI_MethodContentsInOut(System.Runtime.InteropServices.ComWr return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -711,16 +760,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IArrayOfStatelessElements { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IArrayOfStatelessElements diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs index 35672ee..e4e4b59 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IBool.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 214, 62, 157, 90, 23, 204, 185, 79, 143, 130, 0, 112, 72, 155, 114, 19 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IBool { @@ -48,8 +48,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -62,9 +62,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (sbyte)(__invokeRetVal ? 1 : 0); } @@ -85,10 +86,11 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = __value_native != 0; @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Set(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -97,8 +99,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -119,16 +121,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IBool { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IBool diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs index ed15d0f..74732ff 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 62, 95, 29, 225, 87, 221, 166, 65, 165, 158, 125, 17, 5, 81, 167, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16 { @@ -16,6 +16,7 @@ string global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16.GetString() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ICustomStringMarshallingUtf16)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -27,14 +28,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -56,8 +61,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -70,9 +75,10 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetString(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -93,10 +99,11 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetString(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -105,8 +112,8 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -127,16 +134,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface ICustomStringMarshallingUtf16 { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface ICustomStringMarshallingUtf16 diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs index 9d57c73..d2bd382 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IDerived.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 100, 179, 13, 127, 4, 60, 135, 68, 145, 147, 75, 176, 93, 199, 182, 84 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IDerived { @@ -33,6 +33,7 @@ string global::SharedTypes.ComInterfaces.IDerived.GetName() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IDerived)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -44,14 +45,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -91,8 +96,8 @@ int global::SharedTypes.ComInterfaces.IGetAndSetInt.GetInt() => throw new System.Diagnostics.UnreachableException(); void global::SharedTypes.ComInterfaces.IGetAndSetInt.SetInt(int x) => throw new System.Diagnostics.UnreachableException(); -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -104,10 +109,11 @@ internal static int ABI_SetName(System.Runtime.InteropServices.ComWrappers.ComIn try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK name = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__name_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetName(name); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -127,9 +133,10 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetName(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -140,8 +147,8 @@ internal static int ABI_GetName(System.Runtime.InteropServices.ComWrappers.ComIn return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -158,16 +165,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IDerived { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IDerived diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs index 0b4a031..7feb8f3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEmpty.cs @@ -1,22 +1,22 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 80, 159, 209, 149, 216, 242, 97, 78, 136, 75, 10, 145, 98, 234, 70, 70 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IEmpty { -} - +} + file unsafe partial interface InterfaceImplementation { -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -35,16 +35,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IEmpty { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IEmpty diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs index 9bcb5bf..a7296e3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IEnumUnknown.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 0, 1, 0, 0, 0, 0, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IEnumUnknown { @@ -16,6 +16,7 @@ void global::SharedTypes.ComInterfaces.IEnumUnknown.Next(uint celt, object[] rgelt, out uint pceltFetched) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out pceltFetched); System.IntPtr* __rgelt_native = default; int __invokeRetVal = default; @@ -39,6 +40,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. { @@ -53,15 +55,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __rgelt_native__nativeSpan = __rgelt_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __rgelt_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free((void*)__rgelt_native__nativeSpan[__i0]); + System.ReadOnlySpan __rgelt_native__nativeSpan = __rgelt_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __rgelt_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free((void*)__rgelt_native__nativeSpan[__i0]); + } } } + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __rgelt_native__marshaller.Free(); } } @@ -101,6 +107,7 @@ void global::SharedTypes.ComInterfaces.IEnumUnknown.Clone(out global::SharedTypes.ComInterfaces.IEnumUnknown ppenum) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IEnumUnknown)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out ppenum); void* __ppenum_native = default; int __invokeRetVal = default; @@ -112,18 +119,22 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. ppenum = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__ppenum_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__ppenum_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__ppenum_native); + } } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -140,10 +151,11 @@ internal static int ABI_Next(System.Runtime.InteropServices.ComWrappers.ComInter try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(rgelt).Clear(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Next(celt, rgelt, out pceltFetched); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __pceltFetched_native = pceltFetched; { @@ -174,9 +186,10 @@ internal static int ABI_Skip(System.Runtime.InteropServices.ComWrappers.ComInter try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Skip(celt); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -194,9 +207,10 @@ internal static int ABI_Reset(System.Runtime.InteropServices.ComWrappers.ComInte try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Reset(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -216,9 +230,10 @@ internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInte try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Clone(out ppenum); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __ppenum_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(ppenum); } @@ -229,8 +244,8 @@ internal static int ABI_Clone(System.Runtime.InteropServices.ComWrappers.ComInte return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -253,16 +268,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IEnumUnknown { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IEnumUnknown diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs index 5bdc240..f2e3ec3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IFloat.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 169, 168, 164, 159, 143, 45, 168, 72, 182, 251, 180, 75, 95, 27, 159, 182 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IFloat { @@ -42,8 +42,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -56,9 +56,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = __invokeRetVal; } @@ -78,9 +79,10 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Set(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -89,8 +91,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -111,16 +113,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IFloat { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IFloat diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs index 91a3fb8..6cec94e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetAndSetInt.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 3, 153, 63, 44, 134, 181, 177, 70, 136, 27, 173, 252, 233, 175, 71, 177 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IGetAndSetInt { @@ -42,8 +42,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -56,9 +56,10 @@ internal static int ABI_GetInt(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetInt(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = __invokeRetVal; } @@ -78,9 +79,10 @@ internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetInt(x); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -89,8 +91,8 @@ internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -111,16 +113,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IGetAndSetInt { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IGetAndSetInt diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs index d8a339d..4413c49 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IGetIntArray.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 10, 42, 128, 125, 10, 99, 142, 76, 162, 31, 119, 28, 201, 3, 31, 185 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IGetIntArray { @@ -16,6 +16,7 @@ int[] global::SharedTypes.ComInterfaces.IGetIntArray.GetInts() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IGetIntArray)); + bool __invokeSucceeded = default; int[] __retVal = default; int* __retVal_native = default; int __invokeRetVal = default; @@ -30,6 +31,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 10; @@ -38,15 +40,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -62,9 +66,10 @@ internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComIn try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetInts(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__invokeRetVal).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements)); @@ -76,8 +81,8 @@ internal static int ABI_GetInts(System.Runtime.InteropServices.ComWrappers.ComIn return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -97,16 +102,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IGetIntArray { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IGetIntArray diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs index 5bd9062..087e030 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInt.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 42, 31, 109, 238, 24, 52, 23, 67, 168, 124, 53, 72, 143, 101, 70, 171 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IInt { @@ -94,8 +94,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -108,9 +108,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = __invokeRetVal; } @@ -130,9 +131,10 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Set(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -152,10 +154,11 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = __value_native; @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SwapRef(ref value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = value; } @@ -177,9 +180,10 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.GetOut(out value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = value; } @@ -201,10 +205,11 @@ internal static int ABI_SetIn(System.Runtime.InteropServices.ComWrappers.ComInte try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = __value_native; @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetIn(in value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -213,8 +218,8 @@ internal static int ABI_SetIn(System.Runtime.InteropServices.ComWrappers.ComInte return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -238,16 +243,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IInt { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IInt diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs index a9e2401..4e44eeb 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IIntArray.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IIntArray { @@ -16,6 +16,7 @@ int[] global::SharedTypes.ComInterfaces.IIntArray.GetReturn(out int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out size); int[] __retVal = default; int* __retVal_native = default; @@ -33,6 +34,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = size; @@ -41,9 +43,11 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = size; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; @@ -54,6 +58,7 @@ int global::SharedTypes.ComInterfaces.IIntArray.GetOut(out int[] array) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IIntArray)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out array); int* __array_native = default; int __retVal = default; @@ -69,6 +74,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __array_native__numElements = __retVal; @@ -77,9 +83,11 @@ } finally { - // Cleanup - Perform required cleanup. - __array_native__numElements = __retVal; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } } return __retVal; @@ -166,7 +174,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __array_native__marshaller.Free(); } } @@ -200,13 +208,13 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __array_native__numElements = size; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -224,9 +232,10 @@ internal static int ABI_GetReturn(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetReturn(out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __size_native = size; __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); @@ -255,9 +264,10 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetOut(out array); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = __invokeRetVal; __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); @@ -283,12 +293,13 @@ internal static int ABI_SetContents(System.Runtime.InteropServices.ComWrappers.C try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __array_native__numElements = size; array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetContents(array, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -310,10 +321,11 @@ internal static int ABI_FillAscending(System.Runtime.InteropServices.ComWrappers try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).Clear(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.FillAscending(array, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.InteropServices.MemoryMarshal.GetReference(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements)), global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).Length)); } @@ -337,12 +349,13 @@ internal static int ABI_Double(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __array_native__numElements = size; array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Double(array, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array).CopyTo(System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.InteropServices.MemoryMarshal.GetReference(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements)), global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).Length)); } @@ -367,12 +380,13 @@ internal static int ABI_PassIn(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __array_native__numElements = size; array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.PassIn(in array, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -397,12 +411,13 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __array_native__numElements = size; array = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__array_native, __array_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(array)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SwapArray(ref array, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __array_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(array, out __array_native__numElements); __array_native__ownOriginal = true; @@ -414,7 +429,7 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__array_native__ownOriginal) { __array_native__numElements = size; @@ -424,8 +439,8 @@ internal static int ABI_SwapArray(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -451,16 +466,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IIntArray { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IIntArray diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs index 577f12e..c673224 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IInterface.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 152, 115, 133, 164, 251, 6, 110, 74, 129, 219, 53, 70, 27, 233, 153, 197 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IInterface { @@ -16,6 +16,7 @@ global::SharedTypes.ComInterfaces.IInt global::SharedTypes.ComInterfaces.IInterface.Get() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.IInt __retVal = default; void* __retVal_native = default; int __invokeRetVal = default; @@ -27,14 +28,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + } } return __retVal; @@ -61,7 +66,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); } } @@ -89,7 +94,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); } } @@ -99,6 +104,7 @@ void global::SharedTypes.ComInterfaces.IInterface.GetOut(out global::SharedTypes.ComInterfaces.IInt value) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IInterface)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out value); void* __value_native = default; int __invokeRetVal = default; @@ -110,14 +116,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); + } } } @@ -142,12 +152,12 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -160,9 +170,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -183,10 +194,11 @@ internal static int ABI_SetInt(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetInt(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -209,10 +221,11 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SwapRef(ref value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); __value_native__ownOriginal = true; @@ -223,7 +236,7 @@ internal static int ABI_SwapRef(System.Runtime.InteropServices.ComWrappers.ComIn } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__value_native__ownOriginal) { global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__value_native__original); @@ -243,9 +256,10 @@ internal static int ABI_GetOut(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.GetOut(out value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = (void*)global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToUnmanaged(value); } @@ -267,10 +281,11 @@ internal static int ABI_InInt(System.Runtime.InteropServices.ComWrappers.ComInte try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.InInt(in value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -279,8 +294,8 @@ internal static int ABI_InInt(System.Runtime.InteropServices.ComWrappers.ComInte return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -304,16 +319,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IInterface { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IInterface diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs index 2422368..16d2053 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IJaggedIntArray.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IJaggedIntArray { @@ -16,6 +16,7 @@ int[][] global::SharedTypes.ComInterfaces.IJaggedIntArray.Get(out int[] widths, out int length) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); System.Runtime.CompilerServices.Unsafe.SkipInit(out length); int* __widths_native = default; @@ -37,6 +38,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __widths_native__numElements = length; @@ -59,22 +61,22 @@ } finally { - // Cleanup - Perform required cleanup. - __widths_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; @@ -85,6 +87,7 @@ int global::SharedTypes.ComInterfaces.IJaggedIntArray.Get2(out int[][] array, out int[] widths) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out array); System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); System.IntPtr* __array_native = default; @@ -104,6 +107,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __widths_native__numElements = __retVal; @@ -126,22 +130,22 @@ } finally { - // Cleanup - Perform required cleanup. - __widths_native__numElements = __retVal; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + if (__invokeSucceeded) { - System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); - for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); + } } - } - __array_native__numElements = __retVal; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } } return __retVal; @@ -152,6 +156,7 @@ void global::SharedTypes.ComInterfaces.IJaggedIntArray.Set(int[][] array, int[] widths, int length) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IJaggedIntArray)); + bool __invokeSucceeded = default; System.IntPtr* __array_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -186,18 +191,25 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __array_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __array_native__lastIndexMarshalled; ++__i0) { int __array_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - ; + __array_native__nativeSpan____i0__numElements = 0; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__array_native__nativeSpan[__i0]); } } @@ -205,8 +217,8 @@ __array_native__marshaller.Free(); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -228,9 +240,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(out widths, out length); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __length_native = length; __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); @@ -276,9 +289,10 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get2(out array, out widths); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = __invokeRetVal; __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); @@ -320,7 +334,6 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __widths_native__numElements = length; widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); @@ -341,6 +354,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Set(array, widths, length); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -349,8 +364,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -372,16 +387,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IJaggedIntArray { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IJaggedIntArray diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs index b33293c..36a3a77 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IPointProvider.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 20, 25, 70, 228, 2, 66, 159, 71, 132, 39, 98, 14, 145, 95, 132, 185 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IPointProvider { @@ -39,8 +39,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -70,9 +70,10 @@ internal static int ABI_SetPoint(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetPoint(point); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -81,8 +82,8 @@ internal static int ABI_SetPoint(System.Runtime.InteropServices.ComWrappers.ComI return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -103,16 +104,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IPointProvider { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IPointProvider diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs index 1badf00..cf4b3ce 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IRefStrings.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 219, 183, 70, 81, 136, 5, 155, 70, 184, 229, 179, 128, 144, 162, 252, 21 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IRefStrings { @@ -34,7 +34,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); } } @@ -64,7 +64,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __value_native__marshaller.Free(); } } @@ -74,6 +74,7 @@ void global::SharedTypes.ComInterfaces.IRefStrings.OutString(out string value) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IRefStrings)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out value); byte* __value_native = default; int __invokeRetVal = default; @@ -85,18 +86,22 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native); + } } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -112,10 +117,11 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.RefString(ref value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); __value_native__ownOriginal = true; @@ -126,7 +132,7 @@ internal static int ABI_RefString(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__value_native__ownOriginal) { global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__value_native__original); @@ -146,10 +152,11 @@ internal static int ABI_InString(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.InString(in value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -169,9 +176,10 @@ internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.OutString(out value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(value); } @@ -182,8 +190,8 @@ internal static int ABI_OutString(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -205,16 +213,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IRefStrings { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IRefStrings diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs index e069897..01f3f91 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.ISafeFileHandle.cs @@ -1,11 +1,11 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 124, 183, 82, 10, 139, 224, 116, 66, 161, 244, 26, 43, 242, 192, 126, 96 })); public static void** ManagedVirtualMethodTable => null; -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.ISafeFileHandle { @@ -34,7 +34,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __p_native__marshaller.Free(); } } @@ -64,7 +64,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __p_native__marshaller.Free(); } } @@ -74,6 +74,7 @@ void global::SharedTypes.ComInterfaces.ISafeFileHandle.MethodOut(out global::Microsoft.Win32.SafeHandles.SafeFileHandle p) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.ISafeFileHandle)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out p); nint __p_native = default; int __invokeRetVal = default; @@ -87,6 +88,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __p_native__marshaller.FromUnmanaged(__p_native); @@ -95,8 +97,11 @@ } finally { - // Cleanup - Perform required cleanup. - __p_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __p_native__marshaller.Free(); + } } } @@ -136,28 +141,28 @@ p = __p_native__marshaller.ToManagedFinally(); } - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __p_native__marshaller.Free(); } } -} - +} + file unsafe partial interface InterfaceImplementation { -} - +} + file unsafe partial interface InterfaceImplementation { -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface ISafeFileHandle { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface ISafeFileHandle diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs index f985cda..aa500b7 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling { @@ -36,7 +36,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -66,7 +66,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -76,6 +76,7 @@ void global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType param) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint __param_native = default; int __invokeRetVal = default; @@ -89,6 +90,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); @@ -97,8 +99,11 @@ } finally { - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __param_native__marshaller.Free(); + } } } @@ -129,7 +134,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -139,6 +144,7 @@ global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType __retVal = default; nint __retVal_native = default; int __invokeRetVal = default; @@ -152,6 +158,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -160,8 +167,11 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; @@ -172,6 +182,7 @@ global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling.ReturnPreserveSig() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCallerAllocatedBufferMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulCallerAllocatedBufferType __retVal = default; nint __retVal_native = default; // Setup - Perform required setup. @@ -182,6 +193,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -190,14 +202,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -213,10 +228,11 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -224,7 +240,7 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -245,10 +261,11 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -256,7 +273,7 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -275,9 +292,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); } @@ -287,7 +305,7 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -308,10 +326,11 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); } @@ -321,7 +340,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -340,9 +359,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); } @@ -352,7 +372,7 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __invokeRetValUnmanaged__marshaller.Free(); } @@ -381,14 +401,14 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __retVal_native__marshaller.Free(); } return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -413,16 +433,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatefulCallerAllocatedBufferMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatefulCallerAllocatedBufferMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs index d255f98..da9c9ff 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 124, 183, 82, 10, 139, 224, 116, 66, 161, 244, 26, 43, 242, 192, 126, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement { @@ -39,7 +39,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __p_native__marshaller.Free(); } } @@ -74,7 +74,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pIn_native__marshaller.Free(); } } @@ -113,7 +113,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pRef_native__marshaller.Free(); } } @@ -123,6 +123,7 @@ void global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCollection pOut, out int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); byte* __pOut_native = default; @@ -141,6 +142,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pOut_native__marshaller.FromUnmanaged(__pOut_native); @@ -151,8 +153,11 @@ } finally { - // Cleanup - Perform required cleanup. - __pOut_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __pOut_native__marshaller.Free(); + } } } @@ -161,6 +166,7 @@ global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; byte* __retVal_native = default; int __invokeRetVal = default; @@ -176,6 +182,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -186,8 +193,11 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; @@ -198,6 +208,7 @@ global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement.ReturnPreserveSig(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionBlittableElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; byte* __retVal_native = default; // Setup - Perform required setup. @@ -210,6 +221,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -220,14 +232,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -245,12 +260,13 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __p_native__marshaller.FromUnmanaged(__p_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __p_native__numElements = size; __p_native__marshaller.GetUnmanagedValuesSource(__p_native__numElements).CopyTo(__p_native__marshaller.GetManagedValuesDestination(__p_native__numElements)); p = __p_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(p, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -258,7 +274,7 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __p_native__marshaller.Free(); } @@ -283,13 +299,14 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pIn_native__marshaller.FromUnmanaged(__pIn_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK size = __size_native; __pIn_native__numElements = size; __pIn_native__marshaller.GetUnmanagedValuesSource(__pIn_native__numElements).CopyTo(__pIn_native__marshaller.GetManagedValuesDestination(__pIn_native__numElements)); pIn = __pIn_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in pIn, in size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -297,7 +314,7 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pIn_native__marshaller.Free(); } @@ -322,12 +339,13 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pRef_native__marshaller.FromUnmanaged(__pRef_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __pRef_native__numElements = size; __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements).CopyTo(__pRef_native__marshaller.GetManagedValuesDestination(__pRef_native__numElements)); pRef = __pRef_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref pRef, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pRef_native = __pRef_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. @@ -341,7 +359,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__pRef_native__ownOriginal) { } @@ -368,9 +386,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out pOut, out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pOut_native = __pOut_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. @@ -384,7 +403,7 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pOut_native__marshaller.Free(); } @@ -405,9 +424,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. @@ -420,7 +440,7 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __invokeRetValUnmanaged__marshaller.Free(); } @@ -454,14 +474,14 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __retVal_native__marshaller.Free(); } return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -486,16 +506,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] partial interface IStatefulCollectionBlittableElement { } -} - +} + namespace SharedTypes.ComInterfaces { partial interface IStatefulCollectionBlittableElement diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs index d92b8dd..3e33bf5 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 124, 183, 82, 10, 139, 224, 116, 66, 161, 244, 26, 43, 242, 192, 126, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement { @@ -16,6 +16,7 @@ void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Method(global::SharedTypes.ComInterfaces.StatefulCollection p, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + bool __invokeSucceeded = default; byte* __p_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -44,11 +45,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __p_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __p_native__nativeSpan = __p_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __p_native__lastIndexMarshalled; ++__i0) @@ -66,6 +74,7 @@ void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodIn(in global::SharedTypes.ComInterfaces.StatefulCollection pIn, in int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + bool __invokeSucceeded = default; byte* __pIn_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -96,11 +105,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pIn_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __pIn_native__nativeSpan = __pIn_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __pIn_native__lastIndexMarshalled; ++__i0) @@ -118,6 +134,7 @@ void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodRef(ref global::SharedTypes.ComInterfaces.StatefulCollection pRef, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + bool __invokeSucceeded = default; byte* __pRef_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -146,6 +163,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pRef_native__marshaller.FromUnmanaged(__pRef_native); @@ -164,7 +182,13 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pRef_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) @@ -182,6 +206,7 @@ void global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.MethodOut(out global::SharedTypes.ComInterfaces.StatefulCollection pOut, out int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); byte* __pOut_native = default; @@ -200,6 +225,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pOut_native__marshaller.FromUnmanaged(__pOut_native); @@ -218,16 +244,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements); - for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__pOut_native__nativeSpan[__i0]); + System.ReadOnlySpan __pOut_native__nativeSpan = __pOut_native__marshaller.GetUnmanagedValuesSource(__pOut_native__numElements); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__pOut_native__nativeSpan[__i0]); + } } - } - __pOut_native__marshaller.Free(); + __pOut_native__marshaller.Free(); + } } } @@ -236,6 +265,7 @@ global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; byte* __retVal_native = default; int __invokeRetVal = default; @@ -251,6 +281,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -269,16 +300,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__marshaller.Free(); + __retVal_native__marshaller.Free(); + } } return __retVal; @@ -289,6 +323,7 @@ global::SharedTypes.ComInterfaces.StatefulCollection global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement.ReturnPreserveSig(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulCollectionStatelessElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulCollection __retVal = default; byte* __retVal_native = default; // Setup - Perform required setup. @@ -301,6 +336,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this, size); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -319,22 +355,25 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__marshaller.Free(); + __retVal_native__marshaller.Free(); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -352,7 +391,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __p_native__marshaller.FromUnmanaged(__p_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __p_native__numElements = size; { System.ReadOnlySpan __p_native__nativeSpan = __p_native__marshaller.GetUnmanagedValuesSource(__p_native__numElements); @@ -366,6 +404,8 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt p = __p_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(p, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -373,7 +413,7 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __p_native__marshaller.Free(); } @@ -398,7 +438,6 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pIn_native__marshaller.FromUnmanaged(__pIn_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK size = __size_native; __pIn_native__numElements = size; { @@ -413,6 +452,8 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI pIn = __pIn_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in pIn, in size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -420,7 +461,7 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pIn_native__marshaller.Free(); } @@ -446,7 +487,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pRef_native__marshaller.FromUnmanaged(__pRef_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __pRef_native__numElements = size; { System.ReadOnlySpan __pRef_native__nativeSpan = __pRef_native__marshaller.GetUnmanagedValuesSource(__pRef_native__numElements); @@ -460,6 +500,8 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com pRef = __pRef_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref pRef, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pRef_native = __pRef_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. @@ -480,7 +522,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__pRef_native__ownOriginal) { { @@ -514,9 +556,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out pOut, out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __pOut_native = __pOut_native__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. @@ -538,7 +581,7 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pOut_native__marshaller.Free(); } @@ -559,9 +602,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); // Marshal - Convert managed data to native data. @@ -582,7 +626,7 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __invokeRetValUnmanaged__marshaller.Free(); } @@ -621,14 +665,14 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __retVal_native__marshaller.Free(); } return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -653,16 +697,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] partial interface IStatefulCollectionStatelessElement { } -} - +} + namespace SharedTypes.ComInterfaces { partial interface IStatefulCollectionStatelessElement diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs index d24d371..cf9b008 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulFinallyMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatefulFinallyMarshalling { @@ -37,7 +37,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -68,7 +68,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -103,10 +103,9 @@ { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. param = __param_native__marshaller.ToManagedFinally(); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __param_native__marshaller.Free(); } - - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); } } @@ -146,7 +145,7 @@ param = __param_native__marshaller.ToManagedFinally(); } - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -181,10 +180,9 @@ { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. __retVal = __retVal_native__marshaller.ToManagedFinally(); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); } - - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); } return __retVal; @@ -217,16 +215,15 @@ { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. __retVal = __retVal_native__marshaller.ToManagedFinally(); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); } - - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -244,9 +241,10 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -254,7 +252,7 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -277,9 +275,10 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -287,7 +286,7 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -306,10 +305,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __param_native__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); @@ -322,7 +321,7 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -345,10 +344,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __param_native__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); @@ -361,7 +360,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -380,10 +379,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __invokeRetValUnmanaged__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); @@ -396,7 +395,7 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __invokeRetValUnmanaged__marshaller.Free(); } @@ -429,14 +428,14 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __retVal_native__marshaller.Free(); } return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -461,16 +460,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatefulFinallyMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatefulFinallyMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs index 5ea5243..b7e62a5 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatefulMarshalling { @@ -37,7 +37,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -68,7 +68,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -78,6 +78,7 @@ void global::SharedTypes.ComInterfaces.IStatefulMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulType param) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint __param_native = default; int __invokeRetVal = default; @@ -91,6 +92,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); @@ -99,8 +101,11 @@ } finally { - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __param_native__marshaller.Free(); + } } } @@ -134,7 +139,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -144,6 +149,7 @@ global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulType __retVal = default; nint __retVal_native = default; int __invokeRetVal = default; @@ -157,6 +163,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -165,8 +172,11 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; @@ -177,6 +187,7 @@ global::SharedTypes.ComInterfaces.StatefulType global::SharedTypes.ComInterfaces.IStatefulMarshalling.ReturnPreserveSig() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulType __retVal = default; nint __retVal_native = default; // Setup - Perform required setup. @@ -187,6 +198,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -195,14 +207,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -218,10 +233,11 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -229,7 +245,7 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -250,10 +266,11 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -261,7 +278,7 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -280,10 +297,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __param_native__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); @@ -296,7 +313,7 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -317,11 +334,11 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __param_native__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); @@ -334,7 +351,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -353,10 +370,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __invokeRetValUnmanaged__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); @@ -369,7 +386,7 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __invokeRetValUnmanaged__marshaller.Free(); } @@ -402,14 +419,14 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __retVal_native__marshaller.Free(); } return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -434,16 +451,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatefulMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatefulMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs index e030895..9387a8e 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 49, 71, 3, 193, 34, 74, 135, 161, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling { @@ -39,7 +39,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -72,7 +72,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -82,6 +82,7 @@ void global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatefulPinnedType param) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint __param_native = default; int __invokeRetVal = default; @@ -95,6 +96,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); @@ -103,8 +105,11 @@ } finally { - // Cleanup - Perform required cleanup. - __param_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __param_native__marshaller.Free(); + } } } @@ -136,7 +141,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } } @@ -146,6 +151,7 @@ global::SharedTypes.ComInterfaces.StatefulPinnedType global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulPinnedType __retVal = default; nint __retVal_native = default; int __invokeRetVal = default; @@ -159,6 +165,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -167,8 +174,11 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; @@ -179,6 +189,7 @@ global::SharedTypes.ComInterfaces.StatefulPinnedType global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling.ReturnPreserveSig() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatefulPinnedMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatefulPinnedType __retVal = default; nint __retVal_native = default; // Setup - Perform required setup. @@ -189,6 +200,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); @@ -197,14 +209,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -220,10 +235,11 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -231,7 +247,7 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -252,10 +268,11 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -263,7 +280,7 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -282,10 +299,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __param_native__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); @@ -296,7 +313,7 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -317,11 +334,11 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __param_native__marshaller.FromUnmanaged(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = __param_native__marshaller.ToManaged(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __param_native__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __param_native = __param_native__marshaller.ToUnmanaged(); @@ -332,7 +349,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __param_native__marshaller.Free(); } @@ -351,10 +368,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK __invokeRetValUnmanaged__marshaller.OnInvoked(); // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. __invokeRetValUnmanaged = __invokeRetValUnmanaged__marshaller.ToUnmanaged(); @@ -365,7 +382,7 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __invokeRetValUnmanaged__marshaller.Free(); } @@ -396,14 +413,14 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __retVal_native__marshaller.Free(); } return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -428,16 +445,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatefulPinnedMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatefulPinnedMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs index 003ef26..f3233f9 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling { @@ -33,7 +33,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); } } @@ -60,7 +60,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); } } @@ -70,6 +70,7 @@ void global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint __param_native = default; int __invokeRetVal = default; @@ -81,14 +82,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); + } } } @@ -115,7 +120,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native); } } @@ -125,6 +130,7 @@ global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType __retVal = default; nint __retVal_native = default; int __invokeRetVal = default; @@ -136,14 +142,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__retVal_native); + } } return __retVal; @@ -154,6 +164,7 @@ global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling.ReturnPreserveSig() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCallerAllocateBufferMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferType __retVal = default; nint __retVal_native = default; try @@ -162,20 +173,24 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -187,10 +202,11 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -210,10 +226,11 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -233,9 +250,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param); } @@ -260,10 +278,11 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(param); __param_native__ownOriginal = true; @@ -274,7 +293,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__param_native__ownOriginal) { global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.Free(__param_native__original); @@ -294,9 +313,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessCallerAllocatedBufferTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -329,8 +349,8 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -355,16 +375,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatelessCallerAllocateBufferMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatelessCallerAllocateBufferMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs index 747a27f..1b5d89d 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 124, 183, 82, 10, 139, 224, 116, 66, 161, 244, 26, 43, 242, 192, 126, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement { @@ -36,8 +36,8 @@ } finally { - // Cleanup - Perform required cleanup. - ; + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __p_native__numElements = 0; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.Free(__p_native); } } @@ -69,8 +69,8 @@ } finally { - // Cleanup - Perform required cleanup. - ; + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __pIn_native__numElements = 0; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.Free(__pIn_native); } } @@ -104,7 +104,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __pRef_native__numElements = size; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.Free(__pRef_native); } @@ -115,6 +115,7 @@ void global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCollection pOut, out int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); global::SharedTypes.ComInterfaces.NativeCollection __pOut_native = default; @@ -132,6 +133,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __pOut_native__numElements = size; @@ -140,9 +142,11 @@ } finally { - // Cleanup - Perform required cleanup. - __pOut_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__pOut_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__pOut_native); + } } } @@ -151,6 +155,7 @@ global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; global::SharedTypes.ComInterfaces.NativeCollection __retVal_native = default; int __invokeRetVal = default; @@ -165,6 +170,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = size; @@ -173,9 +179,11 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + } } return __retVal; @@ -186,6 +194,7 @@ global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement.ReturnPreserveSig(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionBlittableElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; global::SharedTypes.ComInterfaces.NativeCollection __retVal_native = default; // Setup - Perform required setup. @@ -197,6 +206,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction]> )__vtable_native[8])(__this, size); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = size; @@ -205,15 +215,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -228,12 +240,13 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __p_native__numElements = size; p = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__p_native, __p_native__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__p_native, __p_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(p)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(p, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -258,13 +271,14 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK size = __size_native; __pIn_native__numElements = size; pIn = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(pIn)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in pIn, in size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -289,12 +303,13 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __pRef_native__numElements = size; pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.GetManagedValuesDestination(pRef)); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref pRef, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __pRef_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); __pRef_native__ownOriginal = true; @@ -306,7 +321,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__pRef_native__ownOriginal) { __pRef_native__numElements = size; @@ -332,9 +347,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out pOut, out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __size_native = size; __pOut_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); @@ -361,9 +377,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements)); @@ -401,8 +418,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -427,16 +444,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] partial interface IStatelessCollectionBlittableElement { } -} - +} + namespace SharedTypes.ComInterfaces { partial interface IStatelessCollectionBlittableElement diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs index f855167..02d23ec 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 124, 183, 82, 10, 139, 224, 116, 66, 161, 244, 26, 43, 242, 192, 126, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement { @@ -45,14 +45,16 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __p_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__p_native, __p_native__numElements); for (int __i0 = 0; __i0 < __p_native__lastIndexMarshalled; ++__i0) { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.Free(__p_native__nativeSpan[__i0]); } - }; + } + + __p_native__numElements = 0; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.Free(__p_native); } } @@ -93,14 +95,16 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __pIn_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements); for (int __i0 = 0; __i0 < __pIn_native__lastIndexMarshalled; ++__i0) { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.Free(__pIn_native__nativeSpan[__i0]); } - }; + } + + __pIn_native__numElements = 0; global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.Free(__pIn_native); } } @@ -150,7 +154,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __pRef_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements); for (int __i0 = 0; __i0 < __pRef_native__lastIndexMarshalled; ++__i0) @@ -169,6 +173,7 @@ void global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.MethodOut(out global::SharedTypes.ComInterfaces.StatelessCollection pOut, out int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); System.Runtime.CompilerServices.Unsafe.SkipInit(out size); global::SharedTypes.ComInterfaces.NativeCollection __pOut_native = default; @@ -186,6 +191,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __pOut_native__numElements = size; @@ -201,17 +207,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements); - for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__pOut_native__nativeSpan[__i0]); + System.ReadOnlySpan __pOut_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements); + for (int __i0 = 0; __i0 < __pOut_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__pOut_native__nativeSpan[__i0]); + } } - } - __pOut_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__pOut_native); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__pOut_native); + } } } @@ -220,6 +228,7 @@ global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.Return(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; global::SharedTypes.ComInterfaces.NativeCollection __retVal_native = default; int __invokeRetVal = default; @@ -234,6 +243,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = size; @@ -249,17 +259,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + } } return __retVal; @@ -270,6 +282,7 @@ global::SharedTypes.ComInterfaces.StatelessCollection global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement.ReturnPreserveSig(int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessCollectionStatelessElement)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessCollection __retVal = default; global::SharedTypes.ComInterfaces.NativeCollection __retVal_native = default; // Setup - Perform required setup. @@ -281,6 +294,7 @@ __retVal_native = ((delegate* unmanaged[MemberFunction]> )__vtable_native[8])(__this, size); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = size; @@ -296,23 +310,25 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -327,7 +343,6 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __p_native__numElements = size; p = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__p_native, __p_native__numElements); { @@ -341,6 +356,8 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(p, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -365,7 +382,6 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK size = __size_native; __pIn_native__numElements = size; pIn = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); @@ -380,6 +396,8 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in pIn, in size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -405,7 +423,6 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __pRef_native__numElements = size; pRef = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); { @@ -419,6 +436,8 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref pRef, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __pRef_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.Bidirectional.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); __pRef_native__ownOriginal = true; @@ -437,7 +456,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__pRef_native__ownOriginal) { { @@ -471,9 +490,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out pOut, out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __size_native = size; __pOut_native = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); @@ -508,9 +528,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { @@ -561,8 +582,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -587,16 +608,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatelessCollectionStatelessElement { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatelessCollectionStatelessElement diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs index 6edf970..14914a8 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessFinallyMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 50, 71, 5, 193, 38, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessFinallyMarshalling { @@ -32,7 +32,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); } } @@ -58,7 +58,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); } } @@ -89,10 +89,9 @@ { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); } - - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); } } @@ -125,7 +124,7 @@ param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); } - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native); } } @@ -156,10 +155,9 @@ { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. __retVal = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__retVal_native); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__retVal_native); } - - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__retVal_native); } return __retVal; @@ -188,16 +186,15 @@ { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. __retVal = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__retVal_native); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__retVal_native); } - - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__retVal_native); } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -211,9 +208,10 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -235,9 +233,10 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -257,9 +256,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); } @@ -286,9 +286,10 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. param = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToManagedFinally(__param_native); // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(param); __param_native__ownOriginal = true; @@ -299,7 +300,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__param_native__ownOriginal) { global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.Free(__param_native__original); @@ -319,9 +320,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessFinallyTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -354,8 +356,8 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -380,16 +382,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatelessFinallyMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatelessFinallyMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs index 6cd4ff3..efc9a0b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessMarshalling { @@ -32,7 +32,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.Free(__param_native); } } @@ -58,7 +58,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.Free(__param_native); } } @@ -68,6 +68,7 @@ void global::SharedTypes.ComInterfaces.IStatelessMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessType param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint __param_native = default; int __invokeRetVal = default; @@ -79,14 +80,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.ConvertToManaged(__param_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__param_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__param_native); + } } } @@ -113,7 +118,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Bidirectional.Free(__param_native); } } @@ -123,6 +128,7 @@ global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessType __retVal = default; nint __retVal_native = default; int __invokeRetVal = default; @@ -134,14 +140,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native); + } } return __retVal; @@ -152,6 +162,7 @@ global::SharedTypes.ComInterfaces.StatelessType global::SharedTypes.ComInterfaces.IStatelessMarshalling.ReturnPreserveSig() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessType __retVal = default; nint __retVal_native = default; try @@ -160,20 +171,24 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -185,10 +200,11 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -208,10 +224,11 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.UnmanagedToManaged.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -231,9 +248,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.ConvertToUnmanaged(param); } @@ -258,10 +276,11 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Bidirectional.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Bidirectional.ConvertToUnmanaged(param); __param_native__ownOriginal = true; @@ -272,7 +291,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__param_native__ownOriginal) { global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.Bidirectional.Free(__param_native__original); @@ -292,9 +311,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.ConvertToUnmanaged(__invokeRetVal); } @@ -327,8 +347,8 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -353,16 +373,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatelessMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatelessMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.cs index 9410be7..a7303b7 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.cs @@ -1,431 +1,448 @@ // #pragma warning disable CS0612, CS0618 -file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType -{ - public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 153, 12, 187, 59, 108, 125, 209, 74, 190, 76, 172, 180, 194, 18, 127, 2 })); - - private static void** _vtable; - public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); +file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType +{ + public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 153, 12, 187, 59, 108, 125, 209, 74, 190, 76, 172, 180, 194, 18, 127, 2 })); + + private static void** _vtable; + public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); } -[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] -file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements -{ - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.Method(global::SharedTypes.ComInterfaces.StatelessPinnableCollection p, int size) - { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); - int __invokeRetVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __p_native = &global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetPinnableReference(p)) - { - __invokeRetVal = ((delegate* unmanaged[MemberFunction], int, int> )__vtable_native[3])(__this, (global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative)__p_native, size); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - System.GC.KeepAlive(this); - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.MethodIn(in global::SharedTypes.ComInterfaces.StatelessPinnableCollection pIn, in int size) - { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pIn_native = default; - int __invokeRetVal = default; - // Setup - Perform required setup. - int __pIn_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pIn_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(pIn, out __pIn_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(pIn).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements)); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) - { - __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int*, int> )__vtable_native[4])(__this, &__pIn_native, __size_native); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - System.GC.KeepAlive(this); - } - finally - { - // Cleanup - Perform required cleanup. - ; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.Free(__pIn_native); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessPinnableCollection pRef, int size) - { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pRef_native = default; - int __invokeRetVal = default; - // Setup - Perform required setup. - int __pRef_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pRef_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); - { - __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int, int> )__vtable_native[5])(__this, &__pRef_native, size); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - __pRef_native__numElements = size; - pRef = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesDestination(pRef)); - } - finally - { - // Cleanup - Perform required cleanup. - __pRef_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.Free(__pRef_native); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.MethodOut(out global::SharedTypes.ComInterfaces.StatelessPinnableCollection pOut, out int size) - { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); - System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); - System.Runtime.CompilerServices.Unsafe.SkipInit(out size); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pOut_native = default; - int __invokeRetVal = default; - // Setup - Perform required setup. - int __pOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __size_native = &size) - { - __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int*, int> )__vtable_native[6])(__this, &__pOut_native, __size_native); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - __pOut_native__numElements = size; - pOut = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(pOut)); - } - finally - { - // Cleanup - Perform required cleanup. - __pOut_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.Free(__pOut_native); - } - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - global::SharedTypes.ComInterfaces.StatelessPinnableCollection global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.Return(int size) - { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); - global::SharedTypes.ComInterfaces.StatelessPinnableCollection __retVal = default; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __retVal_native = default; - int __invokeRetVal = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - { - __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int> )__vtable_native[7])(__this, size, &__retVal_native); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = size; - __retVal = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(__retVal)); - } - finally - { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); - } - - return __retVal; - } - - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - global::SharedTypes.ComInterfaces.StatelessPinnableCollection global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.ReturnPreserveSig(int size) - { - var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); - global::SharedTypes.ComInterfaces.StatelessPinnableCollection __retVal = default; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - { - __retVal_native = ((delegate* unmanaged[MemberFunction]> )__vtable_native[8])(__this, size); - } - - System.GC.KeepAlive(this); - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = size; - __retVal = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(__retVal)); - } - finally - { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); - } - - return __retVal; - } +[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] +file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements +{ + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.Method(global::SharedTypes.ComInterfaces.StatelessPinnableCollection p, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); + int __invokeRetVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __p_native = &global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetPinnableReference(p)) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction], int, int> )__vtable_native[3])(__this, (global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative)__p_native, size); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + System.GC.KeepAlive(this); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.MethodIn(in global::SharedTypes.ComInterfaces.StatelessPinnableCollection pIn, in int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pIn_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pIn_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(pIn, out __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(pIn).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__pIn_native, __pIn_native__numElements)); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int*, int> )__vtable_native[4])(__this, &__pIn_native, __size_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + System.GC.KeepAlive(this); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __pIn_native__numElements = 0; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.Free(__pIn_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.MethodRef(ref global::SharedTypes.ComInterfaces.StatelessPinnableCollection pRef, int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pRef_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pRef_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int, int> )__vtable_native[5])(__this, &__pRef_native, size); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesDestination(pRef)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.Free(__pRef_native); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + void global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.MethodOut(out global::SharedTypes.ComInterfaces.StatelessPinnableCollection pOut, out int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pOut); + System.Runtime.CompilerServices.Unsafe.SkipInit(out size); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pOut_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __size_native = &size) + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int*, int> )__vtable_native[6])(__this, &__pOut_native, __size_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __pOut_native__numElements = size; + pOut = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__pOut_native, __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pOut_native, __pOut_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(pOut)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.Free(__pOut_native); + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessPinnableCollection global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.Return(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); + bool __invokeSucceeded = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection __retVal = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __retVal_native = default; + int __invokeRetVal = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __invokeRetVal = ((delegate* unmanaged[MemberFunction]*, int> )__vtable_native[7])(__this, size, &__retVal_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + } + } + + return __retVal; + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + global::SharedTypes.ComInterfaces.StatelessPinnableCollection global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements.ReturnPreserveSig(int size) + { + var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements)); + bool __invokeSucceeded = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection __retVal = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = ((delegate* unmanaged[MemberFunction]> )__vtable_native[8])(__this, size); + } + + __invokeSucceeded = true; + System.GC.KeepAlive(this); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = size; + __retVal = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.Free(__retVal_native); + } + } + + return __retVal; + } } -file unsafe partial interface InterfaceImplementation -{ - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __p_native, int size) - { - global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; - global::SharedTypes.ComInterfaces.StatelessPinnableCollection p = default; - int __retVal = default; - // Setup - Perform required setup. - int __p_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); - try - { - // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK - __p_native__numElements = size; - p = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__p_native, __p_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__p_native, __p_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(p)); - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - @this.Method(p, size); - } - catch (System.Exception __exception) - { - __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - - return __retVal; - } - - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __pIn_native__param, int* __size_native__param) - { - global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; - ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pIn_native = ref *__pIn_native__param; - global::SharedTypes.ComInterfaces.StatelessPinnableCollection pIn = default; - ref int __size_native = ref *__size_native__param; - int size = default; - int __retVal = default; - // Setup - Perform required setup. - int __pIn_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); - try - { - // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK - size = __size_native; - __pIn_native__numElements = size; - pIn = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(pIn)); - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - @this.MethodIn(in pIn, in size); - } - catch (System.Exception __exception) - { - __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - - return __retVal; - } - - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __pRef_native__param, int size) - { - global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; - ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pRef_native = ref *__pRef_native__param; - global::SharedTypes.ComInterfaces.StatelessPinnableCollection pRef = default; - int __retVal = default; - // Setup - Perform required setup. - int __pRef_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); - bool __pRef_native__ownOriginal = false; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pRef_native__original = __pRef_native; - try - { - // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK - __pRef_native__numElements = size; - pRef = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesDestination(pRef)); - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - @this.MethodRef(ref pRef, size); - // Marshal - Convert managed data to native data. - __pRef_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); - __pRef_native__ownOriginal = true; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); - } - catch (System.Exception __exception) - { - __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - finally - { - // Cleanup - Perform required cleanup. - if (__pRef_native__ownOriginal) - { - __pRef_native__numElements = size; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.Free(__pRef_native__original); - } - } - - return __retVal; - } - - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __pOut_native__param, int* __size_native__param) - { - global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; - ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pOut_native = ref *__pOut_native__param; - global::SharedTypes.ComInterfaces.StatelessPinnableCollection pOut = default; - ref int __size_native = ref *__size_native__param; - int size = default; - int __retVal = default; - // Setup - Perform required setup. - int __pOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); - try - { - // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - @this.MethodOut(out pOut, out size); - // Marshal - Convert managed data to native data. - __size_native = size; - __pOut_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(pOut).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__pOut_native, __pOut_native__numElements)); - } - catch (System.Exception __exception) - { - __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - - return __retVal; - } - - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __invokeRetValUnmanaged__param) - { - global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; - ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; - global::SharedTypes.ComInterfaces.StatelessPinnableCollection __invokeRetVal = default; - int __retVal = default; - // Setup - Perform required setup. - int __invokeRetValUnmanaged__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); - try - { - // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - __invokeRetVal = @this.Return(size); - // Marshal - Convert managed data to native data. - __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements)); - } - catch (System.Exception __exception) - { - __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); - } - - return __retVal; - } - - [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] - internal static global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) - { - global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; - global::SharedTypes.ComInterfaces.StatelessPinnableCollection __retVal = default; - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - // Unmarshal - Convert native data to managed data. - @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); - __retVal = @this.ReturnPreserveSig(size); - // Marshal - Convert managed data to native data. - __retVal_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(__retVal, out __retVal_native__numElements); - global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(__retVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements)); - } - catch (System.Exception __exception) - { - __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller>.ConvertToUnmanaged(__exception); - } - - return __retVal_native; - } +file unsafe partial interface InterfaceImplementation +{ + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __p_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection p = default; + int __retVal = default; + // Setup - Perform required setup. + int __p_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __p_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + __p_native__numElements = size; + p = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__p_native, __p_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__p_native, __p_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(p)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.Method(p, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __pIn_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; + ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pIn_native = ref *__pIn_native__param; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection pIn = default; + ref int __size_native = ref *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pIn_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pIn_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + size = __size_native; + __pIn_native__numElements = size; + pIn = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.AllocateContainerForManagedElements(__pIn_native, __pIn_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetUnmanagedValuesSource(__pIn_native, __pIn_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.UnmanagedToManaged.GetManagedValuesDestination(pIn)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodIn(in pIn, in size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __pRef_native__param, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; + ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pRef_native = ref *__pRef_native__param; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection pRef = default; + int __retVal = default; + // Setup - Perform required setup. + int __pRef_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pRef_native__numElements); + bool __pRef_native__ownOriginal = false; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pRef_native__original = __pRef_native; + try + { + // Unmarshal - Convert native data to managed data. + __pRef_native__numElements = size; + pRef = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForManagedElements(__pRef_native, __pRef_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesSource(__pRef_native, __pRef_native__numElements).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesDestination(pRef)); + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodRef(ref pRef, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK + // Marshal - Convert managed data to native data. + __pRef_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.AllocateContainerForUnmanagedElements(pRef, out __pRef_native__numElements); + __pRef_native__ownOriginal = true; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetManagedValuesSource(pRef).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.GetUnmanagedValuesDestination(__pRef_native, __pRef_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + if (__pRef_native__ownOriginal) + { + __pRef_native__numElements = size; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.Bidirectional.Free(__pRef_native__original); + } + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __pOut_native__param, int* __size_native__param) + { + global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; + ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __pOut_native = ref *__pOut_native__param; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection pOut = default; + ref int __size_native = ref *__size_native__param; + int size = default; + int __retVal = default; + // Setup - Perform required setup. + int __pOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pOut_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + @this.MethodOut(out pOut, out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK + // Marshal - Convert managed data to native data. + __size_native = size; + __pOut_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(pOut, out __pOut_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(pOut).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__pOut_native, __pOut_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size, global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative* __invokeRetValUnmanaged__param) + { + global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; + ref global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __invokeRetValUnmanaged = ref *__invokeRetValUnmanaged__param; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection __invokeRetVal = default; + int __retVal = default; + // Setup - Perform required setup. + int __invokeRetValUnmanaged__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __invokeRetValUnmanaged__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __invokeRetVal = @this.Return(size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK + // Marshal - Convert managed data to native data. + __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(__invokeRetVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__invokeRetValUnmanaged, __invokeRetValUnmanaged__numElements)); + } + catch (System.Exception __exception) + { + __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller.ConvertToUnmanaged(__exception); + } + + return __retVal; + } + + [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] + internal static global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, int size) + { + global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements @this = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollection __retVal = default; + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionNative __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Unmarshal - Convert native data to managed data. + @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); + __retVal = @this.ReturnPreserveSig(size); + // Marshal - Convert managed data to native data. + __retVal_native = global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.AllocateContainerForUnmanagedElements(__retVal, out __retVal_native__numElements); + global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetManagedValuesSource(__retVal).CopyTo(global::SharedTypes.ComInterfaces.StatelessPinnableCollectionMarshaller.ManagedToUnmanaged.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements)); + } + catch (System.Exception __exception) + { + __retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionAsDefaultMarshaller>.ConvertToUnmanaged(__exception); + } + + return __retVal_native; + } } -file unsafe partial interface InterfaceImplementation -{ - internal static void** CreateManagedVirtualFunctionTable() - { - void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements), sizeof(void*) * 9); - { - nint v0, v1, v2; - System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2); - vtable[0] = (void*)v0; - vtable[1] = (void*)v1; - vtable[2] = (void*)v2; - } - - { - vtable[3] = (void*)(delegate* unmanaged[MemberFunction], int, int> )&ABI_Method; - vtable[4] = (void*)(delegate* unmanaged[MemberFunction]*, int*, int> )&ABI_MethodIn; - vtable[5] = (void*)(delegate* unmanaged[MemberFunction]*, int, int> )&ABI_MethodRef; - vtable[6] = (void*)(delegate* unmanaged[MemberFunction]*, int*, int> )&ABI_MethodOut; - vtable[7] = (void*)(delegate* unmanaged[MemberFunction]*, int> )&ABI_Return; - vtable[8] = (void*)(delegate* unmanaged[MemberFunction]> )&ABI_ReturnPreserveSig; - } - - return vtable; - } +file unsafe partial interface InterfaceImplementation +{ + internal static void** CreateManagedVirtualFunctionTable() + { + void** vtable = (void**)System.Runtime.CompilerServices.RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnableCollectionBlittableElements), sizeof(void*) * 9); + { + nint v0, v1, v2; + System.Runtime.InteropServices.ComWrappers.GetIUnknownImpl(out v0, out v1, out v2); + vtable[0] = (void*)v0; + vtable[1] = (void*)v1; + vtable[2] = (void*)v2; + } + + { + vtable[3] = (void*)(delegate* unmanaged[MemberFunction], int, int> )&ABI_Method; + vtable[4] = (void*)(delegate* unmanaged[MemberFunction]*, int*, int> )&ABI_MethodIn; + vtable[5] = (void*)(delegate* unmanaged[MemberFunction]*, int, int> )&ABI_MethodRef; + vtable[6] = (void*)(delegate* unmanaged[MemberFunction]*, int*, int> )&ABI_MethodOut; + vtable[7] = (void*)(delegate* unmanaged[MemberFunction]*, int> )&ABI_Return; + vtable[8] = (void*)(delegate* unmanaged[MemberFunction]> )&ABI_ReturnPreserveSig; + } + + return vtable; + } } -namespace SharedTypes.ComInterfaces -{ - [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] - internal partial interface IStatelessPinnableCollectionBlittableElements - { - } +namespace SharedTypes.ComInterfaces +{ + [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] + internal partial interface IStatelessPinnableCollectionBlittableElements + { + } } -namespace SharedTypes.ComInterfaces -{ - internal partial interface IStatelessPinnableCollectionBlittableElements - { - } +namespace SharedTypes.ComInterfaces +{ + internal partial interface IStatelessPinnableCollectionBlittableElements + { + } } \ No newline at end of file diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs index a9b6a91..7a547e3 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 93, 250, 50, 71, 5, 193, 35, 74, 135, 167, 88, 220, 237, 212, 169, 179 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling { @@ -49,7 +49,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); } } @@ -59,6 +59,7 @@ void global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.MethodOut(out global::SharedTypes.ComInterfaces.StatelessPinnedType param, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out param); nint __param_native = default; int __invokeRetVal = default; @@ -70,14 +71,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); + } } } @@ -104,7 +109,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native); } } @@ -114,6 +119,7 @@ global::SharedTypes.ComInterfaces.StatelessPinnedType global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.Return() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessPinnedType __retVal = default; nint __retVal_native = default; int __invokeRetVal = default; @@ -125,14 +131,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__retVal_native); + } } return __retVal; @@ -143,6 +153,7 @@ global::SharedTypes.ComInterfaces.StatelessPinnedType global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling.ReturnPreserveSig() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStatelessPinnedMarshalling)); + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.StatelessPinnedType __retVal = default; nint __retVal_native = default; try @@ -151,20 +162,24 @@ __retVal_native = ((delegate* unmanaged[MemberFunction] )__vtable_native[8])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -176,10 +191,11 @@ internal static int ABI_Method(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Method(param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -199,10 +215,11 @@ internal static int ABI_MethodIn(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodIn(in param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -222,9 +239,10 @@ internal static int ABI_MethodOut(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodOut(out param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(param); } @@ -249,10 +267,11 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK param = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToManaged(__param_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.MethodRef(ref param, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __param_native = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(param); __param_native__ownOriginal = true; @@ -263,7 +282,7 @@ internal static int ABI_MethodRef(System.Runtime.InteropServices.ComWrappers.Com } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__param_native__ownOriginal) { global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.Free(__param_native__original); @@ -283,9 +302,10 @@ internal static int ABI_Return(System.Runtime.InteropServices.ComWrappers.ComInt try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Return(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::SharedTypes.ComInterfaces.StatelessPinnedTypeMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -318,8 +338,8 @@ internal static nint ABI_ReturnPreserveSig(System.Runtime.InteropServices.ComWra return __retVal_native; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -344,16 +364,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStatelessPinnedMarshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStatelessPinnedMarshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs index 2678430..a815939 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverride.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 219, 183, 70, 81, 136, 5, 155, 70, 184, 229, 179, 128, 144, 162, 252, 21 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStringMarshallingOverride { @@ -16,6 +16,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.StringMarshallingUtf8(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); + bool __invokeSucceeded = default; byte* __input_native = default; string __retVal = default; byte* __retVal_native = default; @@ -34,14 +35,20 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __input_native__marshaller.Free(); } @@ -53,6 +60,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalAsLPWString(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -66,14 +74,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -84,6 +96,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalUsingUtf16(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverride)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -97,20 +110,24 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -124,10 +141,11 @@ internal static int ABI_StringMarshallingUtf8(System.Runtime.InteropServices.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK input = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__input_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.StringMarshallingUtf8(input); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -150,10 +168,11 @@ internal static int ABI_MarshalAsLPWString(System.Runtime.InteropServices.ComWra try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalAsLPWString(input); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -176,10 +195,11 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalUsingUtf16(input); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -190,8 +210,8 @@ internal static int ABI_MarshalUsingUtf16(System.Runtime.InteropServices.ComWrap return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -213,16 +233,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStringMarshallingOverride { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStringMarshallingOverride diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs index 0966a52..87160b0 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 253, 227, 255, 58, 30, 209, 149, 65, 130, 80, 12, 115, 50, 25, 119, 160 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived { @@ -16,6 +16,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.StringMarshallingUtf8_2(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + bool __invokeSucceeded = default; byte* __input_native = default; string __retVal = default; byte* __retVal_native = default; @@ -34,14 +35,20 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __input_native__marshaller.Free(); } @@ -53,6 +60,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalAsLPWString_2(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -66,14 +74,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -84,6 +96,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalUsingUtf16_2(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -97,14 +110,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -115,6 +132,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.StringMarshallingUtf8(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + bool __invokeSucceeded = default; byte* __input_native = default; string __retVal = default; byte* __retVal_native = default; @@ -133,14 +151,20 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __input_native__marshaller.Free(); } @@ -152,6 +176,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalAsLPWString(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -165,14 +190,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -183,6 +212,7 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived.MarshalUsingUtf16(string input) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IStringMarshallingOverrideDerived)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -196,14 +226,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -212,8 +246,8 @@ string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.StringMarshallingUtf8(string input) => throw new System.Diagnostics.UnreachableException(); string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalAsLPWString(string input) => throw new System.Diagnostics.UnreachableException(); string global::SharedTypes.ComInterfaces.IStringMarshallingOverride.MarshalUsingUtf16(string input) => throw new System.Diagnostics.UnreachableException(); -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -227,10 +261,11 @@ internal static int ABI_StringMarshallingUtf8_2(System.Runtime.InteropServices.C try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK input = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__input_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.StringMarshallingUtf8_2(input); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -253,10 +288,11 @@ internal static int ABI_MarshalAsLPWString_2(System.Runtime.InteropServices.ComW try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalAsLPWString_2(input); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -279,10 +315,11 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK input = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__input_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.MarshalUsingUtf16_2(input); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -293,8 +330,8 @@ internal static int ABI_MarshalUsingUtf16_2(System.Runtime.InteropServices.ComWr return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -312,16 +349,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStringMarshallingOverrideDerived { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IStringMarshallingOverrideDerived diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs index 4eed3e8..3a38cb6 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF16Marshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 62, 95, 29, 225, 87, 221, 166, 65, 165, 158, 125, 17, 5, 81, 167, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IUTF16Marshalling { @@ -16,6 +16,7 @@ string global::SharedTypes.ComInterfaces.IUTF16Marshalling.GetString() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF16Marshalling)); + bool __invokeSucceeded = default; string __retVal = default; ushort* __retVal_native = default; int __invokeRetVal = default; @@ -27,14 +28,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -56,8 +61,8 @@ System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); System.GC.KeepAlive(this); } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -70,9 +75,10 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetString(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -93,10 +99,11 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetString(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -105,8 +112,8 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -127,16 +134,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IUTF16Marshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IUTF16Marshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs index 4bfc1fc..4a387f5 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.IUTF8Marshalling.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 62, 95, 29, 225, 87, 221, 166, 65, 165, 158, 125, 17, 5, 81, 167, 96 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.IUTF8Marshalling { @@ -16,6 +16,7 @@ string global::SharedTypes.ComInterfaces.IUTF8Marshalling.GetString() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.IUTF8Marshalling)); + bool __invokeSucceeded = default; string __retVal = default; byte* __retVal_native = default; int __invokeRetVal = default; @@ -27,14 +28,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } } return __retVal; @@ -65,12 +70,12 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __value_native__marshaller.Free(); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -83,9 +88,10 @@ internal static int ABI_GetString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetString(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__invokeRetVal); } @@ -106,10 +112,11 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK value = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__value_native); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.SetString(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -118,8 +125,8 @@ internal static int ABI_SetString(System.Runtime.InteropServices.ComWrappers.Com return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -140,16 +147,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IUTF8Marshalling { } -} - +} + namespace SharedTypes.ComInterfaces { internal partial interface IUTF8Marshalling diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs index 141779b..fa16993 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 149, 115, 133, 164, 251, 6, 110, 74, 129, 219, 53, 70, 27, 233, 153, 197 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails { @@ -16,6 +16,7 @@ int[] global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.GetConstSize() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + bool __invokeSucceeded = default; int[] __retVal = default; nint* __retVal_native = default; int __invokeRetVal = default; @@ -30,6 +31,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 10; @@ -45,17 +47,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; @@ -66,6 +70,7 @@ int[] global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.Get(out int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out size); int[] __retVal = default; nint* __retVal_native = default; @@ -83,6 +88,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = size; @@ -98,17 +104,19 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan[__i0]); + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = size; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; @@ -119,6 +127,7 @@ void global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails.Set(int[] value, int size) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.ICollectionMarshallingFails)); + bool __invokeSucceeded = default; nint* __value_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -149,11 +158,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __value_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __value_native__nativeSpan = __value_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __value_native__lastIndexMarshalled; ++__i0) @@ -165,8 +181,8 @@ __value_native__marshaller.Free(); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -182,9 +198,10 @@ internal static int ABI_GetConstSize(System.Runtime.InteropServices.ComWrappers. try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetConstSize(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { @@ -220,9 +237,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(out size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __size_native = size; __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); @@ -256,7 +274,6 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __value_native__numElements = size; value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); { @@ -270,6 +287,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Set(value, size); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -278,8 +297,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -301,16 +320,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface ICollectionMarshallingFails { } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { internal partial interface ICollectionMarshallingFails diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs index 072cd9e..f1b8bec 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 169, 168, 164, 159, 143, 61, 168, 72, 182, 251, 180, 91, 95, 27, 159, 182 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails { @@ -16,6 +16,7 @@ int[][] global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Get(out int[] widths, out int length) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); System.Runtime.CompilerServices.Unsafe.SkipInit(out length); int* __widths_native = default; @@ -37,6 +38,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __widths_native__numElements = length; @@ -66,31 +68,31 @@ } finally { - // Cleanup - Perform required cleanup. - __widths_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = widths[__i0]; + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) { - System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = widths[__i0]; { - global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } } - } - __retVal_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__retVal_native__nativeSpan[__i0]); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; @@ -101,6 +103,7 @@ int global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Get2(out int[][] array, out int[] widths) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out array); System.Runtime.CompilerServices.Unsafe.SkipInit(out widths); System.IntPtr* __array_native = default; @@ -120,6 +123,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __widths_native__numElements = __retVal; @@ -149,31 +153,31 @@ } finally { - // Cleanup - Perform required cleanup. - __widths_native__numElements = __retVal; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); + if (__invokeSucceeded) { - System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); - for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__widths_native); { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; + System.ReadOnlySpan __array_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__array_native, __array_native__numElements); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) { - System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; { - global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } } - } - __array_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } } - } - __array_native__numElements = __retVal; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__array_native); + } } return __retVal; @@ -184,6 +188,7 @@ int[][] global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.GetConstSize() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + bool __invokeSucceeded = default; int[][] __retVal = default; System.IntPtr* __retVal_native = default; int __invokeRetVal = default; @@ -198,6 +203,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 10; @@ -224,29 +230,30 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = 10; + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) { - System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = 10; { - global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + System.ReadOnlySpan __retVal_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __retVal_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__retVal_native__nativeSpan____i0__nativeSpan[__i1]); + } } - } - __retVal_native__nativeSpan____i0__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__retVal_native__nativeSpan[__i0]); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__retVal_native__nativeSpan[__i0]); + } } - } - __retVal_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; @@ -257,6 +264,7 @@ void global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails.Set(int[][] array, int[] widths, int length) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IJaggedIntArrayMarshallingFails)); + bool __invokeSucceeded = default; System.IntPtr* __array_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -299,11 +307,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __array_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __array_native__lastIndexMarshalled; ++__i0) @@ -317,7 +332,9 @@ { global::SharedTypes.ComInterfaces.MarshallingFails.ThrowOn4thElementMarshalled.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); } - }; + } + + __array_native__nativeSpan____i0__numElements = 0; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); } } @@ -325,8 +342,8 @@ __array_native__marshaller.Free(); } } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -348,9 +365,10 @@ internal static int ABI_Get(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get(out widths, out length); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __length_native = length; __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); @@ -404,9 +422,10 @@ internal static int ABI_Get2(System.Runtime.InteropServices.ComWrappers.ComInter try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.Get2(out array, out widths); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = __invokeRetVal; __widths_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(widths, out __widths_native__numElements); @@ -454,9 +473,10 @@ internal static int ABI_GetConstSize(System.Runtime.InteropServices.ComWrappers. try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.GetConstSize(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { @@ -503,7 +523,6 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __widths_native__numElements = length; widths = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__widths_native, __widths_native__numElements); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__widths_native, __widths_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(widths)); @@ -531,6 +550,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Set(array, widths, length); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -539,8 +560,8 @@ internal static int ABI_Set(System.Runtime.InteropServices.ComWrappers.ComInterf return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -563,16 +584,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IJaggedIntArrayMarshallingFails { } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { internal partial interface IJaggedIntArrayMarshallingFails diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs index 4211dde..2472114 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.ComInterfaceGenerator/SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.cs @@ -1,13 +1,13 @@ -// -#pragma warning disable CS0612, CS0618 +// +#pragma warning disable CS0612, CS0618 file unsafe class InterfaceInformation : System.Runtime.InteropServices.Marshalling.IIUnknownInterfaceType { public static System.Guid Iid { get; } = new(new System.ReadOnlySpan(new byte[] { 17, 194, 17, 190, 213, 118, 111, 73, 161, 23, 130, 245, 209, 50, 8, 247 })); private static void** _vtable; public static void** ManagedVirtualMethodTable => _vtable != null ? _vtable : (_vtable = InterfaceImplementation.CreateManagedVirtualFunctionTable()); -} - +} + [System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute] file unsafe partial interface InterfaceImplementation : global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails { @@ -16,6 +16,7 @@ void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.Param(string[] value) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + bool __invokeSucceeded = default; nint* __value_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -46,11 +47,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __value_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. _ = __value_native__lastIndexMarshalled; __value_native__marshaller.Free(); } @@ -61,6 +69,7 @@ void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.InParam(in string[] value) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + bool __invokeSucceeded = default; nint* __value_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -91,11 +100,18 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __value_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. _ = __value_native__lastIndexMarshalled; __value_native__marshaller.Free(); } @@ -146,7 +162,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. _ = __value_native__lastIndexMarshalled; __value_native__numElements = 10; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); @@ -158,6 +174,7 @@ void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.OutParam(out string[] value) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out value); nint* __value_native = default; int __invokeRetVal = default; @@ -172,6 +189,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __value_native__numElements = 10; @@ -187,9 +205,11 @@ } finally { - // Cleanup - Perform required cleanup. - __value_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__value_native); + } } } @@ -233,7 +253,7 @@ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __value_native__marshaller.Free(); } } @@ -243,6 +263,7 @@ void global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.ByValueInOutParam(string[] value) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + bool __invokeSucceeded = default; nint* __value_native = default; int __invokeRetVal = default; // Setup - Perform required setup. @@ -273,6 +294,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. { @@ -287,7 +309,13 @@ } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __value_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. _ = __value_native__lastIndexMarshalled; __value_native__marshaller.Free(); } @@ -298,6 +326,7 @@ string[] global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails.ReturnValue() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::SharedTypes.ComInterfaces.MarshallingFails.IStringArrayMarshallingFails)); + bool __invokeSucceeded = default; string[] __retVal = default; nint* __retVal_native = default; int __invokeRetVal = default; @@ -312,6 +341,7 @@ // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal); + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 10; @@ -327,15 +357,17 @@ } finally { - // Cleanup - Perform required cleanup. - __retVal_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } } return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { [System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvMemberFunction) })] @@ -350,7 +382,6 @@ internal static int ABI_Param(System.Runtime.InteropServices.ComWrappers.ComInte try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __value_native__numElements = 10; value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); { @@ -364,6 +395,8 @@ internal static int ABI_Param(System.Runtime.InteropServices.ComWrappers.ComInte @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.Param(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -386,7 +419,6 @@ internal static int ABI_InParam(System.Runtime.InteropServices.ComWrappers.ComIn try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __value_native__numElements = 10; value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); { @@ -400,6 +432,8 @@ internal static int ABI_InParam(System.Runtime.InteropServices.ComWrappers.ComIn @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.InParam(in value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK } catch (System.Exception __exception) { @@ -425,7 +459,6 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __value_native__numElements = 10; value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); { @@ -439,6 +472,8 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.RefParam(ref value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); __value_native__ownOriginal = true; @@ -457,7 +492,7 @@ internal static int ABI_RefParam(System.Runtime.InteropServices.ComWrappers.ComI } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__value_native__ownOriginal) { _ = __value_native__lastIndexMarshalled; @@ -482,9 +517,10 @@ internal static int ABI_OutParam(System.Runtime.InteropServices.ComWrappers.ComI try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.OutParam(out value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __value_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(value, out __value_native__numElements); { @@ -517,10 +553,11 @@ internal static int ABI_ByValueOutParam(System.Runtime.InteropServices.ComWrappe try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Clear(); @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.ByValueOutParam(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. { __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; @@ -553,7 +590,6 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK __value_native__numElements = 10; value = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__value_native, __value_native__numElements); { @@ -567,6 +603,8 @@ internal static int ABI_ByValueInOutParam(System.Runtime.InteropServices.ComWrap @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); @this.ByValueInOutParam(value); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. { __value_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(value).Length; @@ -600,9 +638,10 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C try { // Unmarshal - Convert native data to managed data. - __retVal = 0; // S_OK @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance(__this_native); __invokeRetVal = @this.ReturnValue(); + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __retVal = 0; // S_OK // Marshal - Convert managed data to native data. __invokeRetValUnmanaged = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__invokeRetVal, out __invokeRetValUnmanaged__numElements); { @@ -622,8 +661,8 @@ internal static int ABI_ReturnValue(System.Runtime.InteropServices.ComWrappers.C return __retVal; } -} - +} + file unsafe partial interface InterfaceImplementation { internal static void** CreateManagedVirtualFunctionTable() @@ -649,16 +688,16 @@ file unsafe partial interface InterfaceImplementation return vtable; } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { [System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute] internal partial interface IStringArrayMarshallingFails { } -} - +} + namespace SharedTypes.ComInterfaces.MarshallingFails { internal partial interface IStringArrayMarshallingFails diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs index b895405..60f1e9d 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/ManagedToNativeStubs.g.cs @@ -1,4 +1,4 @@ -// +// namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -26,7 +26,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -52,7 +52,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -80,7 +80,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -110,7 +110,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -150,7 +150,7 @@ internal unsafe partial interface Native } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } @@ -159,7 +159,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -187,7 +187,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -215,7 +215,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -243,7 +243,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -259,6 +259,7 @@ internal unsafe partial interface Native global::SharedTypes.IntWrapper global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.GetData() { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + bool __invokeSucceeded = default; global::SharedTypes.IntWrapper __retVal = default; int __retVal_native = default; try @@ -267,14 +268,18 @@ internal unsafe partial interface Native __retVal_native = ((delegate* unmanaged )__vtable_native[0])(__this); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. __retVal = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__retVal_native); + } } return __retVal; @@ -283,7 +288,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -312,7 +317,7 @@ internal unsafe partial interface Native } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__x_native); } } @@ -320,7 +325,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -351,7 +356,7 @@ internal unsafe partial interface Native } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native); } } @@ -359,7 +364,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -375,6 +380,7 @@ internal unsafe partial interface Native void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.SumAndSetData(global::SharedTypes.IntWrapper[] values, int numValues, out global::SharedTypes.IntWrapper oldValue) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); int* __values_native = default; int __oldValue_native = default; @@ -404,14 +410,21 @@ internal unsafe partial interface Native ((delegate* unmanaged )__vtable_native[3])(__this, __values_native, numValues, &__oldValue_native); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. oldValue = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__oldValue_native); } finally { - // Cleanup - Perform required cleanup. - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native); + _ = __values_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) @@ -427,7 +440,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -443,6 +456,7 @@ internal unsafe partial interface Native void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.SumAndSetData(ref global::SharedTypes.IntWrapper[] values, int numValues, out global::SharedTypes.IntWrapper oldValue) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + bool __invokeSucceeded = default; System.Runtime.CompilerServices.Unsafe.SkipInit(out oldValue); int* __values_native = default; int __oldValue_native = default; @@ -467,6 +481,7 @@ internal unsafe partial interface Native ((delegate* unmanaged )__vtable_native[4])(__this, &__values_native, numValues, &__oldValue_native); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. oldValue = global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.ConvertToManaged(__oldValue_native); @@ -483,8 +498,13 @@ internal unsafe partial interface Native } finally { - // Cleanup - Perform required cleanup. - global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__oldValue_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __values_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements); for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) @@ -501,7 +521,7 @@ internal unsafe partial interface Native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -517,6 +537,7 @@ internal unsafe partial interface Native void global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject.MultiplyWithData(global::SharedTypes.IntWrapper[] values123, int numValues) { var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::ComInterfaceGenerator.Tests.NativeExportsNE.UnmanagedToManagedCustomMarshalling.INativeObject)); + bool __invokeSucceeded = default; int* __values123_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __values123_native__marshaller = new(); @@ -544,6 +565,7 @@ internal unsafe partial interface Native ((delegate* unmanaged )__vtable_native[5])(__this, __values123_native, numValues); } + __invokeSucceeded = true; System.GC.KeepAlive(this); // Unmarshal - Convert native data to managed data. { @@ -558,7 +580,13 @@ internal unsafe partial interface Native } finally { - // Cleanup - Perform required cleanup. + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __values123_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. { System.ReadOnlySpan __values123_native__nativeSpan = __values123_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __values123_native__lastIndexMarshalled; ++__i0) @@ -574,4 +602,4 @@ internal unsafe partial interface Native } } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs index 02a9876..4be9aa0 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeInterfaces.g.cs @@ -1,4 +1,4 @@ -// +// namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -14,7 +14,7 @@ internal partial interface Native : INativeObject } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -30,7 +30,7 @@ internal partial interface Native : IStaticMethodTable } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -46,7 +46,7 @@ internal partial interface Native : INativeObject } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -62,4 +62,4 @@ internal partial interface Native : INativeObjectStateful } } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs index d63dd38..e100501 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/NativeToManagedStubs.g.cs @@ -1,4 +1,4 @@ -// +// namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -23,7 +23,7 @@ internal static int ABI_GetData(void* __this_native) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -46,7 +46,7 @@ internal static void ABI_SetData(void* __this_native, int x) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -74,7 +74,7 @@ internal static void ABI_ExchangeData(void* __this_native, int* __x_native__para } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -108,7 +108,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -148,7 +148,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__values_native__ownOriginal) { __values_native__numElements = numValues; @@ -160,7 +160,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -190,7 +190,7 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values_nat } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -218,7 +218,7 @@ internal static int ABI_GetData(void* __this_native) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -243,7 +243,7 @@ internal static void ABI_SetData(void* __this_native, int __x_native) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -275,7 +275,7 @@ internal static void ABI_ExchangeData(void* __this_native, int* __data_native__p } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__data_native__ownOriginal) { global::ComInterfaceGenerator.Tests.UnmanagedToManagedCustomMarshallingTests.IntWrapperMarshallerToIntWithFreeCounts.Free(__data_native__original); @@ -286,7 +286,7 @@ internal static void ABI_ExchangeData(void* __this_native, int* __data_native__p } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -328,7 +328,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -384,7 +384,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__values_native__ownOriginal) { { @@ -404,7 +404,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -454,7 +454,7 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -499,7 +499,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __values_native__marshaller.Free(); } } @@ -507,7 +507,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int* __values_native } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -568,7 +568,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. if (__values_native__ownOriginal) { { @@ -587,7 +587,7 @@ internal static void ABI_SumAndSetData(void* __this_native, int** __values_nativ } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -640,7 +640,7 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __values123_native__marshaller.Free(); } } @@ -648,4 +648,4 @@ internal static void ABI_MultiplyWithData(void* __this_native, int* __values123_ } } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs index e3af32f..bc54486 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.ComInterfaceGenerator/Microsoft.Interop.VtableIndexStubGenerator/PopulateVTable.g.cs @@ -1,4 +1,4 @@ -// +// namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -22,7 +22,7 @@ internal static unsafe void PopulateUnmanagedVirtualMethodTable(void** vtable) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -46,7 +46,7 @@ internal static unsafe void PopulateUnmanagedVirtualMethodTable(void** vtable) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -67,4 +67,4 @@ internal static unsafe void PopulateUnmanagedVirtualMethodTable(void** vtable) } } } -} +} diff --git a/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs index c2d6257..352883b 100644 --- a/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ b/ComInterfaceGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -1,4 +1,4 @@ -// +// namespace ComInterfaceGenerator.Tests { unsafe partial class NativeExportsNE @@ -6,7 +6,7 @@ unsafe partial class NativeExportsNE [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_com_object_data", ExactSpelling = true)] public static extern partial void SetComObjectData(void* obj, int data); } -} +} namespace ComInterfaceGenerator.Tests { unsafe partial class NativeExportsNE @@ -14,7 +14,7 @@ unsafe partial class NativeExportsNE [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_com_object_data", ExactSpelling = true)] public static extern partial int GetComObjectData(void* obj); } -} +} namespace ComInterfaceGenerator.Tests { unsafe partial class NativeExportsNE @@ -34,7 +34,7 @@ public static partial void SetComObjectData(global::SharedTypes.ComInterfaces.IG } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__obj_native); } @@ -43,7 +43,7 @@ public static partial void SetComObjectData(global::SharedTypes.ComInterfaces.IG static extern unsafe void __PInvoke(void* __obj_native, int __data_native); } } -} +} namespace ComInterfaceGenerator.Tests { unsafe partial class NativeExportsNE @@ -64,7 +64,7 @@ public static partial int GetComObjectData(global::SharedTypes.ComInterfaces.IGe } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__obj_native); } @@ -74,7 +74,7 @@ public static partial int GetComObjectData(global::SharedTypes.ComInterfaces.IGe static extern unsafe int __PInvoke(void* __obj_native); } } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class GeneratedComInterfaceComImportInteropTests @@ -83,6 +83,7 @@ public unsafe partial class GeneratedComInterfaceComImportInteropTests [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] private static partial global::SharedTypes.ComInterfaces.IGetAndSetInt NewNativeObject() { + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.IGetAndSetInt __retVal = default; void* __retVal_native = default; try @@ -91,13 +92,17 @@ public unsafe partial class GeneratedComInterfaceComImportInteropTests __retVal_native = __PInvoke(); } + __invokeSucceeded = true; // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + } } return __retVal; @@ -106,7 +111,7 @@ public unsafe partial class GeneratedComInterfaceComImportInteropTests static extern unsafe void* __PInvoke(); } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -114,7 +119,7 @@ internal unsafe partial class NativeExportsNE [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_com_object", ExactSpelling = true)] public static extern partial void* NewNativeObject(); } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class IGetAndSetIntTests @@ -122,7 +127,7 @@ public unsafe partial class IGetAndSetIntTests [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int", ExactSpelling = true)] public static extern partial void* NewNativeObject(); } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class IGetAndSetIntTests @@ -131,6 +136,7 @@ public unsafe partial class IGetAndSetIntTests [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] internal static partial global::SharedTypes.ComInterfaces.IGetAndSetInt NewNativeObjectWithMarshaller() { + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.IGetAndSetInt __retVal = default; void* __retVal_native = default; try @@ -139,13 +145,17 @@ public unsafe partial class IGetAndSetIntTests __retVal_native = __PInvoke(); } + __invokeSucceeded = true; // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ComInterfaceMarshaller.Free(__retVal_native); + } } return __retVal; @@ -154,7 +164,7 @@ public unsafe partial class IGetAndSetIntTests static extern unsafe void* __PInvoke(); } } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class IGetAndSetIntTests @@ -163,6 +173,7 @@ public unsafe partial class IGetAndSetIntTests [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] internal static partial global::SharedTypes.ComInterfaces.IGetAndSetInt NewNativeObjectWithUniqueMarshaller() { + bool __invokeSucceeded = default; global::SharedTypes.ComInterfaces.IGetAndSetInt __retVal = default; void* __retVal_native = default; try @@ -171,13 +182,17 @@ public unsafe partial class IGetAndSetIntTests __retVal_native = __PInvoke(); } + __invokeSucceeded = true; // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.UniqueComInterfaceMarshaller.ConvertToManaged(__retVal_native); } finally { - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.UniqueComInterfaceMarshaller.Free(__retVal_native); + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.UniqueComInterfaceMarshaller.Free(__retVal_native); + } } return __retVal; @@ -186,7 +201,7 @@ public unsafe partial class IGetAndSetIntTests static extern unsafe void* __PInvoke(); } } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class IGetIntArrayTests @@ -194,7 +209,7 @@ public unsafe partial class IGetIntArrayTests [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_get_and_set_int_array", ExactSpelling = true)] public static extern partial void* NewNativeObject(); } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -220,7 +235,7 @@ internal unsafe partial class ImplicitThis } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -231,7 +246,7 @@ internal unsafe partial class ImplicitThis public static extern partial void DeleteNativeObject(void* obj); } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -242,7 +257,7 @@ internal unsafe partial class ImplicitThis public static extern partial void SetNativeObjectData(void* obj, int data); } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -253,7 +268,7 @@ internal unsafe partial class ImplicitThis public static extern partial int GetNativeObjectData(void* obj); } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -279,7 +294,7 @@ internal unsafe partial class NoImplicitThis } } } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class PreserveSigTests @@ -287,7 +302,7 @@ public unsafe partial class PreserveSigTests [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_point_provider", ExactSpelling = true)] public static extern partial void* NewNativeObject(); } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class StringMarshallingTests @@ -295,7 +310,7 @@ public unsafe partial class StringMarshallingTests [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_utf8_marshalling", ExactSpelling = true)] public static extern partial void* NewIUtf8Marshalling(); } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class StringMarshallingTests @@ -303,7 +318,7 @@ public unsafe partial class StringMarshallingTests [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_utf16_marshalling", ExactSpelling = true)] public static extern partial void* NewIUtf16Marshalling(); } -} +} namespace ComInterfaceGenerator.Tests { public unsafe partial class StringMarshallingTests @@ -311,7 +326,7 @@ public unsafe partial class StringMarshallingTests [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "new_string_marshalling_override", ExactSpelling = true)] public static extern partial void* NewStringMarshallingOverride(); } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -322,7 +337,7 @@ internal unsafe partial class UnmanagedToManagedCustomMarshalling public static extern partial void SetNativeObjectData(void* obj, int data); } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -333,7 +348,7 @@ internal unsafe partial class UnmanagedToManagedCustomMarshalling public static extern partial int GetNativeObjectData(void* obj); } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -358,7 +373,7 @@ public static partial int ExchangeNativeObjectData(void* obj, ref int x) } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -385,7 +400,7 @@ public static partial int SumAndSetNativeObjectData(void* obj, int[] arr, int nu } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -420,7 +435,7 @@ public static partial int SumAndSetNativeObjectData(void* obj, ref int[] arr, in } finally { - // Cleanup - Perform required cleanup. + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. __arr_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__arr_native); } @@ -432,7 +447,7 @@ public static partial int SumAndSetNativeObjectData(void* obj, ref int[] arr, in } } } -} +} namespace ComInterfaceGenerator.Tests { internal unsafe partial class NativeExportsNE @@ -457,4 +472,4 @@ public static partial int MultiplyWithNativeObjectData(void* obj, int[] arr, int } } } -} +} diff --git a/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs index b8be077..c65872c 100644 --- a/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ b/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -80,7 +80,11 @@ public static partial int SumInArray(in int[] values, int numValues) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__marshaller.Free(); } @@ -122,7 +126,11 @@ public static partial void Duplicate(ref int[] values, int numValues) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } @@ -144,6 +152,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial int[] CreateRange(int start, int end, out int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); int[] __retVal = default; int* __retVal_native = default; @@ -158,6 +170,10 @@ public static partial int[] CreateRange(int start, int end, out int numValues) __retVal_native = __PInvoke(start, end, __numValues_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numValues; __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -165,9 +181,17 @@ public static partial int[] CreateRange(int start, int end, out int numValues) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -188,6 +212,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void CreateRange_Out(int start, int end, out int numValues, out int[] res) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); int* __res_native = default; @@ -202,6 +230,10 @@ public static partial void CreateRange_Out(int start, int end, out int numValues __PInvoke(start, end, __numValues_native, &__res_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __res_native__numElements = numValues; res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); @@ -209,9 +241,17 @@ public static partial void CreateRange_Out(int start, int end, out int numValues } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __res_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -299,7 +339,11 @@ public static partial void ReverseChars(ref char[] chars, int numElements) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __chars_native__numElements = numElements; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__chars_native); } @@ -321,6 +365,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial int SumStringLengths(string[] strArray) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.IntPtr* __strArray_native = default; int __retVal = default; // Setup - Perform required setup. @@ -348,10 +396,25 @@ public static partial int SumStringLengths(string[] strArray) __strArray_native = __strArray_native__marshaller.ToUnmanaged(); __retVal = __PInvoke(__strArray_native); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __strArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) @@ -420,9 +483,15 @@ public static partial void ReverseStrings_Ref(ref string[] strArray, out int num } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__strArray_native, __strArray_native__numElements); +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__strArray_native, __strArray_native__numElements); +>>>>>>> 4637ad2 (Latest chanages) for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) { global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); @@ -450,6 +519,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string[] ReverseStrings_Return(string[] strArray, out int numElements) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); System.IntPtr* __strArray_native = default; string[] __retVal = default; @@ -483,6 +556,10 @@ public static partial string[] ReverseStrings_Return(string[] strArray, out int __retVal_native = __PInvoke(__strArray_native, __numElements_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numElements; __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -497,6 +574,7 @@ public static partial string[] ReverseStrings_Return(string[] strArray, out int } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); @@ -508,6 +586,24 @@ public static partial string[] ReverseStrings_Return(string[] strArray, out int __retVal_native__numElements = numElements; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__retVal_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __strArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) @@ -537,6 +633,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void ReverseStrings_Out(string[] strArray, out int numElements, out string[] res) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); System.IntPtr* __strArray_native = default; @@ -570,6 +670,10 @@ public static partial void ReverseStrings_Out(string[] strArray, out int numElem __PInvoke(__strArray_native, __numElements_native, &__res_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __res_native__numElements = numElements; res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); @@ -584,6 +688,7 @@ public static partial void ReverseStrings_Out(string[] strArray, out int numElem } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements); @@ -595,6 +700,24 @@ public static partial void ReverseStrings_Out(string[] strArray, out int numElem __res_native__numElements = numElements; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__res_native, __res_native__numElements); + for (int __i0 = 0; __i0 < __res_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__res_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); + _ = __strArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) @@ -623,6 +746,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial byte[] GetLongBytes(long l) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte[] __retVal = default; byte* __retVal_native = default; // Setup - Perform required setup. @@ -634,6 +761,10 @@ public static partial byte[] GetLongBytes(long l) __retVal_native = __PInvoke(l); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 8; __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -641,9 +772,17 @@ public static partial byte[] GetLongBytes(long l) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = 8; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -684,7 +823,11 @@ public static partial void Append(ref int[] values, int numOriginalValues, int n } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__numElements = checked(1 + numOriginalValues); global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); } @@ -740,7 +883,11 @@ public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __array_native__marshaller.Free(); } @@ -762,6 +909,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void DoubleValues(global::SharedTypes.IntStructWrapper[] array, int length) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.IntStructWrapperNative* __array_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); @@ -789,6 +940,10 @@ public static partial void DoubleValues(global::SharedTypes.IntStructWrapper[] a __PInvoke(__array_native, length); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. { __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; @@ -802,7 +957,17 @@ public static partial void DoubleValues(global::SharedTypes.IntStructWrapper[] a } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __array_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __array_native__lastIndexMarshalled; __array_native__marshaller.Free(); } @@ -824,6 +989,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool AndAllMembers(global::SharedTypes.BoolStruct[] pArray, int length) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; bool __retVal = default; byte __retVal_native = default; @@ -853,12 +1022,26 @@ public static partial bool AndAllMembers(global::SharedTypes.BoolStruct[] pArray __retVal_native = __PInvoke(__pArray_native, length); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __pArray_native__lastIndexMarshalled; __pArray_native__marshaller.Free(); } @@ -881,6 +1064,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool AndAllMembersIn(in global::SharedTypes.BoolStruct[] pArray, int length) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; bool __retVal = default; byte __retVal_native = default; @@ -910,12 +1097,26 @@ public static partial bool AndAllMembersIn(in global::SharedTypes.BoolStruct[] p __retVal_native = __PInvoke(&__pArray_native, length); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __pArray_native__lastIndexMarshalled; __pArray_native__marshaller.Free(); } @@ -974,7 +1175,11 @@ public static partial void NegateBools(ref global::SharedTypes.BoolStruct[] bool } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); @@ -997,6 +1202,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native = default; @@ -1028,6 +1237,10 @@ public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStru __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __pBoolStructOut_native__numElements = numValues; pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); @@ -1042,9 +1255,20 @@ public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStru } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __pBoolStructOut_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -1066,6 +1290,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::SharedTypes.BoolStruct[] NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; global::SharedTypes.BoolStruct[] __retVal = default; global::SharedTypes.BoolStructMarshaller.BoolStructNative* __retVal_native = default; @@ -1097,6 +1325,10 @@ public unsafe partial class Arrays __retVal_native = __PInvoke(__boolStruct_native, numValues); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numValues; __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -1111,9 +1343,20 @@ public unsafe partial class Arrays } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -1136,6 +1379,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int numColumns) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.IntPtr* __matrix_native = default; int[][] __retVal = default; System.IntPtr* __retVal_native = default; @@ -1171,6 +1418,10 @@ public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int __retVal_native = __PInvoke(__matrix_native, (int*)__numRows_native, numColumns); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numColumns; __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -1189,6 +1440,7 @@ public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); @@ -1203,13 +1455,37 @@ public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int __retVal_native__numElements = numColumns; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __matrix_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __matrix_native__lastIndexMarshalled; ++__i0) { int __matrix_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); +<<<<<<< HEAD ; +======= + __matrix_native__nativeSpan____i0__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__matrix_native__nativeSpan[__i0]); } } @@ -1281,7 +1557,11 @@ public static unsafe partial int SumInArray(in int*[] values, int numValues) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__marshaller.Free(); } @@ -1323,7 +1603,11 @@ public static unsafe partial void Duplicate(ref int*[] values, int numValues) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__values_native); } @@ -1345,6 +1629,10 @@ public unsafe partial class Arrays [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static unsafe partial int*[] ReturnDuplicate(int*[] values, int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) int*[] __retVal = default; nint* __retVal_native = default; // Setup - Perform required setup. @@ -1358,6 +1646,10 @@ public unsafe partial class Arrays __retVal_native = __PInvoke((nint*)__values_native, numValues); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numValues; __retVal = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -1365,9 +1657,17 @@ public unsafe partial class Arrays } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -2077,6 +2377,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Utf8StringSpan(global::System.ReadOnlySpan s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.IntPtr* __s_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); @@ -2103,10 +2407,25 @@ public static partial void Utf8StringSpan(global::System.ReadOnlySpan s) __s_native = __s_native__marshaller.ToUnmanaged(); __PInvoke(__s_native); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __s_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) @@ -2135,6 +2454,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Utf8StringArray(string[] s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.IntPtr* __s_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); @@ -2161,10 +2484,25 @@ public static partial void Utf8StringArray(string[] s) __s_native = __s_native__marshaller.ToUnmanaged(); __PInvoke(__s_native); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __s_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) @@ -2193,6 +2531,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void MarshalSingleDimensionalArray(global::SharedTypes.BoolStruct[] c) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) nint* __c_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); @@ -2219,10 +2561,25 @@ public static partial void MarshalSingleDimensionalArray(global::SharedTypes.Boo __c_native = __c_native__marshaller.ToUnmanaged(); __PInvoke(__c_native); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __c_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) @@ -2251,6 +2608,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked(global::SharedTypes.BoolStruct[][] c) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) nint* __c_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); @@ -2277,10 +2638,25 @@ public static partial void MarshalMultidimensionalArray_CheckOuterArrayIsIndexTr __c_native = __c_native__marshaller.ToUnmanaged(); __PInvoke(__c_native); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __c_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) @@ -2309,6 +2685,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreCleared(global::SharedTypes.BoolStruct[][] c) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.IntPtr* __c_native = default; // Setup - Perform required setup. scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); @@ -2346,10 +2726,25 @@ public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreClear __c_native = __c_native__marshaller.ToUnmanaged(); __PInvoke(__c_native); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __c_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) @@ -2363,7 +2758,13 @@ public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreClear { global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__c_native__nativeSpan____i0__nativeSpan[__i1]); } +<<<<<<< HEAD }; +======= + } + + __c_native__nativeSpan____i0__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__c_native__nativeSpan[__i0]); } } @@ -2424,9 +2825,15 @@ public static partial void MarshalArray_Ref(ref global::SharedTypes.BoolStruct[] } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__c_native, __c_native__numElements); +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__c_native, __c_native__numElements); +>>>>>>> 4637ad2 (Latest chanages) for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) { global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); @@ -2454,6 +2861,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; nint* __pBoolStructOut_native = default; @@ -2485,6 +2896,10 @@ public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolS __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __pBoolStructOut_native__numElements = numValues; pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); @@ -2499,6 +2914,7 @@ public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolS } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); @@ -2510,6 +2926,24 @@ public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolS __pBoolStructOut_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -2531,6 +2965,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths, out global::SharedTypes.BoolStruct[][] pBoolStructOut) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); System.IntPtr* __boolStruct_native = default; System.IntPtr* __pBoolStructOut_native = default; @@ -2574,6 +3012,10 @@ public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] b __PInvoke(__boolStruct_native, length, (int*)__widths_native, &__pBoolStructOut_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __pBoolStructOut_native__numElements = length; pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); @@ -2599,6 +3041,7 @@ public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] b } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); @@ -2622,13 +3065,46 @@ public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] b __pBoolStructOut_native__numElements = length; global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) + { + int __pBoolStructOut_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); + __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) { int __boolStruct_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); +<<<<<<< HEAD ; +======= + __boolStruct_native__nativeSpan____i0__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0]); } } @@ -2653,6 +3129,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) nint* __array_native = default; bool __retVal = default; byte __retVal_native = default; @@ -2673,6 +3153,10 @@ public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] __retVal_native = __PInvoke(__array_native, length, start); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; { @@ -2687,6 +3171,7 @@ public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); @@ -2696,6 +3181,21 @@ public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] } } +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan[__i0]); + } + } + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __array_native__marshaller.Free(); } @@ -2717,6 +3217,10 @@ public unsafe partial class MarshallingFails [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper[][] array, int length, int[] widths, int start) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.IntPtr* __array_native = default; bool __retVal = default; byte __retVal_native = default; @@ -2738,6 +3242,10 @@ public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper __retVal_native = __PInvoke(__array_native, length, (int*)__widths_native, start); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; { @@ -2763,6 +3271,7 @@ public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); @@ -2784,6 +3293,32 @@ public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper } } +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + } + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __array_native__marshaller.Free(); } @@ -2841,9 +3376,15 @@ public static partial void NegateBoolsRef(ref global::SharedTypes.BoolStruct[] b } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); +>>>>>>> 4637ad2 (Latest chanages) for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) { global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__boolStruct_native__nativeSpan[__i0]); @@ -2907,9 +3448,15 @@ public static partial void NegateBoolsRef2D_LastElementMarshalling(ref global::S } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); +>>>>>>> 4637ad2 (Latest chanages) for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) { global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__boolStruct_native__nativeSpan[__i0]); @@ -2997,16 +3544,26 @@ public static partial void NegateBoolsRef2D_ClearMarshalling(ref global::SharedT } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. { System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); +>>>>>>> 4637ad2 (Latest chanages) for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) { int __boolStruct_native__nativeSpan____i0__numElements; System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; { +<<<<<<< HEAD System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); +======= + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); +>>>>>>> 4637ad2 (Latest chanages) for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__nativeSpan.Length; ++__i1) { global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); @@ -3057,8 +3614,13 @@ public static partial int Sum(global::System.Collections.Generic.List value } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. ; +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3100,8 +3662,13 @@ public static partial int SumWithBuffer(global::System.Collections.Generic.List< } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. ; +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -3150,14 +3717,24 @@ public static unsafe partial int SumWithFreeTracking(global::System.Collections. } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) { global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); } +<<<<<<< HEAD }; +======= + } + + __values_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3226,8 +3803,13 @@ public static partial int SumInArray(in global::System.Collections.Generic.List< } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. ; +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3272,7 +3854,11 @@ public static partial void Duplicate(ref global::System.Collections.Generic.List } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__values_native); } @@ -3297,6 +3883,10 @@ public unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); global::System.Collections.Generic.List __retVal = default; byte* __retVal_native = default; @@ -3311,6 +3901,10 @@ public unsafe partial class Stateless __retVal_native = __PInvoke(start, end, __numValues_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numValues; __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -3318,9 +3912,17 @@ public unsafe partial class Stateless } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -3344,6 +3946,10 @@ public unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); byte* __res_native = default; @@ -3358,6 +3964,10 @@ public static partial void CreateRange_Out(int start, int end, out int numValues __PInvoke(start, end, __numValues_native, &__res_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __res_native__numElements = numValues; res = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); @@ -3365,9 +3975,17 @@ public static partial void CreateRange_Out(int start, int end, out int numValues } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __res_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__res_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__res_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -3390,6 +4008,10 @@ public unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Collections.Generic.List GetLongBytes(long l) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::System.Collections.Generic.List __retVal = default; byte* __retVal_native = default; // Setup - Perform required setup. @@ -3401,6 +4023,10 @@ public unsafe partial class Stateless __retVal_native = __PInvoke(l); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 8; __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -3408,9 +4034,17 @@ public unsafe partial class Stateless } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = 8; global::SharedTypes.ListMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -3463,9 +4097,15 @@ public static partial bool AndAllMembers(global::System.Collections.Generic.List } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. _ = __pArray_native__lastIndexMarshalled; ; +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__pArray_native); } @@ -3519,9 +4159,15 @@ public static partial bool AndAllMembersIn(in global::System.Collections.Generic } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. _ = __pArray_native__lastIndexMarshalled; ; +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__pArray_native); } @@ -3582,7 +4228,11 @@ public static partial void NegateBools(ref global::System.Collections.Generic.Li } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__boolStruct_native); @@ -3608,6 +4258,10 @@ public unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); byte* __boolStruct_native = default; byte* __pBoolStructOut_native = default; @@ -3634,6 +4288,10 @@ public static partial void NegateBools(global::System.Collections.Generic.List>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __pBoolStructOut_native__numElements = numValues; pBoolStructOut = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); @@ -3648,11 +4306,23 @@ public static partial void NegateBools(global::System.Collections.Generic.List.Free(__pBoolStructOut_native); _ = __boolStruct_native__lastIndexMarshalled; ; +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__pBoolStructOut_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__boolStruct_native); } @@ -3676,6 +4346,10 @@ public unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __boolStruct_native = default; global::System.Collections.Generic.List __retVal = default; byte* __retVal_native = default; @@ -3702,6 +4376,10 @@ public unsafe partial class Stateless __retVal_native = __PInvoke(__boolStruct_native, numValues); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numValues; __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -3716,11 +4394,23 @@ public unsafe partial class Stateless } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = numValues; global::SharedTypes.ListMarshaller.Free(__retVal_native); _ = __boolStruct_native__lastIndexMarshalled; ; +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = 0; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.ListMarshaller.Free(__boolStruct_native); } @@ -3771,9 +4461,12 @@ public static partial int GuaranteedUnmarshal(out global::System.Collections.Gen __ret_native__numElements = 1; ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); } +<<<<<<< HEAD // Cleanup - Perform required cleanup. __ret_native__numElements = 1; +======= +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -3823,9 +4516,12 @@ public static partial int GuaranteedUnmarshal(out global::System.Collections.Gen __ret_native__numElements = 1; ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); } +<<<<<<< HEAD // Cleanup - Perform required cleanup. __ret_native__numElements = 1; +======= +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -3870,7 +4566,11 @@ public static partial int Sum(global::System.Collections.Generic.List value } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__marshaller.Free(); } @@ -3895,6 +4595,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __values_native = default; int __retVal = default; // Setup - Perform required setup. @@ -3922,10 +4626,25 @@ public static unsafe partial int SumWithFreeTracking(global::System.Collections. __values_native = __values_native__marshaller.ToUnmanaged(); __retVal = __PInvoke(__values_native, numValues); } +<<<<<<< HEAD } finally { // Cleanup - Perform required cleanup. +======= + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __values_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) { System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) @@ -3979,7 +4698,11 @@ public static partial int SumInArray(in global::System.Collections.Generic.List< } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__marshaller.Free(); } @@ -4029,7 +4752,11 @@ public static partial void Duplicate(ref global::System.Collections.Generic.List } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__marshaller.Free(); } @@ -4053,6 +4780,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); global::System.Collections.Generic.List __retVal = default; byte* __retVal_native = default; @@ -4068,6 +4799,10 @@ public unsafe partial class Stateful __retVal_native = __PInvoke(start, end, __numValues_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); // Unmarshal - Convert native data to managed data. @@ -4077,8 +4812,16 @@ public unsafe partial class Stateful } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -4102,6 +4845,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); System.Runtime.CompilerServices.Unsafe.SkipInit(out res); byte* __res_native = default; @@ -4117,6 +4864,10 @@ public static partial void CreateRange_Out(int start, int end, out int numValues __PInvoke(start, end, __numValues_native, &__res_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __res_native__marshaller.FromUnmanaged(__res_native); // Unmarshal - Convert native data to managed data. @@ -4126,8 +4877,16 @@ public static partial void CreateRange_Out(int start, int end, out int numValues } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __res_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __res_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -4150,6 +4909,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Collections.Generic.List GetLongBytes(long l) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::System.Collections.Generic.List __retVal = default; byte* __retVal_native = default; // Setup - Perform required setup. @@ -4162,6 +4925,10 @@ public unsafe partial class Stateful __retVal_native = __PInvoke(l); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); // Unmarshal - Convert native data to managed data. @@ -4171,8 +4938,16 @@ public unsafe partial class Stateful } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -4196,6 +4971,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __pArray_native = default; bool __retVal = default; byte __retVal_native = default; @@ -4225,12 +5004,26 @@ public static partial bool AndAllMembers(global::System.Collections.Generic.List __retVal_native = __PInvoke(__pArray_native, length); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __pArray_native__lastIndexMarshalled; __pArray_native__marshaller.Free(); } @@ -4256,6 +5049,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __pArray_native = default; bool __retVal = default; byte __retVal_native = default; @@ -4285,12 +5082,26 @@ public static partial bool AndAllMembersIn(in global::System.Collections.Generic __retVal_native = __PInvoke(&__pArray_native, length); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __pArray_native__lastIndexMarshalled; __pArray_native__marshaller.Free(); } @@ -4316,6 +5127,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __boolStruct_native = default; // Setup - Perform required setup. scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); @@ -4341,6 +5156,10 @@ public static partial void NegateBools(ref global::System.Collections.Generic.Li __PInvoke(&__boolStruct_native, numValues); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __boolStruct_native__marshaller.FromUnmanaged(__boolStruct_native); // Unmarshal - Convert native data to managed data. @@ -4358,7 +5177,17 @@ public static partial void NegateBools(ref global::System.Collections.Generic.Li } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -4383,6 +5212,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); byte* __boolStruct_native = default; byte* __pBoolStructOut_native = default; @@ -4415,6 +5248,10 @@ public static partial void NegateBools(global::System.Collections.Generic.List>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); // Unmarshal - Convert native data to managed data. @@ -4432,8 +5269,19 @@ public static partial void NegateBools(global::System.Collections.Generic.List>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -4458,6 +5306,10 @@ public unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __boolStruct_native = default; global::System.Collections.Generic.List __retVal = default; byte* __retVal_native = default; @@ -4490,6 +5342,10 @@ public unsafe partial class Stateful __retVal_native = __PInvoke(__boolStruct_native, numValues); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); // Unmarshal - Convert native data to managed data. @@ -4507,8 +5363,19 @@ public unsafe partial class Stateful } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __boolStruct_native__lastIndexMarshalled; __boolStruct_native__marshaller.Free(); } @@ -4561,10 +5428,16 @@ public static partial int GuaranteedUnmarshal(out global::System.Collections.Gen { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. ret = __ret_native__marshaller.ToManagedFinally(); +<<<<<<< HEAD } // Cleanup - Perform required cleanup. __ret_native__marshaller.Free(); +======= + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __ret_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -4615,10 +5488,16 @@ public static partial int GuaranteedUnmarshal(out global::System.Collections.Gen { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. ret = __ret_native__marshaller.ToManagedFinally(); +<<<<<<< HEAD } // Cleanup - Perform required cleanup. __ret_native__marshaller.Free(); +======= + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __ret_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -4640,6 +5519,10 @@ internal unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void DeepDuplicateStrings(global::SharedTypes.StringContainer strings, out global::SharedTypes.StringContainer pStringsOut) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out pStringsOut); global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; global::SharedTypes.StringContainerMarshaller.StringContainerNative __pStringsOut_native = default; @@ -4651,13 +5534,27 @@ public static partial void DeepDuplicateStrings(global::SharedTypes.StringContai __PInvoke(__strings_native, &__pStringsOut_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. pStringsOut = global::SharedTypes.StringContainerMarshaller.Out.ConvertToManaged(__pStringsOut_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::SharedTypes.StringContainerMarshaller.Out.Free(__pStringsOut_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.StringContainerMarshaller.Out.Free(__pStringsOut_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.StringContainerMarshaller.In.Free(__strings_native); } @@ -4692,7 +5589,11 @@ public static partial void ReverseStrings(ref global::SharedTypes.StringContaine } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.StringContainerMarshaller.Ref.Free(__strings_native); } @@ -4823,6 +5724,10 @@ internal unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) int* __pInt_native = default; global::SharedTypes.IntWrapper __retVal = default; int* __retVal_native = default; @@ -4834,13 +5739,27 @@ internal unsafe partial class Stateless __retVal_native = __PInvoke(__pInt_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.IntWrapperMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::SharedTypes.IntWrapperMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.IntWrapperMarshaller.Free(__pInt_native); } @@ -4862,6 +5781,10 @@ internal unsafe partial class Stateless [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; int* __retVal_native = default; try @@ -4872,13 +5795,25 @@ internal unsafe partial class Stateless __retVal_native = __PInvoke((int*)__pInt_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -5094,6 +6029,10 @@ internal unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; int* __retVal_native = default; try @@ -5104,13 +6043,25 @@ internal unsafe partial class Stateful __retVal_native = __PInvoke((int*)__pInt_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -5131,6 +6082,10 @@ internal unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRefNoAlloc(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) int* __pInt_native = default; global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; int* __retVal_native = default; @@ -5148,13 +6103,25 @@ internal unsafe partial class Stateful __retVal_native = __PInvoke(__pInt_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -5175,6 +6142,10 @@ internal unsafe partial class Stateful [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) int* __pInt_native = default; global::SharedTypes.IntWrapper __retVal = default; int* __retVal_native = default; @@ -5191,6 +6162,10 @@ internal unsafe partial class Stateful __retVal_native = __PInvoke(__pInt_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); // Unmarshal - Convert native data to managed data. @@ -5198,8 +6173,18 @@ internal unsafe partial class Stateful } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __pInt_native__marshaller.Free(); } @@ -5246,10 +6231,16 @@ public static partial int GuaranteedUnmarshal(out int ret) { // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. __retVal = __retVal_native__marshaller.ToManagedFinally(); +<<<<<<< HEAD } // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -5282,7 +6273,11 @@ public static partial void ReverseReplaceString(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -5624,6 +6619,10 @@ public unsafe partial class NativeExportsSafeHandle [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] private static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; nint __retVal_native = default; // Setup - Perform required setup. @@ -5634,6 +6633,10 @@ public unsafe partial class NativeExportsSafeHandle __retVal_native = __PInvoke(); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); // Unmarshal - Convert native data to managed data. @@ -5641,8 +6644,16 @@ public unsafe partial class NativeExportsSafeHandle } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -5661,6 +6672,10 @@ unsafe partial class NativeExportsNE [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; nint __retVal_native = default; // Setup - Perform required setup. @@ -5671,6 +6686,10 @@ unsafe partial class NativeExportsNE __retVal_native = __PInvoke(); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __retVal_native__marshaller.FromUnmanaged(__retVal_native); // Unmarshal - Convert native data to managed data. @@ -5678,8 +6697,16 @@ unsafe partial class NativeExportsNE } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -5697,6 +6724,10 @@ unsafe partial class NativeExportsNE [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void AllocateHandle(out global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out handle); nint __handle_native = default; // Setup - Perform required setup. @@ -5707,6 +6738,10 @@ public static partial void AllocateHandle(out global::LibraryImportGenerator.Int __PInvoke(&__handle_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. __handle_native__marshaller.FromUnmanaged(__handle_native); // Unmarshal - Convert native data to managed data. @@ -5714,8 +6749,16 @@ public static partial void AllocateHandle(out global::LibraryImportGenerator.Int } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __handle_native__marshaller.Free(); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __handle_native__marshaller.Free(); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -5775,7 +6818,11 @@ public static partial bool IsHandleAlive(global::LibraryImportGenerator.Integrat } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __handle_native__marshaller.Free(); } @@ -5824,7 +6871,11 @@ public static partial void ModifyHandle(ref global::LibraryImportGenerator.Integ handle = __handle_native__marshaller.ToManagedFinally(); } +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __handle_native__marshaller.Free(); } @@ -5902,6 +6953,10 @@ public unsafe partial class SetLastError public static partial string SetError_NonBlittableSignature(int error, bool shouldSetError, string errorString) { int __lastError; +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte __shouldSetError_native = default; string __retVal = default; ushort* __retVal_native = default; @@ -5917,13 +6972,25 @@ public static partial string SetError_NonBlittableSignature(int error, bool shou __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); @@ -6016,7 +7083,11 @@ public static partial int SumInArray(in global::System.Span values, int num } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__marshaller.Free(); } @@ -6058,7 +7129,11 @@ public static partial void Duplicate(ref global::System.Span values, int nu } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __values_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__values_native); } @@ -6080,6 +7155,10 @@ public unsafe partial class Span [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Span CreateRange(int start, int end, out int numValues) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); global::System.Span __retVal = default; int* __retVal_native = default; @@ -6094,6 +7173,10 @@ public unsafe partial class Span __retVal_native = __PInvoke(start, end, __numValues_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = numValues; __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -6101,9 +7184,17 @@ public unsafe partial class Span } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -6124,6 +7215,10 @@ public unsafe partial class Span [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Span res) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); res = default; int* __res_native = default; @@ -6138,6 +7233,10 @@ public static partial void CreateRange_Out(int start, int end, out int numValues __PInvoke(start, end, __numValues_native, &__res_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __res_native__numElements = numValues; res = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); @@ -6145,9 +7244,17 @@ public static partial void CreateRange_Out(int start, int end, out int numValues } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __res_native__numElements = numValues; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__res_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__res_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -6167,6 +7274,10 @@ public unsafe partial class Span [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial global::System.Span GetLongBytes(long l) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::System.Span __retVal = default; byte* __retVal_native = default; // Setup - Perform required setup. @@ -6178,6 +7289,10 @@ public unsafe partial class Span __retVal_native = __PInvoke(l); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal_native__numElements = 8; __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); @@ -6185,9 +7300,17 @@ public unsafe partial class Span } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. __retVal_native__numElements = 8; global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -6208,6 +7331,10 @@ public unsafe partial class Span [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial bool AndAllMembers(global::System.Span pArray, int length) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; bool __retVal = default; byte __retVal_native = default; @@ -6237,12 +7364,26 @@ public static partial bool AndAllMembers(global::System.Span>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = __retVal_native != 0; } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) _ = __pArray_native__lastIndexMarshalled; __pArray_native__marshaller.Free(); } @@ -6290,6 +7431,10 @@ public unsafe partial class Utf16 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) string __retVal = default; ushort* __retVal_native = default; try @@ -6300,13 +7445,25 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke((ushort*)__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -6327,6 +7484,10 @@ public unsafe partial class Utf16 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); ushort* __ret_native = default; try @@ -6337,13 +7498,25 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke((ushort*)__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -6377,7 +7550,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6409,7 +7586,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6444,7 +7625,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6515,6 +7700,10 @@ public unsafe partial class LPTStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) string __retVal = default; ushort* __retVal_native = default; try @@ -6525,13 +7714,25 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke((ushort*)__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -6552,6 +7753,10 @@ public unsafe partial class LPTStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); ushort* __ret_native = default; try @@ -6562,13 +7767,25 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke((ushort*)__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -6602,7 +7819,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6634,7 +7855,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6669,7 +7894,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6740,6 +7969,10 @@ public unsafe partial class LPWStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) string __retVal = default; ushort* __retVal_native = default; try @@ -6750,13 +7983,25 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke((ushort*)__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -6777,6 +8022,10 @@ public unsafe partial class LPWStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); ushort* __ret_native = default; try @@ -6787,13 +8036,25 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke((ushort*)__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -6827,7 +8088,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6859,7 +8124,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6894,7 +8163,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -6931,7 +8204,11 @@ public static partial int ReturnLength(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -6969,7 +8246,11 @@ public static partial int ReturnLength_IgnoreStringMarshalling(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -6991,6 +8272,10 @@ public unsafe partial class LPUTF8Str [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __s_native = default; string __retVal = default; byte* __retVal_native = default; @@ -7006,13 +8291,27 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke(__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7034,6 +8333,10 @@ public unsafe partial class LPUTF8Str [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); byte* __s_native = default; byte* __ret_native = default; @@ -7049,13 +8352,27 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke(__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7091,7 +8408,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7126,7 +8447,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); } @@ -7161,7 +8486,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); } @@ -7198,7 +8527,11 @@ public static partial int ReturnLength(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7220,6 +8553,10 @@ public unsafe partial class Utf8 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __s_native = default; string __retVal = default; byte* __retVal_native = default; @@ -7235,13 +8572,27 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke(__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7263,6 +8614,10 @@ public unsafe partial class Utf8 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); byte* __s_native = default; byte* __ret_native = default; @@ -7278,13 +8633,27 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke(__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7319,7 +8688,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); } @@ -7355,7 +8728,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7390,7 +8767,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); } @@ -7427,7 +8808,11 @@ public static partial int ReturnLength(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7465,7 +8850,11 @@ public static partial int ReturnLength_IgnoreStringMarshalling(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7487,6 +8876,10 @@ public unsafe partial class LPStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __s_native = default; string __retVal = default; byte* __retVal_native = default; @@ -7502,13 +8895,27 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke(__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7530,6 +8937,10 @@ public unsafe partial class LPStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); byte* __s_native = default; byte* __ret_native = default; @@ -7545,13 +8956,27 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke(__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7586,7 +9011,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); } @@ -7622,7 +9051,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7657,7 +9090,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); } @@ -7694,7 +9131,11 @@ public static partial int ReturnLength(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7732,7 +9173,11 @@ public static partial int ReturnLength_IgnoreStringMarshalling(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7754,6 +9199,10 @@ public unsafe partial class BStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) ushort* __s_native = default; string __retVal = default; ushort* __retVal_native = default; @@ -7769,13 +9218,27 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke(__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7797,6 +9260,10 @@ public unsafe partial class BStr [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); ushort* __s_native = default; ushort* __ret_native = default; @@ -7812,13 +9279,27 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke(__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7853,7 +9334,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); } @@ -7889,7 +9374,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -7924,7 +9413,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); } @@ -7975,6 +9468,10 @@ public unsafe partial class Utf16 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) string __retVal = default; ushort* __retVal_native = default; try @@ -7985,13 +9482,25 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke((ushort*)__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } +>>>>>>> 4637ad2 (Latest chanages) } return __retVal; @@ -8015,6 +9524,10 @@ public unsafe partial class Utf16 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); ushort* __ret_native = default; try @@ -8025,13 +9538,25 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke((ushort*)__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } +>>>>>>> 4637ad2 (Latest chanages) } // Local P/Invoke @@ -8068,7 +9593,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -8103,7 +9632,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -8141,7 +9674,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); } @@ -8181,7 +9718,11 @@ public static partial int ReturnLength(string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -8206,6 +9747,10 @@ public unsafe partial class Utf8 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial string Reverse_Return(string s) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) byte* __s_native = default; string __retVal = default; byte* __retVal_native = default; @@ -8221,13 +9766,27 @@ public static partial string Reverse_Return(string s) __retVal_native = __PInvoke(__s_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -8252,6 +9811,10 @@ public unsafe partial class Utf8 [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] public static partial void Reverse_Out(string s, out string ret) { +<<<<<<< HEAD +======= + bool __invokeSucceeded = default; +>>>>>>> 4637ad2 (Latest chanages) System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); byte* __s_native = default; byte* __ret_native = default; @@ -8267,13 +9830,27 @@ public static partial void Reverse_Out(string s, out string ret) __PInvoke(__s_native, &__ret_native); } +<<<<<<< HEAD +======= + __invokeSucceeded = true; +>>>>>>> 4637ad2 (Latest chanages) // Unmarshal - Convert native data to managed data. ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); +======= + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -8311,7 +9888,11 @@ public static partial void Reverse_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); } @@ -8350,7 +9931,11 @@ public static partial void Reverse_In(in string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) __s_native__marshaller.Free(); } @@ -8388,7 +9973,11 @@ public static partial void Reverse_Replace_Ref(ref string s) } finally { +<<<<<<< HEAD // Cleanup - Perform required cleanup. +======= + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. +>>>>>>> 4637ad2 (Latest chanages) global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); } diff --git a/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs new file mode 100644 index 0000000..d987767 --- /dev/null +++ b/LibraryImportGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs @@ -0,0 +1,8823 @@ +// +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(int[] values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((int*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(ref int values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __values_native = &values) + { + __retVal = __PInvoke(__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in int[] values, int numValues) + { + int* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref int[] values, int numValues) + { + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int[] CreateRange(int start, int end, out int numValues) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + int[] __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out int[] res) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + int* __res_native = default; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumChars(char[] chars, int numElements) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __chars_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(chars)) + { + __retVal = __PInvoke((char*)__chars_native, numElements); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_char_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(char* __chars_native, int __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void FillChars(char[] chars, int length, ushort start) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __chars_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(chars)) + { + __PInvoke((char*)__chars_native, length, start); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_char_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(char* __chars_native, int __length_native, ushort __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseChars(ref char[] chars, int numElements) + { + char* __chars_native = default; + // Setup - Perform required setup. + int __chars_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __chars_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __chars_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(chars, out __chars_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(chars).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__chars_native, __chars_native__numElements)); + { + __PInvoke(&__chars_native, numElements); + } + + // Unmarshal - Convert native data to managed data. + __chars_native__numElements = numElements; + chars = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__chars_native, __chars_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__chars_native, __chars_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(chars)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __chars_native__numElements = numElements; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__chars_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_char_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(char** __chars_native, int __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumStringLengths(string[] strArray) + { + bool __invokeSucceeded = default; + System.IntPtr* __strArray_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); + int __strArray_native__numElements; + int __strArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); + System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __strArray_native__unused = __strArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __strArray_native = __strArray_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__strArray_native); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __strArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_string_lengths", ExactSpelling = true)] + static extern unsafe int __PInvoke(System.IntPtr* __strArray_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseStrings_Ref(ref string[] strArray, out int numElements) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); + System.IntPtr* __strArray_native = default; + // Setup - Perform required setup. + int __strArray_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + int __strArray_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __strArray_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(strArray, out __strArray_native__numElements); + { + System.ReadOnlySpan __strArray_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(strArray); + System.Span __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__strArray_native, __strArray_native__numElements); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numElements_native = &numElements) + { + __PInvoke(&__strArray_native, __numElements_native); + } + + // Unmarshal - Convert native data to managed data. + __strArray_native__numElements = numElements; + strArray = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__strArray_native, __strArray_native__numElements); + { + System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__strArray_native, __strArray_native__numElements); + System.Span __strArray_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(strArray); + for (int __i0 = 0; __i0 < __strArray_native__numElements; ++__i0) + { + __strArray_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__strArray_native, __strArray_native__numElements); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__numElements = numElements; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__strArray_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_replace", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr** __strArray_native, int* __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string[] ReverseStrings_Return(string[] strArray, out int numElements) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); + System.IntPtr* __strArray_native = default; + string[] __retVal = default; + System.IntPtr* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); + int __strArray_native__numElements; + int __strArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); + System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numElements_native = &numElements) + fixed (void* __strArray_native__unused = __strArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __strArray_native = __strArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__strArray_native, __numElements_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numElements; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__retVal_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __strArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_return", ExactSpelling = true)] + static extern unsafe System.IntPtr* __PInvoke(System.IntPtr* __strArray_native, int* __numElements_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseStrings_Out(string[] strArray, out int numElements, out string[] res) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + System.IntPtr* __strArray_native = default; + System.IntPtr* __res_native = default; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); + int __strArray_native__numElements; + int __strArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); + System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) + { + __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numElements_native = &numElements) + fixed (void* __strArray_native__unused = __strArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __strArray_native = __strArray_native__marshaller.ToUnmanaged(); + __PInvoke(__strArray_native, __numElements_native, &__res_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numElements; + res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + { + System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements); + System.Span __res_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res); + for (int __i0 = 0; __i0 < __res_native__numElements; ++__i0) + { + __res_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__res_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements); + for (int __i0 = 0; __i0 < __res_native__nativeSpan.Length; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__res_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); + _ = __strArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); + } + } + + __strArray_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __strArray_native, int* __numElements_native, System.IntPtr** __res_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial byte[] GetLongBytes(long l) + { + bool __invokeSucceeded = default; + byte[] __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Append(ref int[] values, int numOriginalValues, int newValue) + { + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numOriginalValues, newValue); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = checked(1 + numOriginalValues); + values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = checked(1 + numOriginalValues); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "append_int_to_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(int** __values_native, int __numOriginalValues_native, int __newValue_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) + { + global::SharedTypes.IntStructWrapperNative* __array_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc global::SharedTypes.IntStructWrapperNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__array_native, length, start); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + __array_native__managedSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToManaged(__array_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __array_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.IntStructWrapperNative* __array_native, int __length_native, int __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleValues(global::SharedTypes.IntStructWrapper[] array, int length) + { + bool __invokeSucceeded = default; + global::SharedTypes.IntStructWrapperNative* __array_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + int __array_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc global::SharedTypes.IntStructWrapperNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) + { + __array_native__nativeSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToUnmanaged(__array_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __PInvoke(__array_native, length); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + __array_native__managedSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToManaged(__array_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __array_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __array_native__lastIndexMarshalled; + __array_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_values", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntStructWrapperNative* __array_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::SharedTypes.BoolStruct[] pArray, int length) + { + bool __invokeSucceeded = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pArray_native, length); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembersIn(in global::SharedTypes.BoolStruct[] pArray, int length) + { + bool __invokeSucceeded = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(&__pArray_native, length); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative** __pArray_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(ref global::SharedTypes.BoolStruct[] boolStruct, int numValues) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative** __boolStruct_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native, global::SharedTypes.BoolStructMarshaller.BoolStructNative** __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.BoolStruct[] NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues) + { + bool __invokeSucceeded = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + global::SharedTypes.BoolStruct[] __retVal = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__boolStruct_native, numValues); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] + static extern unsafe global::SharedTypes.BoolStructMarshaller.BoolStructNative* __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int numColumns) + { + bool __invokeSucceeded = default; + System.IntPtr* __matrix_native = default; + int[][] __retVal = default; + System.IntPtr* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __matrix_native__marshaller = new(); + int __matrix_native__numElements; + int __matrix_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __matrix_native__marshaller.FromManaged(matrix, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __matrix_native__managedSpan = __matrix_native__marshaller.GetManagedValuesSource(); + System.Span __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __matrix_native__managedSpan.Length; ++__i0, ++__matrix_native__lastIndexMarshalled) + { + int __matrix_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); + __matrix_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__matrix_native__managedSpan[__i0], out __matrix_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__matrix_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__matrix_native__nativeSpan[__i0], __matrix_native__nativeSpan____i0__numElements)); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __numRows_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(numRows)) + fixed (void* __matrix_native__unused = __matrix_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __matrix_native = __matrix_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__matrix_native, (int*)__numRows_native, numColumns); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numColumns; + __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + __retVal_native__nativeSpan____i0__numElements = numRows[__i0]; + __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) + { + int __retVal_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); + _ = __matrix_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __matrix_native__lastIndexMarshalled; ++__i0) + { + int __matrix_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); + __matrix_native__nativeSpan____i0__numElements = 0; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__matrix_native__nativeSpan[__i0]); + } + } + + __matrix_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "transpose_matrix", ExactSpelling = true)] + static extern unsafe System.IntPtr* __PInvoke(System.IntPtr* __matrix_native, int* __numRows_native, int __numColumns_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int Sum(int*[] values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((nint*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(nint* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int SumInArray(in int*[] values, int numValues) + { + nint* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(nint** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial void Duplicate(ref int*[] values, int numValues) + { + nint* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_ptr_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Arrays + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int*[] ReturnDuplicate(int*[] values, int numValues) + { + bool __invokeSucceeded = default; + int*[] __retVal = default; + nint* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal_native = __PInvoke((nint*)__values_native, numValues); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_duplicate_int_ptr_array", ExactSpelling = true)] + static extern unsafe nint* __PInvoke(nint* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_return_instance", ExactSpelling = true)] + public static extern partial global::SharedTypes.IntFields DoubleIntFields(global::SharedTypes.IntFields result); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsByRef(ref global::SharedTypes.IntFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsByRefIn(in global::SharedTypes.IntFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsRefReturn(global::SharedTypes.IntFields input, ref global::SharedTypes.IntFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(input, __result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_refreturn", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields __input_native, global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DoubleIntFieldsOutReturn(global::SharedTypes.IntFields input, out global::SharedTypes.IntFields result) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out result); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.IntFields* __result_native = &result) + { + __PInvoke(input, __result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_refreturn", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.IntFields __input_native, global::SharedTypes.IntFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void IncrementInvertPointerFieldsByRef(ref global::SharedTypes.PointerFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.PointerFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.PointerFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void IncrementInvertPointerFieldsByRefIn(in global::SharedTypes.PointerFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.PointerFields* __result_native = &result) + { + __PInvoke(__result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_byref", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.PointerFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void IncrementInvertPointerFieldsRefReturn(global::SharedTypes.PointerFields input, ref global::SharedTypes.PointerFields result) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::SharedTypes.PointerFields* __result_native = &result) + { + __PInvoke(input, __result_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_refreturn", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.PointerFields __input_native, global::SharedTypes.PointerFields* __result_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnByteBoolAsUInt(bool input) + { + byte __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (byte)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "bytebool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(byte __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnSByteBoolAsUInt(bool input) + { + sbyte __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (sbyte)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "bytebool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(sbyte __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnVariantBoolAsUInt(bool input) + { + short __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (short)(input ? -1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "variantbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(short __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnIntBoolAsUInt(bool input) + { + int __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (int)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(int __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnUIntBoolAsUInt(bool input) + { + uint __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (uint)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial uint ReturnWinBoolAsUInt(bool input) + { + int __input_native; + uint __retVal; + // Marshal - Convert managed data to native data. + __input_native = (int)(input ? 1 : 0); + { + __retVal = __PInvoke(__input_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe uint __PInvoke(int __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool ReturnUIntAsByteBool(uint input) + { + bool __retVal; + byte __retVal_native; + { + __retVal_native = __PInvoke(input); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe byte __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool ReturnUIntAsVariantBool(uint input) + { + bool __retVal; + short __retVal_native; + { + __retVal_native = __PInvoke(input); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native == -1; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe short __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool ReturnUIntAsWinBool(uint input) + { + bool __retVal; + int __retVal_native; + { + __retVal_native = __PInvoke(input); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] + static extern unsafe int __PInvoke(uint __input_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsByteBool_Ref(uint input, ref bool res) + { + byte __res_native; + // Marshal - Convert managed data to native data. + __res_native = (byte)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsByteBool_Out(uint input, out bool res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + byte __res_native; + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsByteBool_In(uint input, in bool res) + { + byte __res_native; + // Marshal - Convert managed data to native data. + __res_native = (byte)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsVariantBool_Ref(uint input, ref bool res) + { + short __res_native; + // Marshal - Convert managed data to native data. + __res_native = (short)(res ? -1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native == -1; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, short* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsVariantBool_Out(uint input, out bool res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + short __res_native; + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native == -1; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, short* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsVariantBool_In(uint input, in bool res) + { + short __res_native; + // Marshal - Convert managed data to native data. + __res_native = (short)(res ? -1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, short* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsWinBool_Ref(uint input, ref bool res) + { + int __res_native; + // Marshal - Convert managed data to native data. + __res_native = (int)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, int* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsWinBool_Out(uint input, out bool res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + int __res_native; + { + __PInvoke(input, &__res_native); + } + + // Unmarshal - Convert native data to managed data. + res = __res_native != 0; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, int* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsWinBool_In(uint input, in bool res) + { + int __res_native; + // Marshal - Convert managed data to native data. + __res_native = (int)(res ? 1 : 0); + { + __PInvoke(input, &__res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, int* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class CallingConventions + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "add_integers_cdecl", ExactSpelling = true)] + public static extern partial long AddLongsCdecl(long i, long j, long k, long l, long m, long n, long o, long p, long q); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + internal unsafe partial class NativeExportsNE + { + internal unsafe partial class CallingConventions + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "add_integers_stdcall", ExactSpelling = true)] + public static extern partial long AddLongsStdcall(long i, long j, long k, long l, long m, long n, long o, long p, long q); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "ushort_return_as_uint", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] + public static extern partial uint ReturnUnicodeAsUInt(char input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] + public static extern partial char ReturnUIntAsUnicode(uint input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsUnicode_Ref(uint input, ref char res) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __res_native = &res) + { + __PInvoke(input, __res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, char* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsUnicode_Out(uint input, out char res) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __res_native = &res) + { + __PInvoke(input, __res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, char* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReturnUIntAsUnicode_In(uint input, in char res) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __res_native = &res) + { + __PInvoke(input, __res_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(uint __input_native, char* __res_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true)] + public static extern partial char ReturnU2AsU2IgnoreCharSet(char input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true)] + public static extern partial char ReturnI2AsI2IgnoreCharSet(char input); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseBuffer(ref char buffer, int len) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (char* __buffer_native = &buffer) + { + __PInvoke(__buffer_native, len); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_reverse_buffer_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(char* __buffer_native, int __len_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Utf8StringSpan(global::System.ReadOnlySpan s) + { + bool __invokeSucceeded = default; + System.IntPtr* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + int __s_native__numElements; + int __s_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __s_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __s_native__managedSpan = __s_native__marshaller.GetManagedValuesSource(); + System.Span __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__managedSpan.Length; ++__i0, ++__s_native__lastIndexMarshalled) + { + __s_native__nativeSpan[__i0] = (System.IntPtr)(byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__s_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native__unused = __s_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __s_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free((byte*)__s_native__nativeSpan[__i0]); + } + } + + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "Utf8StringSpan", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Utf8StringArray(string[] s) + { + bool __invokeSucceeded = default; + System.IntPtr* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + int __s_native__numElements; + int __s_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __s_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __s_native__managedSpan = __s_native__marshaller.GetManagedValuesSource(); + System.Span __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__managedSpan.Length; ++__i0, ++__s_native__lastIndexMarshalled) + { + __s_native__nativeSpan[__i0] = (System.IntPtr)(byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__s_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native__unused = __s_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __s_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) + { + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free((byte*)__s_native__nativeSpan[__i0]); + } + } + + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "Utf8StringArray", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalSingleDimensionalArray(global::SharedTypes.BoolStruct[] c) + { + bool __invokeSucceeded = default; + nint* __c_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); + int __c_native__numElements; + int __c_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __c_native__marshaller.FromManaged(c, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); + System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__c_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __c_native__unused = __c_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __c_native = __c_native__marshaller.ToUnmanaged(); + __PInvoke(__c_native); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __c_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); + } + } + + __c_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalSingleDimensionalArray", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked(global::SharedTypes.BoolStruct[][] c) + { + bool __invokeSucceeded = default; + nint* __c_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); + int __c_native__numElements; + int __c_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __c_native__marshaller.FromManaged(c, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); + System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToUnmanaged(__c_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __c_native__unused = __c_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __c_native = __c_native__marshaller.ToUnmanaged(); + __PInvoke(__c_native); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __c_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__c_native__nativeSpan[__i0]); + } + } + + __c_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreCleared(global::SharedTypes.BoolStruct[][] c) + { + bool __invokeSucceeded = default; + System.IntPtr* __c_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); + int __c_native__numElements; + int __c_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __c_native__marshaller.FromManaged(c, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); + System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + int __c_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__nativeSpan____i0__numElements); + __c_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__c_native__managedSpan[__i0], out __c_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __c_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__c_native__managedSpan[__i0]); + System.Span __c_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__c_native__nativeSpan[__i0], __c_native__nativeSpan____i0__numElements); + __c_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __c_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __c_native__nativeSpan____i0__nativeSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToUnmanaged(__c_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __c_native__unused = __c_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __c_native = __c_native__marshaller.ToUnmanaged(); + __PInvoke(__c_native); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __c_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + int __c_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__nativeSpan____i0__numElements); + __c_native__nativeSpan____i0__numElements = 0; + { + System.ReadOnlySpan __c_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__c_native__nativeSpan[__i0], __c_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __c_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__c_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + __c_native__nativeSpan____i0__numElements = 0; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__c_native__nativeSpan[__i0]); + } + } + + __c_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalMultidimensionalArray_CheckInnerArraysAreCleared", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void MarshalArray_Ref(ref global::SharedTypes.BoolStruct[] c) + { + nint* __c_native = default; + // Setup - Perform required setup. + int __c_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); + int __c_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __c_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(c, out __c_native__numElements); + { + System.ReadOnlySpan __c_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(c); + System.Span __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__c_native, __c_native__numElements); + for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) + { + __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__c_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__c_native); + } + + // Unmarshal - Convert native data to managed data. + __c_native__numElements = 10; + c = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__c_native, __c_native__numElements); + { + System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__c_native, __c_native__numElements); + System.Span __c_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(c); + for (int __i0 = 0; __i0 < __c_native__numElements; ++__i0) + { + __c_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToManaged(__c_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__c_native, __c_native__numElements); + for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); + } + } + + __c_native__numElements = 10; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__c_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalArray_Ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; + nint* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native, nint** __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths, out global::SharedTypes.BoolStruct[][] pBoolStructOut) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + System.IntPtr* __boolStruct_native = default; + System.IntPtr* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__boolStruct_native__managedSpan[__i0], out __boolStruct_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__boolStruct_native__managedSpan[__i0]); + System.Span __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __boolStruct_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, length, (int*)__widths_native, &__pBoolStructOut_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = length; + pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + int __pBoolStructOut_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); + __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; + __pBoolStructOut_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + System.Span __pBoolStructOut_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__pBoolStructOut_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__numElements; ++__i1) + { + __pBoolStructOut_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.ConvertToManaged(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) + { + int __pBoolStructOut_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); + __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__numElements = 0; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out_2d", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr* __boolStruct_native, int __length_native, int* __widths_native, System.IntPtr** __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) + { + bool __invokeSucceeded = default; + nint* __array_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__array_native, length, start); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + __array_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.ConvertToManaged(__array_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan[__i0]); + } + } + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __array_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(nint* __array_native, int __length_native, int __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper[][] array, int length, int[] widths, int start) + { + bool __invokeSucceeded = default; + System.IntPtr* __array_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); + int __array_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); + __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + fixed (void* __array_native__unused = __array_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __array_native = __array_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__array_native, length, (int*)__widths_native, start); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + { + __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; + System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); + System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) + { + __array_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + { + System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) + { + int __array_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); + __array_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); + } + } + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __array_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array_2d", ExactSpelling = true)] + static extern unsafe byte __PInvoke(System.IntPtr* __array_native, int __length_native, int* __widths_native, int __start_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsRef(ref global::SharedTypes.BoolStruct[] boolStruct, int numValues) + { + nint* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __boolStruct_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsRef2D_LastElementMarshalling(ref global::SharedTypes.BoolStruct[][] boolStruct, int length) + { + nint* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, length); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = length; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "negate_bool_struct_array_ref_2d", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint** __boolStruct_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class MarshallingFails + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBoolsRef2D_ClearMarshalling(ref global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths) + { + System.IntPtr* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__boolStruct_native__managedSpan[__i0], out __boolStruct_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__boolStruct_native__managedSpan[__i0]); + System.Span __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__nativeSpan.Clear(); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__managedSpan.Length; ++__i1) + { + __boolStruct_native__nativeSpan____i0__nativeSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToUnmanaged(__boolStruct_native__nativeSpan____i0__managedSpan[__i1]); + } + } + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) + { + __PInvoke(&__boolStruct_native, length, (int*)__widths_native); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = length; + boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; + __boolStruct_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + System.Span __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__boolStruct_native__managedSpan[__i0]); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__numElements; ++__i1) + { + __boolStruct_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToManaged(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) + { + int __boolStruct_native__nativeSpan____i0__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); + __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; + { + System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); + for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__nativeSpan.Length; ++__i1) + { + global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); + } + } + + __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__boolStruct_native__nativeSpan[__i0]); + } + } + + __boolStruct_native__numElements = length; + global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "negate_bool_struct_array_ref_2d", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr** __boolStruct_native, int __length_native, int* __widths_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumWithBuffer(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + System.Span __values_native__buffer = stackalloc byte[global::SharedTypes.ListMarshallerWithBuffer.BufferSize]; + __values_native = global::SharedTypes.ListMarshallerWithBuffer.AllocateContainerForUnmanagedElements(values, __values_native__buffer, out __values_native__numElements); + global::SharedTypes.ListMarshallerWithBuffer.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshallerWithBuffer.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = 0; + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + int __values_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + { + System.ReadOnlySpan __values_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(values); + System.Span __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = (System.IntPtr)(int*)global::SharedTypes.IntWrapperMarshallerWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + { + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); + } + } + + __values_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int DoubleValues(global::System.Collections.Generic.List values, int length) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::SharedTypes.ListMarshallerWithPinning.GetPinnableReference(values)) + { + __retVal = __PInvoke((byte*)__values_native, length); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_values", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = numValues; + global::SharedTypes.ListMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + byte* __res_native = default; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(res)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__res_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List GetLongBytes(long l) + { + bool __invokeSucceeded = default; + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) + { + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + int __pArray_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + int __pArray_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __pArray_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(pArray, out __pArray_native__numElements); + { + System.ReadOnlySpan __pArray_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(pArray); + System.Span __pArray_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__pArray_native, __pArray_native__numElements); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + { + __retVal_native = __PInvoke(__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__pArray_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte* __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) + { + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + int __pArray_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + int __pArray_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __pArray_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(pArray, out __pArray_native__numElements); + { + System.ReadOnlySpan __pArray_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(pArray); + System.Span __pArray_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__pArray_native, __pArray_native__numElements); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + { + __retVal_native = __PInvoke(&__pArray_native, length); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__pArray_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte** __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) + { + byte* __boolStruct_native = default; + // Setup - Perform required setup. + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(&__boolStruct_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + boolStruct = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(boolStruct); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = numValues; + global::SharedTypes.ListMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + byte* __boolStruct_native = default; + byte* __pBoolStructOut_native = default; + // Setup - Perform required setup. + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + pBoolStructOut = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(pBoolStructOut); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__pBoolStructOut_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__boolStruct_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __boolStruct_native, int __numValues_native, byte** __pBoolStructOut_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) + { + bool __invokeSucceeded = default; + byte* __boolStruct_native = default; + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + int __boolStruct_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + int __boolStruct_native__lastIndexMarshalled = 0; + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); + System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + __retVal_native = __PInvoke(__boolStruct_native, numValues); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + { + System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); + System.Span __retVal_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.ListMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__numElements = 0; + global::SharedTypes.ListMarshaller.Free(__boolStruct_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __ret_native__numElements = 1; + ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __ret_native__numElements = 1; + ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) + { + bool __invokeSucceeded = default; + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + int __values_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc System.IntPtr[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); + System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) + { + __values_native__nativeSpan[__i0] = (System.IntPtr)(int*)global::SharedTypes.IntWrapperMarshallerWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__values_native, numValues); + } + + __invokeSucceeded = true; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __values_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + { + System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) + { + global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); + } + } + + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref global::System.Collections.Generic.List values, int numValues) + { + byte* __values_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __PInvoke(&__values_native, numValues); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __values_native__marshaller.FromUnmanaged(__values_native); + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements).CopyTo(__values_native__marshaller.GetManagedValuesDestination(__values_native__numElements)); + values = __values_native__marshaller.ToManaged(); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __values_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + System.Runtime.CompilerServices.Unsafe.SkipInit(out res); + byte* __res_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __res_native__marshaller = new(); + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __res_native__marshaller.FromUnmanaged(__res_native); + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + __res_native__marshaller.GetUnmanagedValuesSource(__res_native__numElements).CopyTo(__res_native__marshaller.GetManagedValuesDestination(__res_native__numElements)); + res = __res_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __res_native__marshaller.Free(); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List GetLongBytes(long l) + { + bool __invokeSucceeded = default; + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) + { + bool __invokeSucceeded = default; + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pArray_native, length); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte* __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) + { + bool __invokeSucceeded = default; + byte* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(&__pArray_native, length); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] + static extern unsafe byte __PInvoke(byte** __pArray_native, int __length_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) + { + bool __invokeSucceeded = default; + byte* __boolStruct_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(&__boolStruct_native, numValues); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __boolStruct_native__marshaller.FromUnmanaged(__boolStruct_native); + // Unmarshal - Convert native data to managed data. + __boolStruct_native__numElements = numValues; + { + System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesSource(__boolStruct_native__numElements); + System.Span __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesDestination(__boolStruct_native__numElements); + for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) + { + __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); + } + } + + boolStruct = __boolStruct_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + byte* __boolStruct_native = default; + byte* __pBoolStructOut_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pBoolStructOut_native__marshaller = new(); + int __pBoolStructOut_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); + // Unmarshal - Convert native data to managed data. + __pBoolStructOut_native__numElements = numValues; + { + System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = __pBoolStructOut_native__marshaller.GetUnmanagedValuesSource(__pBoolStructOut_native__numElements); + System.Span __pBoolStructOut_native__managedSpan = __pBoolStructOut_native__marshaller.GetManagedValuesDestination(__pBoolStructOut_native__numElements); + for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) + { + __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); + } + } + + pBoolStructOut = __pBoolStructOut_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __pBoolStructOut_native__marshaller.Free(); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __boolStruct_native, int __numValues_native, byte** __pBoolStructOut_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) + { + bool __invokeSucceeded = default; + byte* __boolStruct_native = default; + global::System.Collections.Generic.List __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + int __boolStruct_native__numElements; + int __boolStruct_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); + { + System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); + System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) + { + __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__boolStruct_native, numValues); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + { + System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements); + System.Span __retVal_native__managedSpan = __retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements); + for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) + { + __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); + } + } + + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + _ = __boolStruct_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __boolStruct_native__lastIndexMarshalled; + __boolStruct_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __boolStruct_native, int __numValues_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateful.ListGuaranteedUnmarshal.Marshaller __ret_native__marshaller = new(); + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __ret_native__marshaller.FromUnmanaged(__ret_native); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + ret = __ret_native__marshaller.ToManagedFinally(); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __ret_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Collections + { + public unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateful.ListGuaranteedUnmarshal.Marshaller __ret_native__marshaller = new(); + int __ret_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __ret_native__marshaller.FromUnmanaged(__ret_native); + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + ret = __ret_native__marshaller.ToManagedFinally(); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __ret_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void DeepDuplicateStrings(global::SharedTypes.StringContainer strings, out global::SharedTypes.StringContainer pStringsOut) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out pStringsOut); + global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; + global::SharedTypes.StringContainerMarshaller.StringContainerNative __pStringsOut_native = default; + try + { + // Marshal - Convert managed data to native data. + __strings_native = global::SharedTypes.StringContainerMarshaller.In.ConvertToUnmanaged(strings); + { + __PInvoke(__strings_native, &__pStringsOut_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + pStringsOut = global::SharedTypes.StringContainerMarshaller.Out.ConvertToManaged(__pStringsOut_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.StringContainerMarshaller.Out.Free(__pStringsOut_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::SharedTypes.StringContainerMarshaller.In.Free(__strings_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_deepduplicate", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native, global::SharedTypes.StringContainerMarshaller.StringContainerNative* __pStringsOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseStrings(ref global::SharedTypes.StringContainer strings) + { + global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; + try + { + // Marshal - Convert managed data to native data. + __strings_native = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToUnmanaged(strings); + { + __PInvoke(&__strings_native); + } + + // Unmarshal - Convert native data to managed data. + strings = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToManaged(__strings_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::SharedTypes.StringContainerMarshaller.Ref.Free(__strings_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_reverse_strings", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative* __strings_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial double GetLongBytesAsDouble(double d) + { + long __d_native; + double __retVal; + // Marshal - Convert managed data to native data. + __d_native = global::SharedTypes.DoubleToLongMarshaller.ConvertToUnmanaged(d); + { + __retVal = __PInvoke(__d_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes_as_double", ExactSpelling = true)] + static extern unsafe double __PInvoke(long __d_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial double GetBytesAsDoubleBigEndian(double d) + { + byte* __d_native; + double __retVal; + // Marshal - Convert managed data to native data. + System.Span __d_native__buffer = stackalloc byte[global::SharedTypes.DoubleToBytesBigEndianMarshaller.BufferSize]; + __d_native = global::SharedTypes.DoubleToBytesBigEndianMarshaller.ConvertToUnmanaged(d, __d_native__buffer); + { + __retVal = __PInvoke(__d_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_bytes_as_double_big_endian", ExactSpelling = true)] + static extern unsafe double __PInvoke(byte* __d_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::SharedTypes.BoolStruct boolStruct, out global::SharedTypes.BoolStruct pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native; + global::SharedTypes.BoolStructMarshaller.BoolStructNative __pBoolStructOut_native; + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(boolStruct); + { + __PInvoke(__boolStruct_native, &__pBoolStructOut_native); + } + + // Unmarshal - Convert native data to managed data. + pBoolStructOut = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bools", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native, global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndBoolsRef(in global::SharedTypes.BoolStruct boolStruct) + { + global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native; + bool __retVal; + byte __retVal_native; + // Marshal - Convert managed data to native data. + __boolStruct_native = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(boolStruct); + { + __retVal_native = __PInvoke(&__boolStruct_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bools_ref", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) + { + bool __invokeSucceeded = default; + int* __pInt_native = default; + global::SharedTypes.IntWrapper __retVal = default; + int* __retVal_native = default; + try + { + // Marshal - Convert managed data to native data. + __pInt_native = (int*)global::SharedTypes.IntWrapperMarshaller.ConvertToUnmanaged(pInt); + { + __retVal_native = __PInvoke(__pInt_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::SharedTypes.IntWrapperMarshaller.Free(__pInt_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) + { + bool __invokeSucceeded = default; + global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; + int* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pInt_native = &global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.GetPinnableReference(pInt)) + { + __retVal_native = __PInvoke((int*)__pInt_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateless + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out int ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + int __ret_native = default; + int __retVal = default; + int __retVal_native = default; + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Stateless.IntGuaranteedUnmarshal.ConvertToManagedFinally(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithNotification SubtractInts(global::SharedTypes.IntWrapperWithNotification x, global::SharedTypes.IntWrapperWithNotification y) + { + int __x_native; + int __y_native; + global::SharedTypes.IntWrapperWithNotification __retVal; + int __retVal_native; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __retVal_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __y_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __x_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __y_native__marshaller.FromManaged(y); + __x_native__marshaller.FromManaged(x); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __y_native = __y_native__marshaller.ToUnmanaged(); + __x_native = __x_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__x_native, __y_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __y_native__marshaller.OnInvoked(); + __x_native__marshaller.OnInvoked(); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_int", ExactSpelling = true)] + static extern unsafe int __PInvoke(int __x_native, int __y_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void SubtractInts(global::SharedTypes.IntWrapperWithNotification x, global::SharedTypes.IntWrapperWithNotification y, out global::SharedTypes.IntWrapperWithNotification result) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out result); + int __x_native; + int __y_native; + int __result_native; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __result_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __y_native__marshaller = new(); + global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __x_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __y_native__marshaller.FromManaged(y); + __x_native__marshaller.FromManaged(x); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __y_native = __y_native__marshaller.ToUnmanaged(); + __x_native = __x_native__marshaller.ToUnmanaged(); + __PInvoke(__x_native, __y_native, &__result_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __y_native__marshaller.OnInvoked(); + __x_native__marshaller.OnInvoked(); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __result_native__marshaller.FromUnmanaged(__result_native); + // Unmarshal - Convert native data to managed data. + result = __result_native__marshaller.ToManaged(); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __x_native, int __y_native, int* __result_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void NegateBools(global::SharedTypes.BoolStruct boolStruct, out global::SharedTypes.BoolStruct pBoolStructOut) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); + global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native; + global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __pBoolStructOut_native; + // Setup - Perform required setup. + global::SharedTypes.BoolStructMarshallerStateful.Marshaller __pBoolStructOut_native__marshaller = new(); + global::SharedTypes.BoolStructMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __PInvoke(__boolStruct_native, &__pBoolStructOut_native); + } + + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); + // Unmarshal - Convert native data to managed data. + pBoolStructOut = __pBoolStructOut_native__marshaller.ToManaged(); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bools", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native, global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative* __pBoolStructOut_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndBoolsRef(in global::SharedTypes.BoolStruct boolStruct) + { + global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native; + bool __retVal; + byte __retVal_native; + // Setup - Perform required setup. + global::SharedTypes.BoolStructMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); + // Marshal - Convert managed data to native data. + __boolStruct_native__marshaller.FromManaged(boolStruct); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(&__boolStruct_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bools_ref", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative* __boolStruct_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) + { + bool __invokeSucceeded = default; + global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; + int* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pInt_native = &global::SharedTypes.IntWrapperWithoutGetPinnableReferenceStatefulMarshaller.StatelessGetPinnableReference.GetPinnableReference(pInt)) + { + __retVal_native = __PInvoke((int*)__pInt_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRefNoAlloc(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) + { + bool __invokeSucceeded = default; + int* __pInt_native = default; + global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceStatefulNoAllocMarshaller.StatefulGetPinnableReference __pInt_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __pInt_native__marshaller.FromManaged(pInt); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pInt_native__unused = __pInt_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pInt_native = __pInt_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pInt_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) + { + bool __invokeSucceeded = default; + int* __pInt_native = default; + global::SharedTypes.IntWrapper __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + global::SharedTypes.IntWrapperMarshallerStateful.Marshaller __retVal_native__marshaller = new(); + global::SharedTypes.IntWrapperMarshallerStateful.Marshaller __pInt_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __pInt_native__marshaller.FromManaged(pInt); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pInt_native = __pInt_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pInt_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __pInt_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int* __pInt_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + internal unsafe partial class Stateful + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int GuaranteedUnmarshal(out int ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + int __ret_native = default; + int __retVal = default; + int __retVal_native = default; + // Setup - Perform required setup. + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Stateful.IntGuaranteedUnmarshal.Marshaller __retVal_native__marshaller = new(); + try + { + { + __retVal_native = __PInvoke(&__ret_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + ret = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + __retVal = __retVal_native__marshaller.ToManagedFinally(); + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ReverseReplaceString(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnStringLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void InvokeAfterGC(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.VoidVoid cb) + { + System.IntPtr __cb_native; + // Marshal - Convert managed data to native data. + __cb_native = cb != null ? System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(cb) : default; + { + __PInvoke(__cb_native); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + global::System.GC.KeepAlive(cb); + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] + static extern unsafe void __PInvoke(System.IntPtr __cb_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int InvokeWithBlittableArgument(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.IntIntInt cb, int a, int b) + { + System.IntPtr __cb_native; + int __retVal; + // Marshal - Convert managed data to native data. + __cb_native = cb != null ? System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(cb) : default; + { + __retVal = __PInvoke(__cb_native, a, b); + } + + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + global::System.GC.KeepAlive(cb); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] + static extern unsafe int __PInvoke(System.IntPtr __cb_native, int __a_native, int __b_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_int", ExactSpelling = true)] + public static extern partial global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum Subtract_Return(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Out(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b, out global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum c) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out c); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __c_native = &c) + { + __PInvoke(a, b, __c_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __b_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Ref(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, ref global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class IntEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_In(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, in global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_byte", ExactSpelling = true)] + public static extern partial global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum Subtract_Return(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Out(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b, out global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum c) + { + System.Runtime.CompilerServices.Unsafe.SkipInit(out c); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __c_native = &c) + { + __PInvoke(a, b, __c_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __b_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __c_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_Ref(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, ref global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class ByteEnum + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Subtract_In(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, in global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b) + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native = &b) + { + __PInvoke(a, __b_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_managed_callback_after_gc", ExactSpelling = true)] + public static unsafe extern partial void InvokeAfterGC(delegate* cb); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] + public static unsafe extern partial void InvokeAfterGC(delegate* unmanaged cb); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] + public static unsafe extern partial void InvokeAfterGC(delegate* unmanaged[Stdcall] cb); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_managed_callback_blittable_args", ExactSpelling = true)] + public static unsafe extern partial int InvokeWithBlittableArgument(delegate* cb, int a, int b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] + public static unsafe extern partial int InvokeWithBlittableArgument(delegate* unmanaged cb, int a, int b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class FunctionPointer + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] + public static unsafe extern partial int InvokeWithBlittableArgument(delegate* unmanaged[Stdcall] cb, int a, int b); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] + public static unsafe extern partial void Subtract_Int_Ptr(int a, int* b); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] + public static unsafe extern partial void Subtract_Byte_Ptr(byte a, byte* b); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] + public static unsafe extern partial void DoubleIntFields_Ptr(global::SharedTypes.IntFields* result); + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class NativeExportsSafeHandle + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + private static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() + { + bool __invokeSucceeded = default; + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __retVal_native__marshaller = new(); + try + { + { + __retVal_native = __PInvoke(); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle", ExactSpelling = true)] + static extern unsafe nint __PInvoke(); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() + { + bool __invokeSucceeded = default; + global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; + nint __retVal_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __retVal_native__marshaller = new(); + try + { + { + __retVal_native = __PInvoke(); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __retVal_native__marshaller.FromUnmanaged(__retVal_native); + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __retVal_native__marshaller.Free(); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle", ExactSpelling = true)] + static extern unsafe nint __PInvoke(); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void AllocateHandle(out global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out handle); + nint __handle_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __handle_native__marshaller = new(); + try + { + { + __PInvoke(&__handle_native); + } + + __invokeSucceeded = true; + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __handle_native__marshaller.FromUnmanaged(__handle_native); + // Unmarshal - Convert native data to managed data. + handle = __handle_native__marshaller.ToManaged(); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + __handle_native__marshaller.Free(); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __handle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + private static partial bool ReleaseHandle(nint handle) + { + bool __retVal; + sbyte __retVal_native; + { + __retVal_native = __PInvoke(handle); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "release_handle", ExactSpelling = true)] + static extern unsafe sbyte __PInvoke(nint __handle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool IsHandleAlive(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) + { + nint __handle_native = default; + bool __retVal = default; + sbyte __retVal_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedIn __handle_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __handle_native__marshaller.FromManaged(handle); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __handle_native = __handle_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__handle_native); + } + + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __handle_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "is_handle_alive", ExactSpelling = true)] + static extern unsafe sbyte __PInvoke(nint __handle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void ModifyHandle(ref global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle, bool newHandle) + { + bool __invokeSucceeded = default; + nint __handle_native = default; + sbyte __newHandle_native = default; + // Setup - Perform required setup. + global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedRef __handle_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __newHandle_native = (sbyte)(newHandle ? 1 : 0); + __handle_native__marshaller.FromManaged(handle); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __handle_native = __handle_native__marshaller.ToUnmanaged(); + __PInvoke(&__handle_native, __newHandle_native); + } + + __invokeSucceeded = true; + // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. + __handle_native__marshaller.OnInvoked(); + // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. + __handle_native__marshaller.FromUnmanaged(__handle_native); + } + finally + { + if (__invokeSucceeded) + { + // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. + handle = __handle_native__marshaller.ToManagedFinally(); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __handle_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "modify_handle", ExactSpelling = true)] + static extern unsafe void __PInvoke(nint* __handle_native, sbyte __newHandle_native); + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class SetLastError + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SetError(int error, byte shouldSetError) + { + int __lastError; + int __retVal; + { + System.Runtime.InteropServices.Marshal.SetLastSystemError(0); + __retVal = __PInvoke(error, shouldSetError); + __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); + } + + System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error", ExactSpelling = true)] + static extern unsafe int __PInvoke(int __error_native, byte __shouldSetError_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class SetLastError + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SetError_CustomMarshallingSetsError(int error, byte shouldSetError) + { + int __lastError; + int __retVal; + int __retVal_native; + { + System.Runtime.InteropServices.Marshal.SetLastSystemError(0); + __retVal_native = __PInvoke(error, shouldSetError); + __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); + } + + // Unmarshal - Convert native data to managed data. + __retVal = global::LibraryImportGenerator.IntegrationTests.SetLastErrorMarshaller.ConvertToManaged(__retVal_native); + System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error", ExactSpelling = true)] + static extern unsafe int __PInvoke(int __error_native, byte __shouldSetError_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class SetLastError + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string SetError_NonBlittableSignature(int error, bool shouldSetError, string errorString) + { + int __lastError; + bool __invokeSucceeded = default; + byte __shouldSetError_native = default; + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Marshal - Convert managed data to native data. + __shouldSetError_native = (byte)(shouldSetError ? 1 : 0); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __errorString_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(errorString)) + { + System.Runtime.InteropServices.Marshal.SetLastSystemError(0); + __retVal_native = __PInvoke(error, __shouldSetError_native, (ushort*)__errorString_native); + __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + } + + System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error_return_string", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(int __error_native, byte __shouldSetError_native, ushort* __errorString_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.Span values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((int*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int Sum(global::System.ReadOnlySpan values, int numValues) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) + { + __retVal = __PInvoke((int*)__values_native, numValues); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] + static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int SumInArray(in global::System.Span values, int numValues) + { + int* __values_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.BufferSize]); + __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __values_native__unused = __values_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __values_native = __values_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(&__values_native, numValues); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] + static extern unsafe int __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Duplicate(ref global::System.Span values, int numValues) + { + int* __values_native = default; + // Setup - Perform required setup. + int __values_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __values_native = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); + { + __PInvoke(&__values_native, numValues); + } + + // Unmarshal - Convert native data to managed data. + __values_native__numElements = numValues; + values = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(values)); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __values_native__numElements = numValues; + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__values_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] + static extern unsafe void __PInvoke(int** __values_native, int __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Span CreateRange(int start, int end, out int numValues) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + global::System.Span __retVal = default; + int* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __retVal_native = __PInvoke(start, end, __numValues_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = numValues; + __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] + static extern unsafe int* __PInvoke(int __start_native, int __end_native, int* __numValues_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Span res) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); + res = default; + int* __res_native = default; + // Setup - Perform required setup. + int __res_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (int* __numValues_native = &numValues) + { + __PInvoke(start, end, __numValues_native, &__res_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __res_native__numElements = numValues; + res = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(res)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__res_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] + static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial global::System.Span GetLongBytes(long l) + { + bool __invokeSucceeded = default; + global::System.Span __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + int __retVal_native__numElements; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); + try + { + { + __retVal_native = __PInvoke(l); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal_native__numElements = 8; + __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(__retVal)); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(long __l_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Span + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial bool AndAllMembers(global::System.Span pArray, int length) + { + bool __invokeSucceeded = default; + global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; + bool __retVal = default; + byte __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); + int __pArray_native__numElements; + int __pArray_native__lastIndexMarshalled = 0; + System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); + try + { + // Marshal - Convert managed data to native data. + __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); + System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); + for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) + { + __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); + } + } + + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __pArray_native__unused = __pArray_native__marshaller) + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __pArray_native = __pArray_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__pArray_native, length); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = __retVal_native != 0; + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + _ = __pArray_native__lastIndexMarshalled; + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + _ = __pArray_native__lastIndexMarshalled; + __pArray_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] + static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native, int __length_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPTStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPWStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPUTF8Str + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class LPStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + ushort* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_bstr", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength_IgnoreStringMarshalling(string s) + { + ushort* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_bstr", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + ushort* __s_native = default; + string __retVal = default; + ushort* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_bstr", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __s_native = default; + ushort* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class BStr + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_bstr", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + int __retVal; + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal = __PInvoke((ushort*)__s_native); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] + static extern unsafe int __PInvoke(ushort* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + string __retVal = default; + ushort* __retVal_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __retVal_native = __PInvoke((ushort*)__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); + } + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] + static extern unsafe ushort* __PInvoke(ushort* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + ushort* __ret_native = default; + try + { + // Pin - Pin data in preparation for calling the P/Invoke. + fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) + { + __PInvoke((ushort*)__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); + } + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf16 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + ushort* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] + static extern unsafe void __PInvoke(ushort** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial int ReturnLength(string s) + { + byte* __s_native = default; + int __retVal = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal = __PInvoke(__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] + static extern unsafe int __PInvoke(byte* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial string Reverse_Return(string s) + { + bool __invokeSucceeded = default; + byte* __s_native = default; + string __retVal = default; + byte* __retVal_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __retVal_native = __PInvoke(__s_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + return __retVal; + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] + static extern unsafe byte* __PInvoke(byte* __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Out(string s, out string ret) + { + bool __invokeSucceeded = default; + System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); + byte* __s_native = default; + byte* __ret_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(__s_native, &__ret_native); + } + + __invokeSucceeded = true; + // Unmarshal - Convert native data to managed data. + ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); + } + finally + { + if (__invokeSucceeded) + { + // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); + } + + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_In(in string s) + { + byte* __s_native = default; + // Setup - Perform required setup. + scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); + try + { + // Marshal - Convert managed data to native data. + __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); + { + // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. + __s_native = __s_native__marshaller.ToUnmanaged(); + __PInvoke(&__s_native); + } + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + __s_native__marshaller.Free(); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } + } +} +namespace LibraryImportGenerator.IntegrationTests +{ + unsafe partial class NativeExportsNE + { + public unsafe partial class StringMarshallingCustomType + { + public unsafe partial class Utf8 + { + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] + [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] + public static partial void Reverse_Replace_Ref(ref string s) + { + byte* __s_native = default; + try + { + // Marshal - Convert managed data to native data. + __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); + { + __PInvoke(&__s_native); + } + + // Unmarshal - Convert native data to managed data. + s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); + } + finally + { + // CleanupCallerAllocated - Perform cleanup of caller allocated resources. + global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); + } + + // Local P/Invoke + [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] + static extern unsafe void __PInvoke(byte** __s_native); + } + } + } + } +} From f16a10bfad89f9a14a7af1cc97d686c05a9279b2 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Mon, 7 Aug 2023 22:33:37 -0700 Subject: [PATCH 2/2] Changes from CleanupContents --- .../LibraryImports.g.cs | 9991 ----------------- 1 file changed, 9991 deletions(-) delete mode 100644 LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs diff --git a/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs b/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs deleted file mode 100644 index c65872c..0000000 --- a/LibraryImortGenerator.Tests/Microsoft.Interop.LibraryImportGenerator/Microsoft.Interop.LibraryImportGenerator/LibraryImports.g.cs +++ /dev/null @@ -1,9991 +0,0 @@ -// -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int Sum(int[] values, int numValues) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) - { - __retVal = __PInvoke((int*)__values_native, numValues); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int Sum(ref int values, int numValues) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __values_native = &values) - { - __retVal = __PInvoke(__values_native, numValues); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumInArray(in int[] values, int numValues) - { - int* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native__unused = __values_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(&__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] - static extern unsafe int __PInvoke(int** __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Duplicate(ref int[] values, int numValues) - { - int* __values_native = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __PInvoke(&__values_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(int** __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int[] CreateRange(int start, int end, out int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - int[] __retVal = default; - int* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __retVal_native = __PInvoke(start, end, __numValues_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int __start_native, int __end_native, int* __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void CreateRange_Out(int start, int end, out int numValues, out int[] res) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - int* __res_native = default; - // Setup - Perform required setup. - int __res_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __PInvoke(start, end, __numValues_native, &__res_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __res_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumChars(char[] chars, int numElements) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __chars_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(chars)) - { - __retVal = __PInvoke((char*)__chars_native, numElements); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_char_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(char* __chars_native, int __numElements_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void FillChars(char[] chars, int length, ushort start) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __chars_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(chars)) - { - __PInvoke((char*)__chars_native, length, start); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_char_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(char* __chars_native, int __length_native, ushort __start_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReverseChars(ref char[] chars, int numElements) - { - char* __chars_native = default; - // Setup - Perform required setup. - int __chars_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __chars_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __chars_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(chars, out __chars_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(chars).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__chars_native, __chars_native__numElements)); - { - __PInvoke(&__chars_native, numElements); - } - - // Unmarshal - Convert native data to managed data. - __chars_native__numElements = numElements; - chars = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__chars_native, __chars_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__chars_native, __chars_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(chars)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __chars_native__numElements = numElements; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__chars_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_char_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(char** __chars_native, int __numElements_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumStringLengths(string[] strArray) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.IntPtr* __strArray_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); - int __strArray_native__numElements; - int __strArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); - System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) - { - __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __strArray_native__unused = __strArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __strArray_native = __strArray_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__strArray_native); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __strArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); - } - } - - __strArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_string_lengths", ExactSpelling = true)] - static extern unsafe int __PInvoke(System.IntPtr* __strArray_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReverseStrings_Ref(ref string[] strArray, out int numElements) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); - System.IntPtr* __strArray_native = default; - // Setup - Perform required setup. - int __strArray_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); - int __strArray_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __strArray_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(strArray, out __strArray_native__numElements); - { - System.ReadOnlySpan __strArray_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(strArray); - System.Span __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__strArray_native, __strArray_native__numElements); - for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) - { - __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numElements_native = &numElements) - { - __PInvoke(&__strArray_native, __numElements_native); - } - - // Unmarshal - Convert native data to managed data. - __strArray_native__numElements = numElements; - strArray = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__strArray_native, __strArray_native__numElements); - { - System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__strArray_native, __strArray_native__numElements); - System.Span __strArray_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(strArray); - for (int __i0 = 0; __i0 < __strArray_native__numElements; ++__i0) - { - __strArray_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__strArray_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__strArray_native, __strArray_native__numElements); -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - { - System.ReadOnlySpan __strArray_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__strArray_native, __strArray_native__numElements); ->>>>>>> 4637ad2 (Latest chanages) - for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); - } - } - - __strArray_native__numElements = numElements; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__strArray_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_replace", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr** __strArray_native, int* __numElements_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string[] ReverseStrings_Return(string[] strArray, out int numElements) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); - System.IntPtr* __strArray_native = default; - string[] __retVal = default; - System.IntPtr* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); - int __strArray_native__numElements; - int __strArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); - System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) - { - __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numElements_native = &numElements) - fixed (void* __strArray_native__unused = __strArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __strArray_native = __strArray_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__strArray_native, __numElements_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numElements; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) - { - __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__retVal_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__retVal_native__nativeSpan[__i0]); - } - } - - __retVal_native__numElements = numElements; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__retVal_native__nativeSpan[__i0]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); - _ = __strArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); - } - } - - __strArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_return", ExactSpelling = true)] - static extern unsafe System.IntPtr* __PInvoke(System.IntPtr* __strArray_native, int* __numElements_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReverseStrings_Out(string[] strArray, out int numElements, out string[] res) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numElements); - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - System.IntPtr* __strArray_native = default; - System.IntPtr* __res_native = default; - // Setup - Perform required setup. - int __res_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __strArray_native__marshaller = new(); - int __strArray_native__numElements; - int __strArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __strArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __strArray_native__marshaller.FromManaged(strArray, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __strArray_native__managedSpan = __strArray_native__marshaller.GetManagedValuesSource(); - System.Span __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __strArray_native__managedSpan.Length; ++__i0, ++__strArray_native__lastIndexMarshalled) - { - __strArray_native__nativeSpan[__i0] = (System.IntPtr)(ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(__strArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numElements_native = &numElements) - fixed (void* __strArray_native__unused = __strArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __strArray_native = __strArray_native__marshaller.ToUnmanaged(); - __PInvoke(__strArray_native, __numElements_native, &__res_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numElements; - res = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - { - System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements); - System.Span __res_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(res); - for (int __i0 = 0; __i0 < __res_native__numElements; ++__i0) - { - __res_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged((ushort*)__res_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements); - for (int __i0 = 0; __i0 < __res_native__nativeSpan.Length; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__res_native__nativeSpan[__i0]); - } - } - - __res_native__numElements = numElements; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __res_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__res_native, __res_native__numElements); - for (int __i0 = 0; __i0 < __res_native__nativeSpan.Length; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__res_native__nativeSpan[__i0]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__res_native); - _ = __strArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __strArray_native__nativeSpan = __strArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __strArray_native__lastIndexMarshalled; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free((ushort*)__strArray_native__nativeSpan[__i0]); - } - } - - __strArray_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_strings_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr* __strArray_native, int* __numElements_native, System.IntPtr** __res_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial byte[] GetLongBytes(long l) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte[] __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - { - __retVal_native = __PInvoke(l); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = 8; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = 8; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(long __l_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Append(ref int[] values, int numOriginalValues, int newValue) - { - int* __values_native = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __PInvoke(&__values_native, numOriginalValues, newValue); - } - - // Unmarshal - Convert native data to managed data. - __values_native__numElements = checked(1 + numOriginalValues); - values = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(values)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__numElements = checked(1 + numOriginalValues); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__values_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "append_int_to_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(int** __values_native, int __numOriginalValues_native, int __newValue_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) - { - global::SharedTypes.IntStructWrapperNative* __array_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); - int __array_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __array_native__marshaller.FromManaged(array, stackalloc global::SharedTypes.IntStructWrapperNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __array_native__unused = __array_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __array_native = __array_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__array_native, length, start); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - { - __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; - System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); - System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) - { - __array_native__managedSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToManaged(__array_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __array_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array", ExactSpelling = true)] - static extern unsafe byte __PInvoke(global::SharedTypes.IntStructWrapperNative* __array_native, int __length_native, int __start_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void DoubleValues(global::SharedTypes.IntStructWrapper[] array, int length) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.IntStructWrapperNative* __array_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); - int __array_native__numElements; - int __array_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __array_native__marshaller.FromManaged(array, stackalloc global::SharedTypes.IntStructWrapperNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __array_native__managedSpan = __array_native__marshaller.GetManagedValuesSource(); - System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__managedSpan.Length; ++__i0, ++__array_native__lastIndexMarshalled) - { - __array_native__nativeSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToUnmanaged(__array_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __array_native__unused = __array_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __array_native = __array_native__marshaller.ToUnmanaged(); - __PInvoke(__array_native, length); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - { - __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; - System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); - System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) - { - __array_native__managedSpan[__i0] = global::SharedTypes.IntStructWrapperMarshaller.ConvertToManaged(__array_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __array_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __array_native__lastIndexMarshalled; - __array_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_values", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.IntStructWrapperNative* __array_native, int __length_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembers(global::SharedTypes.BoolStruct[] pArray, int length) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); - int __pArray_native__numElements; - int __pArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); - System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pArray_native__unused = __pArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pArray_native = __pArray_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__pArray_native, length); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __pArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] - static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native, int __length_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembersIn(in global::SharedTypes.BoolStruct[] pArray, int length) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); - int __pArray_native__numElements; - int __pArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); - System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pArray_native__unused = __pArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pArray_native = __pArray_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(&__pArray_native, length); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __pArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] - static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative** __pArray_native, int __length_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(ref global::SharedTypes.BoolStruct[] boolStruct, int numValues) - { - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; - // Setup - Perform required setup. - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - __PInvoke(&__boolStruct_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __boolStruct_native__numElements = numValues; - boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); - System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); - for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) - { - __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative** __boolStruct_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native = default; - // Setup - Perform required setup. - int __pBoolStructOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __pBoolStructOut_native__numElements = numValues; - pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) - { - __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __pBoolStructOut_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native, global::SharedTypes.BoolStructMarshaller.BoolStructNative** __pBoolStructOut_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.BoolStruct[] NegateBools(global::SharedTypes.BoolStruct[] boolStruct, int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; - global::SharedTypes.BoolStruct[] __retVal = default; - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__boolStruct_native, numValues); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) - { - __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] - static extern unsafe global::SharedTypes.BoolStructMarshaller.BoolStructNative* __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int[][] TransposeMatrix(int[][] matrix, int[] numRows, int numColumns) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.IntPtr* __matrix_native = default; - int[][] __retVal = default; - System.IntPtr* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __matrix_native__marshaller = new(); - int __matrix_native__numElements; - int __matrix_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __matrix_native__marshaller.FromManaged(matrix, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __matrix_native__managedSpan = __matrix_native__marshaller.GetManagedValuesSource(); - System.Span __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __matrix_native__managedSpan.Length; ++__i0, ++__matrix_native__lastIndexMarshalled) - { - int __matrix_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); - __matrix_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__matrix_native__managedSpan[__i0], out __matrix_native__nativeSpan____i0__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__matrix_native__managedSpan[__i0]).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((int*)__matrix_native__nativeSpan[__i0], __matrix_native__nativeSpan____i0__numElements)); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __numRows_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(numRows)) - fixed (void* __matrix_native__unused = __matrix_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __matrix_native = __matrix_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__matrix_native, (int*)__numRows_native, numColumns); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numColumns; - __retVal = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) - { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = numRows[__i0]; - __retVal_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((int*)__retVal_native__nativeSpan[__i0], __retVal_native__nativeSpan____i0__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__retVal_native__managedSpan[__i0])); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) - { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - __retVal_native__nativeSpan____i0__numElements = numRows[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); - } - } - - __retVal_native__numElements = numColumns; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__retVal_native, __retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__nativeSpan.Length; ++__i0) - { - int __retVal_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__nativeSpan____i0__numElements); - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__retVal_native__nativeSpan[__i0]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__retVal_native); - _ = __matrix_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __matrix_native__nativeSpan = __matrix_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __matrix_native__lastIndexMarshalled; ++__i0) - { - int __matrix_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __matrix_native__nativeSpan____i0__numElements); -<<<<<<< HEAD - ; -======= - __matrix_native__nativeSpan____i0__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((int*)__matrix_native__nativeSpan[__i0]); - } - } - - __matrix_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "transpose_matrix", ExactSpelling = true)] - static extern unsafe System.IntPtr* __PInvoke(System.IntPtr* __matrix_native, int* __numRows_native, int __numColumns_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static unsafe partial int Sum(int*[] values, int numValues) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) - { - __retVal = __PInvoke((nint*)__values_native, numValues); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(nint* __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static unsafe partial int SumInArray(in int*[] values, int numValues) - { - nint* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native__unused = __values_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(&__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array_ref", ExactSpelling = true)] - static extern unsafe int __PInvoke(nint** __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static unsafe partial void Duplicate(ref int*[] values, int numValues) - { - nint* __values_native = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __PInvoke(&__values_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesDestination(values)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__values_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_ptr_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint** __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Arrays - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static unsafe partial int*[] ReturnDuplicate(int*[] values, int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - int*[] __retVal = default; - nint* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) - { - __retVal_native = __PInvoke((nint*)__values_native, numValues); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal = global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.PointerArrayMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_duplicate_int_ptr_array", ExactSpelling = true)] - static extern unsafe nint* __PInvoke(nint* __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_return_instance", ExactSpelling = true)] - public static extern partial global::SharedTypes.IntFields DoubleIntFields(global::SharedTypes.IntFields result); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void DoubleIntFieldsByRef(ref global::SharedTypes.IntFields result) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.IntFields* __result_native = &result) - { - __PInvoke(__result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.IntFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void DoubleIntFieldsByRefIn(in global::SharedTypes.IntFields result) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.IntFields* __result_native = &result) - { - __PInvoke(__result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.IntFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void DoubleIntFieldsRefReturn(global::SharedTypes.IntFields input, ref global::SharedTypes.IntFields result) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.IntFields* __result_native = &result) - { - __PInvoke(input, __result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_refreturn", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.IntFields __input_native, global::SharedTypes.IntFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void DoubleIntFieldsOutReturn(global::SharedTypes.IntFields input, out global::SharedTypes.IntFields result) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out result); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.IntFields* __result_native = &result) - { - __PInvoke(input, __result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_refreturn", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.IntFields __input_native, global::SharedTypes.IntFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void IncrementInvertPointerFieldsByRef(ref global::SharedTypes.PointerFields result) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.PointerFields* __result_native = &result) - { - __PInvoke(__result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_byref", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.PointerFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void IncrementInvertPointerFieldsByRefIn(in global::SharedTypes.PointerFields result) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.PointerFields* __result_native = &result) - { - __PInvoke(__result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_byref", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.PointerFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void IncrementInvertPointerFieldsRefReturn(global::SharedTypes.PointerFields input, ref global::SharedTypes.PointerFields result) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::SharedTypes.PointerFields* __result_native = &result) - { - __PInvoke(input, __result_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_increment_invert_ptrfields_refreturn", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.PointerFields __input_native, global::SharedTypes.PointerFields* __result_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial uint ReturnByteBoolAsUInt(bool input) - { - byte __input_native; - uint __retVal; - // Marshal - Convert managed data to native data. - __input_native = (byte)(input ? 1 : 0); - { - __retVal = __PInvoke(__input_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "bytebool_return_as_uint", ExactSpelling = true)] - static extern unsafe uint __PInvoke(byte __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial uint ReturnSByteBoolAsUInt(bool input) - { - sbyte __input_native; - uint __retVal; - // Marshal - Convert managed data to native data. - __input_native = (sbyte)(input ? 1 : 0); - { - __retVal = __PInvoke(__input_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "bytebool_return_as_uint", ExactSpelling = true)] - static extern unsafe uint __PInvoke(sbyte __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial uint ReturnVariantBoolAsUInt(bool input) - { - short __input_native; - uint __retVal; - // Marshal - Convert managed data to native data. - __input_native = (short)(input ? -1 : 0); - { - __retVal = __PInvoke(__input_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "variantbool_return_as_uint", ExactSpelling = true)] - static extern unsafe uint __PInvoke(short __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial uint ReturnIntBoolAsUInt(bool input) - { - int __input_native; - uint __retVal; - // Marshal - Convert managed data to native data. - __input_native = (int)(input ? 1 : 0); - { - __retVal = __PInvoke(__input_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] - static extern unsafe uint __PInvoke(int __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial uint ReturnUIntBoolAsUInt(bool input) - { - uint __input_native; - uint __retVal; - // Marshal - Convert managed data to native data. - __input_native = (uint)(input ? 1 : 0); - { - __retVal = __PInvoke(__input_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] - static extern unsafe uint __PInvoke(uint __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial uint ReturnWinBoolAsUInt(bool input) - { - int __input_native; - uint __retVal; - // Marshal - Convert managed data to native data. - __input_native = (int)(input ? 1 : 0); - { - __retVal = __PInvoke(__input_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] - static extern unsafe uint __PInvoke(int __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool ReturnUIntAsByteBool(uint input) - { - bool __retVal; - byte __retVal_native; - { - __retVal_native = __PInvoke(input); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] - static extern unsafe byte __PInvoke(uint __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool ReturnUIntAsVariantBool(uint input) - { - bool __retVal; - short __retVal_native; - { - __retVal_native = __PInvoke(input); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native == -1; - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] - static extern unsafe short __PInvoke(uint __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool ReturnUIntAsWinBool(uint input) - { - bool __retVal; - int __retVal_native; - { - __retVal_native = __PInvoke(input); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "winbool_return_as_uint", ExactSpelling = true)] - static extern unsafe int __PInvoke(uint __input_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsByteBool_Ref(uint input, ref bool res) - { - byte __res_native; - // Marshal - Convert managed data to native data. - __res_native = (byte)(res ? 1 : 0); - { - __PInvoke(input, &__res_native); - } - - // Unmarshal - Convert native data to managed data. - res = __res_native != 0; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsByteBool_Out(uint input, out bool res) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - byte __res_native; - { - __PInvoke(input, &__res_native); - } - - // Unmarshal - Convert native data to managed data. - res = __res_native != 0; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsByteBool_In(uint input, in bool res) - { - byte __res_native; - // Marshal - Convert managed data to native data. - __res_native = (byte)(res ? 1 : 0); - { - __PInvoke(input, &__res_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, byte* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsVariantBool_Ref(uint input, ref bool res) - { - short __res_native; - // Marshal - Convert managed data to native data. - __res_native = (short)(res ? -1 : 0); - { - __PInvoke(input, &__res_native); - } - - // Unmarshal - Convert native data to managed data. - res = __res_native == -1; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, short* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsVariantBool_Out(uint input, out bool res) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - short __res_native; - { - __PInvoke(input, &__res_native); - } - - // Unmarshal - Convert native data to managed data. - res = __res_native == -1; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, short* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsVariantBool_In(uint input, in bool res) - { - short __res_native; - // Marshal - Convert managed data to native data. - __res_native = (short)(res ? -1 : 0); - { - __PInvoke(input, &__res_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refvariantbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, short* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsWinBool_Ref(uint input, ref bool res) - { - int __res_native; - // Marshal - Convert managed data to native data. - __res_native = (int)(res ? 1 : 0); - { - __PInvoke(input, &__res_native); - } - - // Unmarshal - Convert native data to managed data. - res = __res_native != 0; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, int* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsWinBool_Out(uint input, out bool res) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - int __res_native; - { - __PInvoke(input, &__res_native); - } - - // Unmarshal - Convert native data to managed data. - res = __res_native != 0; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, int* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsWinBool_In(uint input, in bool res) - { - int __res_native; - // Marshal - Convert managed data to native data. - __res_native = (int)(res ? 1 : 0); - { - __PInvoke(input, &__res_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "uint_return_as_refwinbool", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, int* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - internal unsafe partial class NativeExportsNE - { - internal unsafe partial class CallingConventions - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "add_integers_cdecl", ExactSpelling = true)] - public static extern partial long AddLongsCdecl(long i, long j, long k, long l, long m, long n, long o, long p, long q); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - internal unsafe partial class NativeExportsNE - { - internal unsafe partial class CallingConventions - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "add_integers_stdcall", ExactSpelling = true)] - public static extern partial long AddLongsStdcall(long i, long j, long k, long l, long m, long n, long o, long p, long q); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "ushort_return_as_uint", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public static extern partial uint ReturnUnicodeAsUInt(char input); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Unicode)] - public static extern partial char ReturnUIntAsUnicode(uint input); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsUnicode_Ref(uint input, ref char res) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (char* __res_native = &res) - { - __PInvoke(input, __res_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, char* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsUnicode_Out(uint input, out char res) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (char* __res_native = &res) - { - __PInvoke(input, __res_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, char* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReturnUIntAsUnicode_In(uint input, in char res) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (char* __res_native = &res) - { - __PInvoke(input, __res_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_refushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(uint __input_native, char* __res_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true)] - public static extern partial char ReturnU2AsU2IgnoreCharSet(char input); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_return_as_uint", ExactSpelling = true)] - public static extern partial char ReturnI2AsI2IgnoreCharSet(char input); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReverseBuffer(ref char buffer, int len) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (char* __buffer_native = &buffer) - { - __PInvoke(__buffer_native, len); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "char_reverse_buffer_ref", ExactSpelling = true)] - static extern unsafe void __PInvoke(char* __buffer_native, int __len_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Utf8StringSpan(global::System.ReadOnlySpan s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.IntPtr* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - int __s_native__numElements; - int __s_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __s_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __s_native__managedSpan = __s_native__marshaller.GetManagedValuesSource(); - System.Span __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __s_native__managedSpan.Length; ++__i0, ++__s_native__lastIndexMarshalled) - { - __s_native__nativeSpan[__i0] = (System.IntPtr)(byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__s_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native__unused = __s_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __s_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free((byte*)__s_native__nativeSpan[__i0]); - } - } - - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "Utf8StringSpan", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Utf8StringArray(string[] s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.IntPtr* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - int __s_native__numElements; - int __s_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __s_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __s_native__managedSpan = __s_native__marshaller.GetManagedValuesSource(); - System.Span __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __s_native__managedSpan.Length; ++__i0, ++__s_native__lastIndexMarshalled) - { - __s_native__nativeSpan[__i0] = (System.IntPtr)(byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(__s_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native__unused = __s_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __s_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __s_native__nativeSpan = __s_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __s_native__lastIndexMarshalled; ++__i0) - { - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free((byte*)__s_native__nativeSpan[__i0]); - } - } - - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "Utf8StringArray", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void MarshalSingleDimensionalArray(global::SharedTypes.BoolStruct[] c) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - nint* __c_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); - int __c_native__numElements; - int __c_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __c_native__marshaller.FromManaged(c, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); - System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) - { - __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__c_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __c_native__unused = __c_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __c_native = __c_native__marshaller.ToUnmanaged(); - __PInvoke(__c_native); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __c_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); - } - } - - __c_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalSingleDimensionalArray", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint* __c_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked(global::SharedTypes.BoolStruct[][] c) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - nint* __c_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); - int __c_native__numElements; - int __c_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __c_native__marshaller.FromManaged(c, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); - System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) - { - __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToUnmanaged(__c_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __c_native__unused = __c_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __c_native = __c_native__marshaller.ToUnmanaged(); - __PInvoke(__c_native); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __c_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__c_native__nativeSpan[__i0]); - } - } - - __c_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalMultidimensionalArray_CheckOuterArrayIsIndexTracked", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint* __c_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void MarshalMultidimensionalArray_CheckInnerArraysAreCleared(global::SharedTypes.BoolStruct[][] c) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.IntPtr* __c_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __c_native__marshaller = new(); - int __c_native__numElements; - int __c_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __c_native__marshaller.FromManaged(c, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __c_native__managedSpan = __c_native__marshaller.GetManagedValuesSource(); - System.Span __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) - { - int __c_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__nativeSpan____i0__numElements); - __c_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__c_native__managedSpan[__i0], out __c_native__nativeSpan____i0__numElements); - { - System.ReadOnlySpan __c_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__c_native__managedSpan[__i0]); - System.Span __c_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__c_native__nativeSpan[__i0], __c_native__nativeSpan____i0__numElements); - __c_native__nativeSpan____i0__nativeSpan.Clear(); - for (int __i1 = 0; __i1 < __c_native__nativeSpan____i0__managedSpan.Length; ++__i1) - { - __c_native__nativeSpan____i0__nativeSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToUnmanaged(__c_native__nativeSpan____i0__managedSpan[__i1]); - } - } - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __c_native__unused = __c_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __c_native = __c_native__marshaller.ToUnmanaged(); - __PInvoke(__c_native); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __c_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __c_native__nativeSpan = __c_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) - { - int __c_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__nativeSpan____i0__numElements); - __c_native__nativeSpan____i0__numElements = 0; - { - System.ReadOnlySpan __c_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__c_native__nativeSpan[__i0], __c_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __c_native__nativeSpan____i0__nativeSpan.Length; ++__i1) - { - global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__c_native__nativeSpan____i0__nativeSpan[__i1]); - } -<<<<<<< HEAD - }; -======= - } - - __c_native__nativeSpan____i0__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__c_native__nativeSpan[__i0]); - } - } - - __c_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalMultidimensionalArray_CheckInnerArraysAreCleared", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr* __c_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void MarshalArray_Ref(ref global::SharedTypes.BoolStruct[] c) - { - nint* __c_native = default; - // Setup - Perform required setup. - int __c_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __c_native__numElements); - int __c_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __c_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(c, out __c_native__numElements); - { - System.ReadOnlySpan __c_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(c); - System.Span __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__c_native, __c_native__numElements); - for (int __i0 = 0; __i0 < __c_native__managedSpan.Length; ++__i0, ++__c_native__lastIndexMarshalled) - { - __c_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__c_native__managedSpan[__i0]); - } - } - - { - __PInvoke(&__c_native); - } - - // Unmarshal - Convert native data to managed data. - __c_native__numElements = 10; - c = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__c_native, __c_native__numElements); - { - System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__c_native, __c_native__numElements); - System.Span __c_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(c); - for (int __i0 = 0; __i0 < __c_native__numElements; ++__i0) - { - __c_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToManaged(__c_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__c_native, __c_native__numElements); -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - { - System.ReadOnlySpan __c_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__c_native, __c_native__numElements); ->>>>>>> 4637ad2 (Latest chanages) - for (int __i0 = 0; __i0 < __c_native__lastIndexMarshalled; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__c_native__nativeSpan[__i0]); - } - } - - __c_native__numElements = 10; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__c_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "MarshalArray_Ref", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint** __c_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBoolsOut(global::SharedTypes.BoolStruct[] boolStruct, int numValues, out global::SharedTypes.BoolStruct[] pBoolStructOut) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native = default; - nint* __pBoolStructOut_native = default; - // Setup - Perform required setup. - int __pBoolStructOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __pBoolStructOut_native__numElements = numValues; - pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) - { - __pBoolStructOut_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan[__i0]); - } - } - - __pBoolStructOut_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan[__i0]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native, int __numValues_native, nint** __pBoolStructOut_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBoolsOut2D(global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths, out global::SharedTypes.BoolStruct[][] pBoolStructOut) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - System.IntPtr* __boolStruct_native = default; - System.IntPtr* __pBoolStructOut_native = default; - // Setup - Perform required setup. - int __pBoolStructOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - int __boolStruct_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); - __boolStruct_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__boolStruct_native__managedSpan[__i0], out __boolStruct_native__nativeSpan____i0__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__boolStruct_native__managedSpan[__i0]); - System.Span __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); - __boolStruct_native__nativeSpan____i0__nativeSpan.Clear(); - for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__managedSpan.Length; ++__i1) - { - __boolStruct_native__nativeSpan____i0__nativeSpan[__i1] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__nativeSpan____i0__managedSpan[__i1]); - } - } - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) - fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __PInvoke(__boolStruct_native, length, (int*)__widths_native, &__pBoolStructOut_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __pBoolStructOut_native__numElements = length; - pBoolStructOut = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - System.Span __pBoolStructOut_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(pBoolStructOut); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) - { - int __pBoolStructOut_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); - __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; - __pBoolStructOut_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); - System.Span __pBoolStructOut_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__pBoolStructOut_native__managedSpan[__i0]); - for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__numElements; ++__i1) - { - __pBoolStructOut_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.ConvertToManaged(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) - { - int __pBoolStructOut_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); - __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__nativeSpan.Length; ++__i1) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - - __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__pBoolStructOut_native__nativeSpan[__i0]); - } - } - - __pBoolStructOut_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__nativeSpan.Length; ++__i0) - { - int __pBoolStructOut_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__nativeSpan____i0__numElements); - __pBoolStructOut_native__nativeSpan____i0__numElements = widths[__i0]; - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__pBoolStructOut_native__nativeSpan[__i0], __pBoolStructOut_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __pBoolStructOut_native__nativeSpan____i0__nativeSpan.Length; ++__i1) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpBoolStruct.Free(__pBoolStructOut_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__pBoolStructOut_native__nativeSpan[__i0]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__pBoolStructOut_native); - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) - { - int __boolStruct_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); -<<<<<<< HEAD - ; -======= - __boolStruct_native__nativeSpan____i0__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((global::SharedTypes.BoolStructMarshaller.BoolStructNative*)__boolStruct_native__nativeSpan[__i0]); - } - } - - __boolStruct_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out_2d", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr* __boolStruct_native, int __length_native, int* __widths_native, System.IntPtr** __pBoolStructOut_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool FillRangeArray(global::SharedTypes.IntStructWrapper[] array, int length, int start) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - nint* __array_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); - int __array_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __array_native__marshaller.FromManaged(array, stackalloc nint[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __array_native__unused = __array_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __array_native = __array_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__array_native, length, start); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - { - __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; - System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); - System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) - { - __array_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.ConvertToManaged(__array_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan[__i0]); - } - } - -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan[__i0]); - } - } - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __array_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array", ExactSpelling = true)] - static extern unsafe byte __PInvoke(nint* __array_native, int __length_native, int __start_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool FillRangeArray2D(global::SharedTypes.IntStructWrapper[][] array, int length, int[] widths, int start) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.IntPtr* __array_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn __array_native__marshaller = new(); - int __array_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __array_native__marshaller.FromManaged(array, stackalloc System.IntPtr[global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.BufferSize]); - __array_native__marshaller.GetUnmanagedValuesDestination().Clear(); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) - fixed (void* __array_native__unused = __array_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __array_native = __array_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__array_native, length, (int*)__widths_native, start); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - { - __array_native__numElements = __array_native__marshaller.GetManagedValuesSource().Length; - System.Span __array_native__managedSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in __array_native__marshaller.GetManagedValuesSource().GetPinnableReference()), __array_native__numElements); - System.Span __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__numElements; ++__i0) - { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; - __array_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - { - System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - System.Span __array_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__array_native__managedSpan[__i0]); - for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__numElements; ++__i1) - { - __array_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.ConvertToManaged(__array_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) - { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; - { - System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - - __array_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); - } - } - -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - { - System.ReadOnlySpan __array_native__nativeSpan = __array_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __array_native__nativeSpan.Length; ++__i0) - { - int __array_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __array_native__nativeSpan____i0__numElements); - __array_native__nativeSpan____i0__numElements = widths[__i0]; - { - System.ReadOnlySpan __array_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__array_native__nativeSpan[__i0], __array_native__nativeSpan____i0__numElements); - for (int __i1 = 0; __i1 < __array_native__nativeSpan____i0__nativeSpan.Length; ++__i1) - { - global::LibraryImportGenerator.IntegrationTests.EnforceAllElementsCleanedUpIntStruct.Free(__array_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__array_native__nativeSpan[__i0]); - } - } - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __array_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "fill_range_array_2d", ExactSpelling = true)] - static extern unsafe byte __PInvoke(System.IntPtr* __array_native, int __length_native, int* __widths_native, int __start_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBoolsRef(ref global::SharedTypes.BoolStruct[] boolStruct, int numValues) - { - nint* __boolStruct_native = default; - // Setup - Perform required setup. - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - __PInvoke(&__boolStruct_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __boolStruct_native__numElements = numValues; - boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); - System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); - for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) - { - __boolStruct_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); ->>>>>>> 4637ad2 (Latest chanages) - for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStruct.Free(__boolStruct_native__nativeSpan[__i0]); - } - } - - __boolStruct_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint** __boolStruct_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBoolsRef2D_LastElementMarshalling(ref global::SharedTypes.BoolStruct[][] boolStruct, int length) - { - nint* __boolStruct_native = default; - // Setup - Perform required setup. - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - __PInvoke(&__boolStruct_native, length); - } - - // Unmarshal - Convert native data to managed data. - __boolStruct_native__numElements = length; - boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); - System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); - for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) - { - __boolStruct_native__managedSpan[__i0] = global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); ->>>>>>> 4637ad2 (Latest chanages) - for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) - { - global::LibraryImportGenerator.IntegrationTests.EnforceLastElementMarshalledCleanupBoolStructArray.Free(__boolStruct_native__nativeSpan[__i0]); - } - } - - __boolStruct_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "negate_bool_struct_array_ref_2d", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint** __boolStruct_native, int __length_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class MarshallingFails - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBoolsRef2D_ClearMarshalling(ref global::SharedTypes.BoolStruct[][] boolStruct, int length, int[] widths) - { - System.IntPtr* __boolStruct_native = default; - // Setup - Perform required setup. - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - int __boolStruct_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); - __boolStruct_native__nativeSpan[__i0] = (System.IntPtr)global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForUnmanagedElements(__boolStruct_native__managedSpan[__i0], out __boolStruct_native__nativeSpan____i0__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesSource(__boolStruct_native__managedSpan[__i0]); - System.Span __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); - __boolStruct_native__nativeSpan____i0__nativeSpan.Clear(); - for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__managedSpan.Length; ++__i1) - { - __boolStruct_native__nativeSpan____i0__nativeSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToUnmanaged(__boolStruct_native__nativeSpan____i0__managedSpan[__i1]); - } - } - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __widths_native = &global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.ManagedToUnmanagedIn.GetPinnableReference(widths)) - { - __PInvoke(&__boolStruct_native, length, (int*)__widths_native); - } - - // Unmarshal - Convert native data to managed data. - __boolStruct_native__numElements = length; - boolStruct = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); - System.Span __boolStruct_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(boolStruct); - for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) - { - int __boolStruct_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); - __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; - __boolStruct_native__managedSpan[__i0] = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.AllocateContainerForManagedElements((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); - System.Span __boolStruct_native__nativeSpan____i0__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetManagedValuesDestination(__boolStruct_native__managedSpan[__i0]); - for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__numElements; ++__i1) - { - __boolStruct_native__nativeSpan____i0__managedSpan[__i1] = global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.ConvertToManaged(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); ->>>>>>> 4637ad2 (Latest chanages) - for (int __i0 = 0; __i0 < __boolStruct_native__lastIndexMarshalled; ++__i0) - { - int __boolStruct_native__nativeSpan____i0__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__nativeSpan____i0__numElements); - __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; - { -<<<<<<< HEAD - System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesSource((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); -======= - System.ReadOnlySpan __boolStruct_native__nativeSpan____i0__nativeSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.GetUnmanagedValuesDestination((nint*)__boolStruct_native__nativeSpan[__i0], __boolStruct_native__nativeSpan____i0__numElements); ->>>>>>> 4637ad2 (Latest chanages) - for (int __i1 = 0; __i1 < __boolStruct_native__nativeSpan____i0__nativeSpan.Length; ++__i1) - { - global::LibraryImportGenerator.IntegrationTests.EnforceClearedMemoryCleanup.Free(__boolStruct_native__nativeSpan____i0__nativeSpan[__i1]); - } - } - - __boolStruct_native__nativeSpan____i0__numElements = widths[__i0]; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free((nint*)__boolStruct_native__nativeSpan[__i0]); - } - } - - __boolStruct_native__numElements = length; - global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller.Free(__boolStruct_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("DoesNotExist", EntryPoint = "negate_bool_struct_array_ref_2d", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr** __boolStruct_native, int __length_native, int* __widths_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int Sum(global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __retVal = __PInvoke(__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - ; -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - __values_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__values_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumWithBuffer(global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - System.Span __values_native__buffer = stackalloc byte[global::SharedTypes.ListMarshallerWithBuffer.BufferSize]; - __values_native = global::SharedTypes.ListMarshallerWithBuffer.AllocateContainerForUnmanagedElements(values, __values_native__buffer, out __values_native__numElements); - global::SharedTypes.ListMarshallerWithBuffer.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshallerWithBuffer.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __retVal = __PInvoke(__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - ; -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - __values_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - int __values_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - { - System.ReadOnlySpan __values_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(values); - System.Span __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) - { - __values_native__nativeSpan[__i0] = (System.IntPtr)(int*)global::SharedTypes.IntWrapperMarshallerWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); - } - } - - { - __retVal = __PInvoke(__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __values_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements); - for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) - { - global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); - } -<<<<<<< HEAD - }; -======= - } - - __values_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__values_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int DoubleValues(global::System.Collections.Generic.List values, int length) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native = &global::SharedTypes.ListMarshallerWithPinning.GetPinnableReference(values)) - { - __retVal = __PInvoke((byte*)__values_native, length); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_values", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __values_native, int __length_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumInArray(in global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __retVal = __PInvoke(&__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - ; -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - __values_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__values_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte** __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Duplicate(ref global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::SharedTypes.ListMarshaller.GetManagedValuesSource(values).CopyTo(global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __PInvoke(&__values_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(values)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__numElements = numValues; - global::SharedTypes.ListMarshaller.Free(__values_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - global::System.Collections.Generic.List __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __retVal_native = __PInvoke(start, end, __numValues_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; - global::SharedTypes.ListMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.ListMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(int __start_native, int __end_native, int* __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - byte* __res_native = default; - // Setup - Perform required setup. - int __res_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __PInvoke(start, end, __numValues_native, &__res_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - res = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(res)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __res_native__numElements = numValues; - global::SharedTypes.ListMarshaller.Free(__res_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.ListMarshaller.Free(__res_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Collections.Generic.List GetLongBytes(long l) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::System.Collections.Generic.List __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - { - __retVal_native = __PInvoke(l); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = 8; - __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = 8; - global::SharedTypes.ListMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.ListMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(long __l_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) - { - byte* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - int __pArray_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - int __pArray_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __pArray_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(pArray, out __pArray_native__numElements); - { - System.ReadOnlySpan __pArray_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(pArray); - System.Span __pArray_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__pArray_native, __pArray_native__numElements); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - { - __retVal_native = __PInvoke(__pArray_native, length); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - _ = __pArray_native__lastIndexMarshalled; - ; -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__pArray_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] - static extern unsafe byte __PInvoke(byte* __pArray_native, int __length_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) - { - byte* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - int __pArray_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - int __pArray_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __pArray_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(pArray, out __pArray_native__numElements); - { - System.ReadOnlySpan __pArray_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(pArray); - System.Span __pArray_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__pArray_native, __pArray_native__numElements); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - { - __retVal_native = __PInvoke(&__pArray_native, length); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - _ = __pArray_native__lastIndexMarshalled; - ; -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__pArray_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] - static extern unsafe byte __PInvoke(byte** __pArray_native, int __length_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) - { - byte* __boolStruct_native = default; - // Setup - Perform required setup. - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - __PInvoke(&__boolStruct_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __boolStruct_native__numElements = numValues; - boolStruct = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__boolStruct_native, __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__boolStruct_native, __boolStruct_native__numElements); - System.Span __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(boolStruct); - for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) - { - __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__numElements = numValues; - global::SharedTypes.ListMarshaller.Free(__boolStruct_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __boolStruct_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - byte* __boolStruct_native = default; - byte* __pBoolStructOut_native = default; - // Setup - Perform required setup. - int __pBoolStructOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __pBoolStructOut_native__numElements = numValues; - pBoolStructOut = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__pBoolStructOut_native, __pBoolStructOut_native__numElements); - System.Span __pBoolStructOut_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(pBoolStructOut); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) - { - __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __pBoolStructOut_native__numElements = numValues; - global::SharedTypes.ListMarshaller.Free(__pBoolStructOut_native); - _ = __boolStruct_native__lastIndexMarshalled; - ; -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.ListMarshaller.Free(__pBoolStructOut_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__boolStruct_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte* __boolStruct_native, int __numValues_native, byte** __pBoolStructOut_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __boolStruct_native = default; - global::System.Collections.Generic.List __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - int __boolStruct_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - int __boolStruct_native__lastIndexMarshalled = 0; - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native = global::SharedTypes.ListMarshaller.AllocateContainerForUnmanagedElements(boolStruct, out __boolStruct_native__numElements); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesSource(boolStruct); - System.Span __boolStruct_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesDestination(__boolStruct_native, __boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - __retVal_native = __PInvoke(__boolStruct_native, numValues); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal = global::SharedTypes.ListMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - { - System.ReadOnlySpan __retVal_native__nativeSpan = global::SharedTypes.ListMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements); - System.Span __retVal_native__managedSpan = global::SharedTypes.ListMarshaller.GetManagedValuesDestination(__retVal); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) - { - __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); - } - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; - global::SharedTypes.ListMarshaller.Free(__retVal_native); - _ = __boolStruct_native__lastIndexMarshalled; - ; -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.ListMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__numElements = 0; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.ListMarshaller.Free(__boolStruct_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(byte* __boolStruct_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) - { - bool __invokeSucceeded = default; - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __ret_native = default; - int __retVal = default; - int __retVal_native = default; - // Setup - Perform required setup. - int __ret_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); - try - { - { - __retVal_native = __PInvoke(&__ret_native); - } - - __invokeSucceeded = true; - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - __ret_native__numElements = 1; - ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); - } -<<<<<<< HEAD - - // Cleanup - Perform required cleanup. - __ret_native__numElements = 1; -======= ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte** __ret_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) - { - bool __invokeSucceeded = default; - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __ret_native = default; - int __retVal = default; - int __retVal_native = default; - // Setup - Perform required setup. - int __ret_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); - try - { - { - __retVal_native = __PInvoke(&__ret_native); - } - - __invokeSucceeded = true; - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - __ret_native__numElements = 1; - ret = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateless.ListGuaranteedUnmarshal.AllocateContainerForManagedElementsFinally(__ret_native, __ret_native__numElements); - } -<<<<<<< HEAD - - // Cleanup - Perform required cleanup. - __ret_native__numElements = 1; -======= ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte** __ret_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int Sum(global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values, stackalloc int[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native__unused = __values_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static unsafe partial int SumWithFreeTracking(global::System.Collections.Generic.List values, int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); - int __values_native__numElements; - int __values_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values, stackalloc System.IntPtr[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - { - System.ReadOnlySpan __values_native__managedSpan = __values_native__marshaller.GetManagedValuesSource(); - System.Span __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __values_native__managedSpan.Length; ++__i0, ++__values_native__lastIndexMarshalled) - { - __values_native__nativeSpan[__i0] = (System.IntPtr)(int*)global::SharedTypes.IntWrapperMarshallerWithFreeCounts.ConvertToUnmanaged(__values_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native__unused = __values_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__values_native, numValues); - } -<<<<<<< HEAD - } - finally - { - // Cleanup - Perform required cleanup. -======= - - __invokeSucceeded = true; - } - finally - { - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __values_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - { - System.ReadOnlySpan __values_native__nativeSpan = __values_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __values_native__lastIndexMarshalled; ++__i0) - { - global::SharedTypes.IntWrapperMarshallerWithFreeCounts.Free((int*)__values_native__nativeSpan[__i0]); - } - } - - __values_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_ptr_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumInArray(in global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values, stackalloc int[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native__unused = __values_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(&__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte** __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Duplicate(ref global::System.Collections.Generic.List values, int numValues) - { - byte* __values_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __values_native__marshaller = new(); - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values); - __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __PInvoke(&__values_native, numValues); - } - - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __values_native__marshaller.FromUnmanaged(__values_native); - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - __values_native__marshaller.GetUnmanagedValuesSource(__values_native__numElements).CopyTo(__values_native__marshaller.GetManagedValuesDestination(__values_native__numElements)); - values = __values_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __values_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Collections.Generic.List CreateRange(int start, int end, out int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - global::System.Collections.Generic.List __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __retVal_native = __PInvoke(start, end, __numValues_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); - __retVal = __retVal_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(int __start_native, int __end_native, int* __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Collections.Generic.List res) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - System.Runtime.CompilerServices.Unsafe.SkipInit(out res); - byte* __res_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __res_native__marshaller = new(); - int __res_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __PInvoke(start, end, __numValues_native, &__res_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __res_native__marshaller.FromUnmanaged(__res_native); - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - __res_native__marshaller.GetUnmanagedValuesSource(__res_native__numElements).CopyTo(__res_native__marshaller.GetManagedValuesDestination(__res_native__numElements)); - res = __res_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __res_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __res_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, byte** __res_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Collections.Generic.List GetLongBytes(long l) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::System.Collections.Generic.List __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - { - __retVal_native = __PInvoke(l); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = 8; - __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements).CopyTo(__retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements)); - __retVal = __retVal_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(long __l_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembers(global::System.Collections.Generic.List pArray, int length) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pArray_native__marshaller = new(); - int __pArray_native__numElements; - int __pArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - { - System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); - System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pArray_native__unused = __pArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pArray_native = __pArray_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__pArray_native, length); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __pArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] - static extern unsafe byte __PInvoke(byte* __pArray_native, int __length_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembersIn(in global::System.Collections.Generic.List pArray, int length) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pArray_native__marshaller = new(); - int __pArray_native__numElements; - int __pArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - { - System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); - System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pArray_native__unused = __pArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pArray_native = __pArray_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(&__pArray_native, length); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __pArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array_in", ExactSpelling = true)] - static extern unsafe byte __PInvoke(byte** __pArray_native, int __length_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(ref global::System.Collections.Generic.List boolStruct, int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __boolStruct_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __PInvoke(&__boolStruct_native, numValues); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __boolStruct_native__marshaller.FromUnmanaged(__boolStruct_native); - // Unmarshal - Convert native data to managed data. - __boolStruct_native__numElements = numValues; - { - System.ReadOnlySpan __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesSource(__boolStruct_native__numElements); - System.Span __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesDestination(__boolStruct_native__numElements); - for (int __i0 = 0; __i0 < __boolStruct_native__numElements; ++__i0) - { - __boolStruct_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__boolStruct_native__nativeSpan[__i0]); - } - } - - boolStruct = __boolStruct_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_ref", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __boolStruct_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(global::System.Collections.Generic.List boolStruct, int numValues, out global::System.Collections.Generic.List pBoolStructOut) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - byte* __boolStruct_native = default; - byte* __pBoolStructOut_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __pBoolStructOut_native__marshaller = new(); - int __pBoolStructOut_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pBoolStructOut_native__numElements); - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __PInvoke(__boolStruct_native, numValues, &__pBoolStructOut_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); - // Unmarshal - Convert native data to managed data. - __pBoolStructOut_native__numElements = numValues; - { - System.ReadOnlySpan __pBoolStructOut_native__nativeSpan = __pBoolStructOut_native__marshaller.GetUnmanagedValuesSource(__pBoolStructOut_native__numElements); - System.Span __pBoolStructOut_native__managedSpan = __pBoolStructOut_native__marshaller.GetManagedValuesDestination(__pBoolStructOut_native__numElements); - for (int __i0 = 0; __i0 < __pBoolStructOut_native__numElements; ++__i0) - { - __pBoolStructOut_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native__nativeSpan[__i0]); - } - } - - pBoolStructOut = __pBoolStructOut_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __pBoolStructOut_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __pBoolStructOut_native__marshaller.Free(); - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte* __boolStruct_native, int __numValues_native, byte** __pBoolStructOut_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Collections.Generic.List NegateBools(global::System.Collections.Generic.List boolStruct, int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __boolStruct_native = default; - global::System.Collections.Generic.List __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __retVal_native__marshaller = new(); - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - scoped global::SharedTypes.ListMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); - int __boolStruct_native__numElements; - int __boolStruct_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __boolStruct_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::SharedTypes.ListMarshallerStateful.Marshaller.BufferSize]); - { - System.ReadOnlySpan __boolStruct_native__managedSpan = __boolStruct_native__marshaller.GetManagedValuesSource(); - System.Span __boolStruct_native__nativeSpan = __boolStruct_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __boolStruct_native__managedSpan.Length; ++__i0, ++__boolStruct_native__lastIndexMarshalled) - { - __boolStruct_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__boolStruct_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __boolStruct_native__unused = __boolStruct_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__boolStruct_native, numValues); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - { - System.ReadOnlySpan __retVal_native__nativeSpan = __retVal_native__marshaller.GetUnmanagedValuesSource(__retVal_native__numElements); - System.Span __retVal_native__managedSpan = __retVal_native__marshaller.GetManagedValuesDestination(__retVal_native__numElements); - for (int __i0 = 0; __i0 < __retVal_native__numElements; ++__i0) - { - __retVal_native__managedSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__retVal_native__nativeSpan[__i0]); - } - } - - __retVal = __retVal_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - _ = __boolStruct_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __boolStruct_native__lastIndexMarshalled; - __boolStruct_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bool_struct_array_return", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(byte* __boolStruct_native, int __numValues_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) - { - bool __invokeSucceeded = default; - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __ret_native = default; - int __retVal = default; - int __retVal_native = default; - // Setup - Perform required setup. - global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateful.ListGuaranteedUnmarshal.Marshaller __ret_native__marshaller = new(); - int __ret_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); - try - { - { - __retVal_native = __PInvoke(&__ret_native); - } - - __invokeSucceeded = true; - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __ret_native__marshaller.FromUnmanaged(__ret_native); - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - ret = __ret_native__marshaller.ToManagedFinally(); -<<<<<<< HEAD - } - - // Cleanup - Perform required cleanup. - __ret_native__marshaller.Free(); -======= - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __ret_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte** __ret_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Collections - { - public unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int GuaranteedUnmarshal(out global::System.Collections.Generic.List ret) - { - bool __invokeSucceeded = default; - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __ret_native = default; - int __retVal = default; - int __retVal_native = default; - // Setup - Perform required setup. - global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Collections.Stateful.ListGuaranteedUnmarshal.Marshaller __ret_native__marshaller = new(); - int __ret_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __ret_native__numElements); - try - { - { - __retVal_native = __PInvoke(&__ret_native); - } - - __invokeSucceeded = true; - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __ret_native__marshaller.FromUnmanaged(__ret_native); - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__retVal_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - ret = __ret_native__marshaller.ToManagedFinally(); -<<<<<<< HEAD - } - - // Cleanup - Perform required cleanup. - __ret_native__marshaller.Free(); -======= - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __ret_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte** __ret_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void DeepDuplicateStrings(global::SharedTypes.StringContainer strings, out global::SharedTypes.StringContainer pStringsOut) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out pStringsOut); - global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; - global::SharedTypes.StringContainerMarshaller.StringContainerNative __pStringsOut_native = default; - try - { - // Marshal - Convert managed data to native data. - __strings_native = global::SharedTypes.StringContainerMarshaller.In.ConvertToUnmanaged(strings); - { - __PInvoke(__strings_native, &__pStringsOut_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - pStringsOut = global::SharedTypes.StringContainerMarshaller.Out.ConvertToManaged(__pStringsOut_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::SharedTypes.StringContainerMarshaller.Out.Free(__pStringsOut_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.StringContainerMarshaller.Out.Free(__pStringsOut_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.StringContainerMarshaller.In.Free(__strings_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_deepduplicate", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native, global::SharedTypes.StringContainerMarshaller.StringContainerNative* __pStringsOut_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReverseStrings(ref global::SharedTypes.StringContainer strings) - { - global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default; - try - { - // Marshal - Convert managed data to native data. - __strings_native = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToUnmanaged(strings); - { - __PInvoke(&__strings_native); - } - - // Unmarshal - Convert native data to managed data. - strings = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToManaged(__strings_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.StringContainerMarshaller.Ref.Free(__strings_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_reverse_strings", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative* __strings_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial double GetLongBytesAsDouble(double d) - { - long __d_native; - double __retVal; - // Marshal - Convert managed data to native data. - __d_native = global::SharedTypes.DoubleToLongMarshaller.ConvertToUnmanaged(d); - { - __retVal = __PInvoke(__d_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes_as_double", ExactSpelling = true)] - static extern unsafe double __PInvoke(long __d_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial double GetBytesAsDoubleBigEndian(double d) - { - byte* __d_native; - double __retVal; - // Marshal - Convert managed data to native data. - System.Span __d_native__buffer = stackalloc byte[global::SharedTypes.DoubleToBytesBigEndianMarshaller.BufferSize]; - __d_native = global::SharedTypes.DoubleToBytesBigEndianMarshaller.ConvertToUnmanaged(d, __d_native__buffer); - { - __retVal = __PInvoke(__d_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_bytes_as_double_big_endian", ExactSpelling = true)] - static extern unsafe double __PInvoke(byte* __d_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(global::SharedTypes.BoolStruct boolStruct, out global::SharedTypes.BoolStruct pBoolStructOut) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native; - global::SharedTypes.BoolStructMarshaller.BoolStructNative __pBoolStructOut_native; - // Marshal - Convert managed data to native data. - __boolStruct_native = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(boolStruct); - { - __PInvoke(__boolStruct_native, &__pBoolStructOut_native); - } - - // Unmarshal - Convert native data to managed data. - pBoolStructOut = global::SharedTypes.BoolStructMarshaller.ConvertToManaged(__pBoolStructOut_native); - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bools", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native, global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pBoolStructOut_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndBoolsRef(in global::SharedTypes.BoolStruct boolStruct) - { - global::SharedTypes.BoolStructMarshaller.BoolStructNative __boolStruct_native; - bool __retVal; - byte __retVal_native; - // Marshal - Convert managed data to native data. - __boolStruct_native = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(boolStruct); - { - __retVal_native = __PInvoke(&__boolStruct_native); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bools_ref", ExactSpelling = true)] - static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __boolStruct_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - int* __pInt_native = default; - global::SharedTypes.IntWrapper __retVal = default; - int* __retVal_native = default; - try - { - // Marshal - Convert managed data to native data. - __pInt_native = (int*)global::SharedTypes.IntWrapperMarshaller.ConvertToUnmanaged(pInt); - { - __retVal_native = __PInvoke(__pInt_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.IntWrapperMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::SharedTypes.IntWrapperMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.IntWrapperMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.IntWrapperMarshaller.Free(__pInt_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int* __pInt_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; - int* __retVal_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pInt_native = &global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.GetPinnableReference(pInt)) - { - __retVal_native = __PInvoke((int*)__pInt_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int* __pInt_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateless - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int GuaranteedUnmarshal(out int ret) - { - bool __invokeSucceeded = default; - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - int __ret_native = default; - int __retVal = default; - int __retVal_native = default; - try - { - { - __retVal_native = __PInvoke(&__ret_native); - } - - __invokeSucceeded = true; - // Unmarshal - Convert native data to managed data. - ret = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__ret_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - __retVal = global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Stateless.IntGuaranteedUnmarshal.ConvertToManagedFinally(__retVal_native); - } - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] - static extern unsafe int __PInvoke(int* __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.IntWrapperWithNotification SubtractInts(global::SharedTypes.IntWrapperWithNotification x, global::SharedTypes.IntWrapperWithNotification y) - { - int __x_native; - int __y_native; - global::SharedTypes.IntWrapperWithNotification __retVal; - int __retVal_native; - // Setup - Perform required setup. - global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __retVal_native__marshaller = new(); - global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __y_native__marshaller = new(); - global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __x_native__marshaller = new(); - // Marshal - Convert managed data to native data. - __y_native__marshaller.FromManaged(y); - __x_native__marshaller.FromManaged(x); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __y_native = __y_native__marshaller.ToUnmanaged(); - __x_native = __x_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__x_native, __y_native); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - __y_native__marshaller.OnInvoked(); - __x_native__marshaller.OnInvoked(); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native__marshaller.ToManaged(); - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_int", ExactSpelling = true)] - static extern unsafe int __PInvoke(int __x_native, int __y_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void SubtractInts(global::SharedTypes.IntWrapperWithNotification x, global::SharedTypes.IntWrapperWithNotification y, out global::SharedTypes.IntWrapperWithNotification result) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out result); - int __x_native; - int __y_native; - int __result_native; - // Setup - Perform required setup. - global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __result_native__marshaller = new(); - global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __y_native__marshaller = new(); - global::SharedTypes.IntWrapperWithNotificationMarshaller.Marshaller __x_native__marshaller = new(); - // Marshal - Convert managed data to native data. - __y_native__marshaller.FromManaged(y); - __x_native__marshaller.FromManaged(x); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __y_native = __y_native__marshaller.ToUnmanaged(); - __x_native = __x_native__marshaller.ToUnmanaged(); - __PInvoke(__x_native, __y_native, &__result_native); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - __y_native__marshaller.OnInvoked(); - __x_native__marshaller.OnInvoked(); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __result_native__marshaller.FromUnmanaged(__result_native); - // Unmarshal - Convert native data to managed data. - result = __result_native__marshaller.ToManaged(); - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_int", ExactSpelling = true)] - static extern unsafe void __PInvoke(int __x_native, int __y_native, int* __result_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void NegateBools(global::SharedTypes.BoolStruct boolStruct, out global::SharedTypes.BoolStruct pBoolStructOut) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out pBoolStructOut); - global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native; - global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __pBoolStructOut_native; - // Setup - Perform required setup. - global::SharedTypes.BoolStructMarshallerStateful.Marshaller __pBoolStructOut_native__marshaller = new(); - global::SharedTypes.BoolStructMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __PInvoke(__boolStruct_native, &__pBoolStructOut_native); - } - - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __pBoolStructOut_native__marshaller.FromUnmanaged(__pBoolStructOut_native); - // Unmarshal - Convert native data to managed data. - pBoolStructOut = __pBoolStructOut_native__marshaller.ToManaged(); - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "negate_bools", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native, global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative* __pBoolStructOut_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndBoolsRef(in global::SharedTypes.BoolStruct boolStruct) - { - global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative __boolStruct_native; - bool __retVal; - byte __retVal_native; - // Setup - Perform required setup. - global::SharedTypes.BoolStructMarshallerStateful.Marshaller __boolStruct_native__marshaller = new(); - // Marshal - Convert managed data to native data. - __boolStruct_native__marshaller.FromManaged(boolStruct); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __boolStruct_native = __boolStruct_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(&__boolStruct_native); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bools_ref", ExactSpelling = true)] - static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshallerStateful.BoolStructNative* __boolStruct_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRef(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; - int* __retVal_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pInt_native = &global::SharedTypes.IntWrapperWithoutGetPinnableReferenceStatefulMarshaller.StatelessGetPinnableReference.GetPinnableReference(pInt)) - { - __retVal_native = __PInvoke((int*)__pInt_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int* __pInt_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.IntWrapperWithoutGetPinnableReference DoubleIntRefNoAlloc(global::SharedTypes.IntWrapperWithoutGetPinnableReference pInt) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - int* __pInt_native = default; - global::SharedTypes.IntWrapperWithoutGetPinnableReference __retVal = default; - int* __retVal_native = default; - // Setup - Perform required setup. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceStatefulNoAllocMarshaller.StatefulGetPinnableReference __pInt_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __pInt_native__marshaller.FromManaged(pInt); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pInt_native__unused = __pInt_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pInt_native = __pInt_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__pInt_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::SharedTypes.IntWrapperWithoutGetPinnableReferenceMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int* __pInt_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::SharedTypes.IntWrapper DoubleIntRef(global::SharedTypes.IntWrapper pInt) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - int* __pInt_native = default; - global::SharedTypes.IntWrapper __retVal = default; - int* __retVal_native = default; - // Setup - Perform required setup. - global::SharedTypes.IntWrapperMarshallerStateful.Marshaller __retVal_native__marshaller = new(); - global::SharedTypes.IntWrapperMarshallerStateful.Marshaller __pInt_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __pInt_native__marshaller.FromManaged(pInt); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pInt_native = __pInt_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__pInt_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __pInt_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "double_int_ref", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int* __pInt_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - internal unsafe partial class Stateful - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int GuaranteedUnmarshal(out int ret) - { - bool __invokeSucceeded = default; - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - int __ret_native = default; - int __retVal = default; - int __retVal_native = default; - // Setup - Perform required setup. - global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.Stateful.IntGuaranteedUnmarshal.Marshaller __retVal_native__marshaller = new(); - try - { - { - __retVal_native = __PInvoke(&__ret_native); - } - - __invokeSucceeded = true; - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - ret = global::SharedTypes.ExceptionOnUnmarshal.ConvertToManaged(__ret_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - __retVal = __retVal_native__marshaller.ToManagedFinally(); -<<<<<<< HEAD - } - - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_zero", ExactSpelling = true)] - static extern unsafe int __PInvoke(int* __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ReverseReplaceString(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnStringLength(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void InvokeAfterGC(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.VoidVoid cb) - { - System.IntPtr __cb_native; - // Marshal - Convert managed data to native data. - __cb_native = cb != null ? System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(cb) : default; - { - __PInvoke(__cb_native); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - global::System.GC.KeepAlive(cb); - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] - static extern unsafe void __PInvoke(System.IntPtr __cb_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int InvokeWithBlittableArgument(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.IntIntInt cb, int a, int b) - { - System.IntPtr __cb_native; - int __retVal; - // Marshal - Convert managed data to native data. - __cb_native = cb != null ? System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(cb) : default; - { - __retVal = __PInvoke(__cb_native, a, b); - } - - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - global::System.GC.KeepAlive(cb); - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] - static extern unsafe int __PInvoke(System.IntPtr __cb_native, int __a_native, int __b_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class IntEnum - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_int", ExactSpelling = true)] - public static extern partial global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum Subtract_Return(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class IntEnum - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Subtract_Out(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b, out global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum c) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out c); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __c_native = &c) - { - __PInvoke(a, b, __c_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_int", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __b_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __c_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class IntEnum - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Subtract_Ref(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, ref global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native = &b) - { - __PInvoke(a, __b_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class IntEnum - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Subtract_In(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum a, in global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum b) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native = &b) - { - __PInvoke(a, __b_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.IntEnum* __b_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class ByteEnum - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_return_byte", ExactSpelling = true)] - public static extern partial global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum Subtract_Return(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class ByteEnum - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Subtract_Out(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b, out global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum c) - { - System.Runtime.CompilerServices.Unsafe.SkipInit(out c); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __c_native = &c) - { - __PInvoke(a, b, __c_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_out_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __b_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __c_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class ByteEnum - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Subtract_Ref(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, ref global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native = &b) - { - __PInvoke(a, __b_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class ByteEnum - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Subtract_In(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum a, in global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum b) - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native = &b) - { - __PInvoke(a, __b_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum __a_native, global::LibraryImportGenerator.IntegrationTests.EnumTests.ByteEnum* __b_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class FunctionPointer - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_managed_callback_after_gc", ExactSpelling = true)] - public static unsafe extern partial void InvokeAfterGC(delegate* cb); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class FunctionPointer - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] - public static unsafe extern partial void InvokeAfterGC(delegate* unmanaged cb); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class FunctionPointer - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_after_gc", ExactSpelling = true)] - public static unsafe extern partial void InvokeAfterGC(delegate* unmanaged[Stdcall] cb); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class FunctionPointer - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_managed_callback_blittable_args", ExactSpelling = true)] - public static unsafe extern partial int InvokeWithBlittableArgument(delegate* cb, int a, int b); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class FunctionPointer - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] - public static unsafe extern partial int InvokeWithBlittableArgument(delegate* unmanaged cb, int a, int b); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class FunctionPointer - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "invoke_callback_blittable_args", ExactSpelling = true)] - public static unsafe extern partial int InvokeWithBlittableArgument(delegate* unmanaged[Stdcall] cb, int a, int b); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_int", ExactSpelling = true)] - public static unsafe extern partial void Subtract_Int_Ptr(int a, int* b); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "subtract_ref_byte", ExactSpelling = true)] - public static unsafe extern partial void Subtract_Byte_Ptr(byte a, byte* b); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "blittablestructs_double_intfields_byref", ExactSpelling = true)] - public static unsafe extern partial void DoubleIntFields_Ptr(global::SharedTypes.IntFields* result); - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class NativeExportsSafeHandle - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - private static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; - nint __retVal_native = default; - // Setup - Perform required setup. - global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __retVal_native__marshaller = new(); - try - { - { - __retVal_native = __PInvoke(); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle", ExactSpelling = true)] - static extern unsafe nint __PInvoke(); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle AllocateHandle() - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle __retVal = default; - nint __retVal_native = default; - // Setup - Perform required setup. - global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __retVal_native__marshaller = new(); - try - { - { - __retVal_native = __PInvoke(); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __retVal_native__marshaller.FromUnmanaged(__retVal_native); - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __retVal_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle", ExactSpelling = true)] - static extern unsafe nint __PInvoke(); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void AllocateHandle(out global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out handle); - nint __handle_native = default; - // Setup - Perform required setup. - global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedOut __handle_native__marshaller = new(); - try - { - { - __PInvoke(&__handle_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __handle_native__marshaller.FromUnmanaged(__handle_native); - // Unmarshal - Convert native data to managed data. - handle = __handle_native__marshaller.ToManaged(); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __handle_native__marshaller.Free(); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - __handle_native__marshaller.Free(); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "alloc_handle_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint* __handle_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - private static partial bool ReleaseHandle(nint handle) - { - bool __retVal; - sbyte __retVal_native; - { - __retVal_native = __PInvoke(handle); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "release_handle", ExactSpelling = true)] - static extern unsafe sbyte __PInvoke(nint __handle_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool IsHandleAlive(global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle) - { - nint __handle_native = default; - bool __retVal = default; - sbyte __retVal_native = default; - // Setup - Perform required setup. - global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedIn __handle_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __handle_native__marshaller.FromManaged(handle); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __handle_native = __handle_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__handle_native); - } - - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __handle_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "is_handle_alive", ExactSpelling = true)] - static extern unsafe sbyte __PInvoke(nint __handle_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void ModifyHandle(ref global::LibraryImportGenerator.IntegrationTests.NativeExportsNE.NativeExportsSafeHandle handle, bool newHandle) - { - bool __invokeSucceeded = default; - nint __handle_native = default; - sbyte __newHandle_native = default; - // Setup - Perform required setup. - global::System.Runtime.InteropServices.Marshalling.SafeHandleMarshaller.ManagedToUnmanagedRef __handle_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __newHandle_native = (sbyte)(newHandle ? 1 : 0); - __handle_native__marshaller.FromManaged(handle); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __handle_native = __handle_native__marshaller.ToUnmanaged(); - __PInvoke(&__handle_native, __newHandle_native); - } - - __invokeSucceeded = true; - // NotifyForSuccessfulInvoke - Keep alive any managed objects that need to stay alive across the call. - __handle_native__marshaller.OnInvoked(); - // UnmarshalCapture - Capture the native data into marshaller instances in case conversion to managed data throws an exception. - __handle_native__marshaller.FromUnmanaged(__handle_native); - } - finally - { - if (__invokeSucceeded) - { - // GuaranteedUnmarshal - Convert native data to managed data even in the case of an exception during the non-cleanup phases. - handle = __handle_native__marshaller.ToManagedFinally(); - } - -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __handle_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "modify_handle", ExactSpelling = true)] - static extern unsafe void __PInvoke(nint* __handle_native, sbyte __newHandle_native); - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class SetLastError - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SetError(int error, byte shouldSetError) - { - int __lastError; - int __retVal; - { - System.Runtime.InteropServices.Marshal.SetLastSystemError(0); - __retVal = __PInvoke(error, shouldSetError); - __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); - } - - System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error", ExactSpelling = true)] - static extern unsafe int __PInvoke(int __error_native, byte __shouldSetError_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class SetLastError - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SetError_CustomMarshallingSetsError(int error, byte shouldSetError) - { - int __lastError; - int __retVal; - int __retVal_native; - { - System.Runtime.InteropServices.Marshal.SetLastSystemError(0); - __retVal_native = __PInvoke(error, shouldSetError); - __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); - } - - // Unmarshal - Convert native data to managed data. - __retVal = global::LibraryImportGenerator.IntegrationTests.SetLastErrorMarshaller.ConvertToManaged(__retVal_native); - System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error", ExactSpelling = true)] - static extern unsafe int __PInvoke(int __error_native, byte __shouldSetError_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class SetLastError - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string SetError_NonBlittableSignature(int error, bool shouldSetError, string errorString) - { - int __lastError; -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte __shouldSetError_native = default; - string __retVal = default; - ushort* __retVal_native = default; - try - { - // Marshal - Convert managed data to native data. - __shouldSetError_native = (byte)(shouldSetError ? 1 : 0); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __errorString_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(errorString)) - { - System.Runtime.InteropServices.Marshal.SetLastSystemError(0); - __retVal_native = __PInvoke(error, __shouldSetError_native, (ushort*)__errorString_native); - __lastError = System.Runtime.InteropServices.Marshal.GetLastSystemError(); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - System.Runtime.InteropServices.Marshal.SetLastPInvokeError(__lastError); - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "set_error_return_string", ExactSpelling = true)] - static extern unsafe ushort* __PInvoke(int __error_native, byte __shouldSetError_native, ushort* __errorString_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int Sum(global::System.Span values, int numValues) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) - { - __retVal = __PInvoke((int*)__values_native, numValues); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int Sum(global::System.ReadOnlySpan values, int numValues) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native = &global::System.Runtime.InteropServices.Marshalling.ReadOnlySpanMarshaller.ManagedToUnmanagedIn.GetPinnableReference(values)) - { - __retVal = __PInvoke((int*)__values_native, numValues); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array", ExactSpelling = true)] - static extern unsafe int __PInvoke(int* __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int SumInArray(in global::System.Span values, int numValues) - { - int* __values_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn __values_native__marshaller = new(); - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native__marshaller.FromManaged(values, stackalloc int[global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.BufferSize]); - __values_native__marshaller.GetManagedValuesSource().CopyTo(__values_native__marshaller.GetUnmanagedValuesDestination()); - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __values_native__unused = __values_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __values_native = __values_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(&__values_native, numValues); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "sum_int_array_ref", ExactSpelling = true)] - static extern unsafe int __PInvoke(int** __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Duplicate(ref global::System.Span values, int numValues) - { - int* __values_native = default; - // Setup - Perform required setup. - int __values_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __values_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __values_native = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForUnmanagedElements(values, out __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesSource(values).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesDestination(__values_native, __values_native__numElements)); - { - __PInvoke(&__values_native, numValues); - } - - // Unmarshal - Convert native data to managed data. - __values_native__numElements = numValues; - values = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__values_native, __values_native__numElements); - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__values_native, __values_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(values)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __values_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__values_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "duplicate_int_array", ExactSpelling = true)] - static extern unsafe void __PInvoke(int** __values_native, int __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Span CreateRange(int start, int end, out int numValues) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - global::System.Span __retVal = default; - int* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __retVal_native = __PInvoke(start, end, __numValues_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = numValues; - __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array", ExactSpelling = true)] - static extern unsafe int* __PInvoke(int __start_native, int __end_native, int* __numValues_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void CreateRange_Out(int start, int end, out int numValues, out global::System.Span res) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out numValues); - res = default; - int* __res_native = default; - // Setup - Perform required setup. - int __res_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __res_native__numElements); - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (int* __numValues_native = &numValues) - { - __PInvoke(start, end, __numValues_native, &__res_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __res_native__numElements = numValues; - res = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__res_native, __res_native__numElements); - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__res_native, __res_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(res)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __res_native__numElements = numValues; - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__res_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__res_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "create_range_array_out", ExactSpelling = true)] - static extern unsafe void __PInvoke(int __start_native, int __end_native, int* __numValues_native, int** __res_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial global::System.Span GetLongBytes(long l) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::System.Span __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - int __retVal_native__numElements; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __retVal_native__numElements); - try - { - { - __retVal_native = __PInvoke(l); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal_native__numElements = 8; - __retVal = global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.AllocateContainerForManagedElements(__retVal_native, __retVal_native__numElements); - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetUnmanagedValuesSource(__retVal_native, __retVal_native__numElements).CopyTo(global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.GetManagedValuesDestination(__retVal)); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - __retVal_native__numElements = 8; - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "get_long_bytes", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(long __l_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Span - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial bool AndAllMembers(global::System.Span pArray, int length) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native = default; - bool __retVal = default; - byte __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn __pArray_native__marshaller = new(); - int __pArray_native__numElements; - int __pArray_native__lastIndexMarshalled = 0; - System.Runtime.CompilerServices.Unsafe.SkipInit(out __pArray_native__numElements); - try - { - // Marshal - Convert managed data to native data. - __pArray_native__marshaller.FromManaged(pArray, stackalloc global::SharedTypes.BoolStructMarshaller.BoolStructNative[global::System.Runtime.InteropServices.Marshalling.SpanMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - System.ReadOnlySpan __pArray_native__managedSpan = __pArray_native__marshaller.GetManagedValuesSource(); - System.Span __pArray_native__nativeSpan = __pArray_native__marshaller.GetUnmanagedValuesDestination(); - for (int __i0 = 0; __i0 < __pArray_native__managedSpan.Length; ++__i0, ++__pArray_native__lastIndexMarshalled) - { - __pArray_native__nativeSpan[__i0] = global::SharedTypes.BoolStructMarshaller.ConvertToUnmanaged(__pArray_native__managedSpan[__i0]); - } - } - - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __pArray_native__unused = __pArray_native__marshaller) - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __pArray_native = __pArray_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__pArray_native, length); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = __retVal_native != 0; - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - _ = __pArray_native__lastIndexMarshalled; - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - _ = __pArray_native__lastIndexMarshalled; - __pArray_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "and_bool_struct_array", ExactSpelling = true)] - static extern unsafe byte __PInvoke(global::SharedTypes.BoolStructMarshaller.BoolStructNative* __pArray_native, int __length_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - string __retVal = default; - ushort* __retVal_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal_native = __PInvoke((ushort*)__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] - static extern unsafe ushort* __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __PInvoke((ushort*)__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength_IgnoreStringMarshalling(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - string __retVal = default; - ushort* __retVal_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal_native = __PInvoke((ushort*)__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] - static extern unsafe ushort* __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __PInvoke((ushort*)__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPTStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength_IgnoreStringMarshalling(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - string __retVal = default; - ushort* __retVal_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal_native = __PInvoke((ushort*)__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] - static extern unsafe ushort* __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __PInvoke((ushort*)__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPWStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - byte* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength_IgnoreStringMarshalling(string s) - { - byte* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __s_native = default; - string __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __s_native = default; - byte* __ret_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - byte* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPUTF8Str - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - byte* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __s_native = default; - string __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __s_native = default; - byte* __ret_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - byte* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - byte* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength_IgnoreStringMarshalling(string s) - { - byte* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __s_native = default; - string __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(byte* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __s_native = default; - byte* __ret_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__ret_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - byte* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class LPStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - ushort* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_bstr", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength_IgnoreStringMarshalling(string s) - { - ushort* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_bstr", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - ushort* __s_native = default; - string __retVal = default; - ushort* __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_bstr", ExactSpelling = true)] - static extern unsafe ushort* __PInvoke(ushort* __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __s_native = default; - ushort* __ret_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__ret_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_bstr", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_bstr", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - ushort* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_bstr", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class BStr - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.BStrStringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_bstr", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - int __retVal; - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal = __PInvoke((ushort*)__s_native); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_ushort", ExactSpelling = true)] - static extern unsafe int __PInvoke(ushort* __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - string __retVal = default; - ushort* __retVal_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __retVal_native = __PInvoke((ushort*)__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__retVal_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_ushort", ExactSpelling = true)] - static extern unsafe ushort* __PInvoke(ushort* __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - ushort* __ret_native = default; - try - { - // Pin - Pin data in preparation for calling the P/Invoke. - fixed (void* __s_native = &global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.GetPinnableReference(s)) - { - __PInvoke((ushort*)__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__ret_native); - } ->>>>>>> 4637ad2 (Latest chanages) - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort* __s_native, ushort** __ret_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf16 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - ushort* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (ushort*)global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf16StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_ushort", ExactSpelling = true)] - static extern unsafe void __PInvoke(ushort** __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial int ReturnLength(string s) - { - byte* __s_native = default; - int __retVal = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal = __PInvoke(__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "return_length_byte", ExactSpelling = true)] - static extern unsafe int __PInvoke(byte* __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial string Reverse_Return(string s) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - byte* __s_native = default; - string __retVal = default; - byte* __retVal_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __retVal_native = __PInvoke(__s_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - __retVal = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__retVal_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__retVal_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - return __retVal; - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_return_byte", ExactSpelling = true)] - static extern unsafe byte* __PInvoke(byte* __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Out(string s, out string ret) - { -<<<<<<< HEAD -======= - bool __invokeSucceeded = default; ->>>>>>> 4637ad2 (Latest chanages) - System.Runtime.CompilerServices.Unsafe.SkipInit(out ret); - byte* __s_native = default; - byte* __ret_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(__s_native, &__ret_native); - } - -<<<<<<< HEAD -======= - __invokeSucceeded = true; ->>>>>>> 4637ad2 (Latest chanages) - // Unmarshal - Convert native data to managed data. - ret = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__ret_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); -======= - if (__invokeSucceeded) - { - // CleanupCalleeAllocated - Perform cleanup of callee allocated resources. - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__ret_native); - } - - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_out_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte* __s_native, byte** __ret_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_In(in string s) - { - byte* __s_native = default; - // Setup - Perform required setup. - scoped global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn __s_native__marshaller = new(); - try - { - // Marshal - Convert managed data to native data. - __s_native__marshaller.FromManaged(s, stackalloc byte[global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ManagedToUnmanagedIn.BufferSize]); - { - // PinnedMarshal - Convert managed data to native data that requires the managed data to be pinned. - __s_native = __s_native__marshaller.ToUnmanaged(); - __PInvoke(&__s_native); - } - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - __s_native__marshaller.Free(); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_inplace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } - } -} -namespace LibraryImportGenerator.IntegrationTests -{ - unsafe partial class NativeExportsNE - { - public unsafe partial class StringMarshallingCustomType - { - public unsafe partial class Utf8 - { - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.LibraryImportGenerator", "42.42.42.42")] - [global::System.Runtime.CompilerServices.SkipLocalsInitAttribute] - public static partial void Reverse_Replace_Ref(ref string s) - { - byte* __s_native = default; - try - { - // Marshal - Convert managed data to native data. - __s_native = (byte*)global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToUnmanaged(s); - { - __PInvoke(&__s_native); - } - - // Unmarshal - Convert native data to managed data. - s = global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.ConvertToManaged(__s_native); - } - finally - { -<<<<<<< HEAD - // Cleanup - Perform required cleanup. -======= - // CleanupCallerAllocated - Perform cleanup of caller allocated resources. ->>>>>>> 4637ad2 (Latest chanages) - global::System.Runtime.InteropServices.Marshalling.Utf8StringMarshaller.Free(__s_native); - } - - // Local P/Invoke - [System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "reverse_replace_ref_byte", ExactSpelling = true)] - static extern unsafe void __PInvoke(byte** __s_native); - } - } - } - } -}