-
Notifications
You must be signed in to change notification settings - Fork 5k
[API Proposal]: change 'Unsafe.AsPointer' parameter to be 'ref readonly' #114189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
@tannergooding FYI - marked this one ready for review since it seems to be minor addition to past work. |
namespace System.Runtime.CompilerServices
{
public static class Unsafe
{
- public static void* AsPointer<T>(ref T value);
+ public static void* AsPointer<T>(ref readonly T value);
}
} |
IMO this makes an unsafe api even more unsafe since it implicitly converts an immutable ref to a mutable where previously developer had to state that with AsRef. Should we continue making unsafe code more convenient to write? PS: I'm not against this change, just hoping we won't continue in this direction |
I don't see how it's really any different to allowing |
Right, this was covered in API review a bit. The reason this one is "ok" is because the point of We don't want to do this for things like |
|
Follow up from #85911
Background and motivation
This proposal is about also updating
Unsafe.AsPointer
to useref readonly
. This is the same change we did for the other APIs in #85911, and it is not breaking. We didn't includeAsPointer
at the time as we didn't have any use cases. This would now benefit us in CsWinRT (see #114024), as it would simplify all property accessors to get the CCW vtables for projected and custom mapped types.API Proposal
API Usage
Risks
None.
Unsafe.AsPointer
is already an unsafe API, and it's in an unsafe namespace. This API makes things simpler, but developer could already achieve the same, just by adding anUnsafe.AsRef
call on top of this chain. Just updating the signature forAsPointer
simplifies all callsites instead.The text was updated successfully, but these errors were encountered: