-
-
Notifications
You must be signed in to change notification settings - Fork 224
Add native pointer overloads of methods that accept IntPtr #76
Comments
CC: @vbfox |
Yes we need a list of all the pro/cons. On the list of languages :
✅: Can call pointer exposing method Also for the two overloads solutions it's pretty easy to codegen the |
Can you add a legend for these icons above? |
Ok I differentiated between VB that doesn't allow unsafe but can call the Turn out that powershell is able to call an Everything seem to point that the dual pointer/ |
Also if we decide to go the "dual" way it's not really needed for a 0.x release, as we will only add overloads that aren't compatible and don't risk being picked by previously existing code. |
Thanks, @vbfox. I agree: let's go for dual mode. Until we have the code gen going, we should at least offer IntPtr versions so we don't block out use by VB. |
I just found out that unsafe code isn't allowed in C# iterator methods. That means that pointers aren't allowed in them, making it less convenient to call these methods even in a language that would otherwise allow it. |
An open question on resolving some of these is what to do about struct fields that are pointers. Should they be IntPtr or a native pointer type? Can we perhaps use native pointers, but offer properties that expose them as IntPtrs for the VB folks? |
Progress on fixing kernel32 is blocked on AArnott/CodeGeneration.Roslyn#1 |
Well, if we want to be consistent, struct fields should be native pointer types and the codegen should inject property wrappers of those fields. So I am leaning toward native pointer type and properties that expose them as IntPtrs. |
Agreed. |
#130 tracks the struct fields now. |
Bumps [Microsoft.CodeAnalysis.FxCopAnalyzers](https://github.com/dotnet/roslyn-analyzers) from 3.3.0 to 3.3.1. - [Release notes](https://github.com/dotnet/roslyn-analyzers/releases) - [Changelog](https://github.com/dotnet/roslyn-analyzers/blob/master/PostReleaseActivities.md) - [Commits](dotnet/roslyn-analyzers@v3.3.0...v3.3.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
IntPtr parameters are harder to deal with than native pointer types (in C# anyway), and they express less in terms of type safety than pointers can.
We should consider changing our policy and code to use pointers instead of IntPtr.
One possibility is that we maintain two overloads of applicable P/Invoke methods: one that takes IntPtr and one that takes pointers, so that folks can call without using
unsafe
code. I don't have much sympathy for any anxiety over writing unsafe code since it's actually simpler, and partial trust is irrelevant for consumers of this library anyway. So the only reason to keep IntPtr around is for languages that don't support pointers (e.g. Powershell).The text was updated successfully, but these errors were encountered: