-
Notifications
You must be signed in to change notification settings - Fork 153
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
Add support for varargs. #344
Conversation
if (cursor is FunctionDecl functionDecl) | ||
{ | ||
if (functionDecl.IsVariadic) | ||
{ | ||
return CallingConvention.Cdecl; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to support remapping still. The default should definitely be Cdecl
, but ClangSharp supports users doing any kind of remapping, even ones that technically may not make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The document of __stdcall
indicates that even the vararg function is marked as __stdcall
, the compiler makes it a __cdecl
. Therefore I force Cdecl
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but that's not necessarily true for any and all potential platforms. ClangSharp has reasonable defaults and allows devs to override the default to fit their own needs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are generating proper dll imports. If a programmer writes a method like
extern "C" int __stdcall foo(...);
The compiler won't raise errors. However, if we generate bindings like
[DllImport("foo.dll", CallingConvention = CallingConvention.StdCall)]
static extern int foo(__arglist);
The program will raise runtime System.TypeLoadException
says that varargs function should use cdecl.
...Sharp.PInvokeGenerator.UnitTests/CSharpCompatibleWindows/FunctionDeclarationDllImportTest.cs
Outdated
Show resolved
Hide resolved
Sorry for the delay in reviewing this. It generally looks correct to me but has a couple fixups that would be good to include. There should ideally be some handling for a variadic function pointer as well. C# doesn't support them, but ClangSharp still needs to generate something (likely just a diagnostic indicating it couldn't be handled and falling back to |
When the param name is empty. Actually the only possible case is when type is __arglist.
According to microsoft/win32metadata#917 and microsoft/win32metadata#33 , the win32 metadata doesn't recognize the varargs declarations, which gives much inconvenience. This PR adds simple dll-import support for varargs, and generate C# code with undocumented keyword
__arglist
.