Closed mikasoukhov closed 3 years ago
I will advise try to use MarshalAs attribute to specify what the underlying type (short, int) should be as a boolean.
@mikasoukhov That would break the intent of DNNE. The project is designed around authoring native callable exports with zero overhead. If support for MarshalAs
was added, then the export wouldn't be possible since the runtime would need to generate an IL Stub - the same as when doing a P/Invoke. Further discussion about this consideration can be found here.
There is an argument to be made that one could integrate with the upcoming DllImportAttribute
source generator in the future which would then complete this story. Unfortunately that is a way off from being consumable in any project.
The attribute can show code generator how to generate C code. Without this option I cannot imagine how to make any instructions for Bool Char etc. Sure there is workaround with short or other underlying types. But it will make C# code dirty and understandable. Think guys whom created the attribute already investigated this issue not one time. No reason reinvented the wheel.
Supporting non-blittable types is a non-goal for DNNE. It is intentionally designed to permit users the lowest overhead for native exports.
For an export function like
int Func1(bool value)
will be an error during compilation. For resolve (and support) I will advise try to use MarshalAs attribute to specify what the underlying type (short, int) should be as a boolean.