Skip to content

[ComInterfaceGenerator] [Out] arrays will free the 'original' elements in unmanaged to managed stubs when marshalling back to native callee #89968

Description

@jtschuster
    internal static int ABI_MethodContentsOut(System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch* __this_native, nint* __param_native, int size)
    {
        global::SharedTypes.ComInterfaces.IArrayOfStatelessElements @this = default;
        global::SharedTypes.ComInterfaces.StatelessType[] param = default;
        int __retVal = default;
        // Setup - Perform required setup.
        int __param_native__numElements;
        System.Runtime.CompilerServices.Unsafe.SkipInit(out __param_native__numElements);
        try
        {
            // Unmarshal - Convert native data to managed data.
            __retVal = 0; // S_OK
            global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<global::SharedTypes.ComInterfaces.StatelessType, nint>.GetManagedValuesDestination(param).Clear();
            @this = System.Runtime.InteropServices.ComWrappers.ComInterfaceDispatch.GetInstance<global::SharedTypes.ComInterfaces.IArrayOfStatelessElements>(__this_native);
            @this.MethodContentsOut(param, size);
            // Marshal - Convert managed data to native data.
            {
                __param_native__numElements = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<global::SharedTypes.ComInterfaces.StatelessType, nint>.GetManagedValuesDestination(param).Length;
                System.Span<nint> __param_native__nativeSpan = System.Runtime.InteropServices.MemoryMarshal.CreateSpan(ref System.Runtime.CompilerServices.Unsafe.AsRef(in global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<global::SharedTypes.ComInterfaces.StatelessType, nint>.GetUnmanagedValuesSource(__param_native, __param_native__numElements).GetPinnableReference()), __param_native__numElements);
                System.Span<global::SharedTypes.ComInterfaces.StatelessType> __param_native__managedSpan = global::System.Runtime.InteropServices.Marshalling.ArrayMarshaller<global::SharedTypes.ComInterfaces.StatelessType, nint>.GetManagedValuesDestination(param);
                for (int __i0 = 0; __i0 < __param_native__numElements; ++__i0)
                {
                    nint __param_native__nativeSpan____i0__original = __param_native__nativeSpan[__i0];
                    __param_native__nativeSpan[__i0] = global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.ConvertToUnmanaged(__param_native__managedSpan[__i0]);
// ISSUE HERE
                    global::SharedTypes.ComInterfaces.StatelessTypeMarshaller.ManagedToUnmanaged.Free(__param_native__nativeSpan____i0__original);
                }
            }
        }
        catch (System.Exception __exception)
        {
            __retVal = System.Runtime.InteropServices.Marshalling.ExceptionAsHResultMarshaller<int>.ConvertToUnmanaged(__exception);
        }

        return __retVal;
    }

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions