You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FuncPtr interop: support more than 16 arguments #493
Why not use function pointer (delegate* managed <Arg1, Arg2, Arg3, etc, RetType>) instead of System.Delegate?
delegate* <> is a void*.
You can get the pointer via ldftn .
And you can call the pointer via calli . Callsite is a signature like <Arg1, Arg2, etc, RetType> + AdditionalFlags (like cdecl/stdcall or managed callin convention). If non-Managed callconv is selected, dotnet adds anti-exception barriers, but it is slightly slower. You can also call native methods in this way. For callback things and all that.
The maximum number of arguments is many times more than 16.
Since delegate*<> is an intptr, there is no runtime checking of arguments. I.e. you can call Foo(int, int) as Foo(int) or Foo(int,int,int). Hence a funny error. If you call Foo(float) as Foo(int), the latter will not get float because float is passed through Xmm1 registers and int is passed through RCX (on x64, if I remember correctly.
Why not use (function) pointers directly? Because they don't have a constant size, and for the Wide architecture, we need a portable pointer of exactly 8 bytes. Feel free to skim over the corresponding documentation.
Why not use a function pointer as an argument for FuncPtr? Because that's impossible. Pointer types can't be used as generic arguments.
Do we have to use all that stuff at all? No, we do not have. If compiling against native architectures1, Cesium doesn't emit CPtr / VoidPtr / FuncPtr interop, and uses the function pointers directly.
Activity
(#487, #493) Connect TODOs with the issues
BadRyuner commentedon Feb 26, 2024
Why not use function pointer (delegate* managed <Arg1, Arg2, Arg3, etc, RetType>) instead of System.Delegate?
delegate* <> is a void*.
You can get the pointer via ldftn .
And you can call the pointer via calli . Callsite is a signature like <Arg1, Arg2, etc, RetType> + AdditionalFlags (like cdecl/stdcall or managed callin convention). If non-Managed callconv is selected, dotnet adds anti-exception barriers, but it is slightly slower. You can also call native methods in this way. For callback things and all that.
The maximum number of arguments is many times more than 16.
Since delegate*<> is an intptr, there is no runtime checking of arguments. I.e. you can call Foo(int, int) as Foo(int) or Foo(int,int,int). Hence a funny error. If you call Foo(float) as Foo(int), the latter will not get float because float is passed through Xmm1 registers and int is passed through RCX (on x64, if I remember correctly.
ForNeVeR commentedon Feb 26, 2024
I will split your question into several parts.
FuncPtr? Because that's impossible. Pointer types can't be used as generic arguments.CPtr/VoidPtr/FuncPtrinterop, and uses the function pointers directly.Footnotes
Everything except Wide. ↩