Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ComInterfaceGenerator] Support PreserveSig on methods #85816

Closed
AaronRobinsonMSFT opened this issue May 5, 2023 · 1 comment · Fixed by #85941
Closed

[ComInterfaceGenerator] Support PreserveSig on methods #85816

AaronRobinsonMSFT opened this issue May 5, 2023 · 1 comment · Fixed by #85941
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Milestone

Comments

@AaronRobinsonMSFT
Copy link
Member

Consider the following API:

[GeneratedComInterface, Guid("B4BE3BD0-3766-4626-B46D-9551B6795CEC")]
public partial interface IEnum
{
    [PreserveSig]
    int Next(uint celt, out uint pceltFetched);
}

The generator attempts to marshal the final out, pceltFetched, instead of returning the HRESULT. It also adds an extra argument? I assume there is some confusion about signature generation when PreserveSig is mentioned.

[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute]
file unsafe partial interface InterfaceImplementation : global::LibraryImportGeneratorSample.IEnum
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
    [System.Runtime.CompilerServices.SkipLocalsInitAttribute]
    int global::LibraryImportGeneratorSample.ICorPublishAppDomainEnum.Next(uint celt, out uint pceltFetched)
    {
        var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::LibraryImportGeneratorSample.IEnum));
        System.Runtime.CompilerServices.Unsafe.SkipInit(out pceltFetched);
        int __retVal;
        int __invokeRetVal;
        // Pin - Pin data in preparation for calling the P/Invoke.
        fixed (uint* __pceltFetched_native = &pceltFetched)
        {
            __invokeRetVal = ((delegate* unmanaged<void*, uint, uint*, int*, int> )__vtable_native[4])(__this, celt, __pceltFetched_native, &__retVal);
        }

        System.GC.KeepAlive(this);
        // Unmarshal - Convert native data to managed data.
        System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal);
        return __retVal;
    }
}
@AaronRobinsonMSFT AaronRobinsonMSFT added area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature labels May 5, 2023
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 8.0.0 milestone May 5, 2023
@ghost
Copy link

ghost commented May 5, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Consider the following API:

[GeneratedComInterface, Guid("B4BE3BD0-3766-4626-B46D-9551B6795CEC")]
public partial interface IEnum
{
    [PreserveSig]
    int Next(uint celt, out uint pceltFetched);
}

The generator attempts to marshal the final out, pceltFetched, instead of returning the HRESULT. It also adds an extra argument? I assume there is some confusion about signature generation when PreserveSig is mentioned.

[System.Runtime.InteropServices.DynamicInterfaceCastableImplementationAttribute]
file unsafe partial interface InterfaceImplementation : global::LibraryImportGeneratorSample.IEnum
{
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Interop.ComInterfaceGenerator", "42.42.42.42")]
    [System.Runtime.CompilerServices.SkipLocalsInitAttribute]
    int global::LibraryImportGeneratorSample.ICorPublishAppDomainEnum.Next(uint celt, out uint pceltFetched)
    {
        var(__this, __vtable_native) = ((System.Runtime.InteropServices.Marshalling.IUnmanagedVirtualMethodTableProvider)this).GetVirtualMethodTableInfoForKey(typeof(global::LibraryImportGeneratorSample.IEnum));
        System.Runtime.CompilerServices.Unsafe.SkipInit(out pceltFetched);
        int __retVal;
        int __invokeRetVal;
        // Pin - Pin data in preparation for calling the P/Invoke.
        fixed (uint* __pceltFetched_native = &pceltFetched)
        {
            __invokeRetVal = ((delegate* unmanaged<void*, uint, uint*, int*, int> )__vtable_native[4])(__this, celt, __pceltFetched_native, &__retVal);
        }

        System.GC.KeepAlive(this);
        // Unmarshal - Convert native data to managed data.
        System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(__invokeRetVal);
        return __retVal;
    }
}
Author: AaronRobinsonMSFT
Assignees: -
Labels:

area-System.Runtime.InteropServices, source-generator

Milestone: 8.0.0

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 8, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label May 10, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant