jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.77k stars 630 forks source link

`MethodCallingConvention` lacks entry for "default unmanaged calling convention" #842

Closed Zastai closed 2 years ago

Zastai commented 2 years ago

When using a function pointer in C#, the following syntax is available, with corresponding calling convention values:

  delegate* managed<type, ..., return-type> // same as leaving off the "managed"; value = 0
  delegate* unmanaged<type, ..., return-type> // means "use the default unmanaged calling convention for the platform; value 9
  delegate* unmanaged[Cdecl]<type, ..., return-type> // cdecl; value 1
  delegate* unmanaged[Fastcall]<type, ..., return-type> // cdecl; value 4
  delegate* unmanaged[Stdcall]<type, ..., return-type> // cdecl; value 2
  delegate* unmanaged[Thiscall]<type, ..., return-type> // cdecl; value 3
  delegate* unmanaged[xxx, yyy, ...]<type, ..., return-type> // also uses 9, and adds modopts to the return type for the listed conventions

So the "unmanaged without explicit calling convention" case currently does not have a name in the enum yet.

Suggested name: DefaultUnmanaged (I'd prefer Default with the current Default becoming Managed, because all values other than 0 imply unmanaged calls, but that's an API break).

(I can't find anything that suggests the enum values VarArg and Generic are usable in C# (perhaps they are a Mono-only thing?).)

Zastai commented 2 years ago

Ah I see here that default is used in CallKind for the "managed" case, so that's fine. And it also lists varargs as specifically unsupported by C#.

So the entry needed is for what is called unmanaged ext in that section. Unmanaged or DefaultUnmanaged seem like decent choices then.

Zastai commented 2 years ago

Oh, looks like the canonical name is Unmanaged: https://github.com/dotnet/runtime/issues/38133

Zastai commented 2 years ago

Wish MS was better at documenting things properly in one place once a language proposal is accepted.