SharpGenTools / SharpGenTools

Accurate and high performance C++ interop code generator for C#.
https://sharpgentools.readthedocs.io/
MIT License
483 stars 56 forks source link

Remove PointerSize and use nint/nuint #209

Open amerkoleci opened 3 years ago

amerkoleci commented 3 years ago

Hi @andrew-boyarshin , Recent .NET language added nint and nuint support, I would suggest to remove PointerSize and map to those directly, same applies to SharpGen.Runtime.COM.

It is supported in ClangSharp as well: intptr_t -> nint ptrdiff_t -> nint size_t -> nuint uintptr_t -> nuint SIZE_T -> nuint SSIZE_T -> nint

andrew-boyarshin commented 3 years ago

Having PointerSize might theoretically enable us to provide APIs not available on pre-.NET5 runtimes (like IComparable). But yeah, using these is simpler.

amerkoleci commented 3 years ago

Not sure what you mean, nuint maps to UIntPtr and nint maps to IntrPtr, so there is no special magin under the hood.

amerkoleci commented 3 years ago

If you plan to keep PointerSize then we need UPointerSize with ulong and map SIZE_T to that instance. Otherwise we'll end in marshalling issues (https://github.com/amerkoleci/Vortice.Windows/issues/185)

andrew-boyarshin commented 3 years ago

Yeah, I know that nint is a syntax sugar for System.IntPtr and native int. But until .NET 5 (dotnet/runtime#307) IntPtr had a much more narrow API surface, and so does the nint on these older runtimes.