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

PInvokeGenerator ignores calling convention attribute on function pointer #237

Closed
DCNick3 opened this issue Jun 6, 2021 · 0 comments · Fixed by #257
Closed

PInvokeGenerator ignores calling convention attribute on function pointer #237

DCNick3 opened this issue Jun 6, 2021 · 0 comments · Fixed by #257

Comments

@DCNick3
Copy link

DCNick3 commented Jun 6, 2021

Repro:
test.cpp:

struct test {
    void (__stdcall* test_cb)(void);
};

Command line (on arch linux): dotnet run -r ubuntu.18.04-x64 -f net5.0 -- -a -target i386-pc-win32 -n test -f test.cpp -o test.cs

Produced output:

namespace test
{
    public unsafe partial struct test
    {
        [NativeTypeName("void (*)() __attribute__((stdcall))")]
        public delegate* unmanaged[Cdecl]<void> test_cb;
    }
}

Expected output:

namespace test
{
    public unsafe partial struct test
    {
        [NativeTypeName("void (*)() __attribute__((stdcall))")]
        public delegate* unmanaged[Stdcall]<void> test_cb;
    }
}

(Notice the ignored calling convention)

I found a codepath where this information was discarded:

https://github.com/microsoft/ClangSharp/blob/73da2e7a8f75a2b789620b0882a55dd66b6ee05c/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs#L1625-L1628

This clause unwraps AttributedType and calls the same function for attributedType.ModifiedType.

attributedType.Handle.FunctionTypeCallingConv is CXCallingConv_X86StdCall, but ModifiedType does not have this information and attributedType.ModifiedType.Handle.FunctionTypeCallingConv is CXCallingConv_C

win32metadata evades this by having Winapi as a default calling convention (--with-callconv *=Winapi) and seemingly all callbacks using this calling convention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant