Adding Unsafe.SkipInit#41995
Adding Unsafe.SkipInit#41995tannergooding merged 3 commits intodotnet:masterfrom tannergooding:unsafe-skipinit
Conversation
|
(need to fix to be |
src/System.Runtime.CompilerServices.Unsafe/ref/System.Runtime.CompilerServices.Unsafe.cs
Outdated
Show resolved
Hide resolved
|
Needs test |
| [Fact] | ||
| public static void SkipInit() | ||
| { | ||
| // Validate that calling with primitive types works. |
There was a problem hiding this comment.
I don't think there is a "good way" to validate that Unsafe.SkipInit leaves an "arbitrary" value, so I added these tests which just validate the call doesn't fail and the tests below (f2a593d#diff-401abe3f2532c0a42128029a72a1240dR861) which validate that the previous value (w/e it was set to) is preserved.
| Unsafe.SkipInit(out short shortValue); | ||
| Unsafe.SkipInit(out ushort ushortValue); | ||
| Unsafe.SkipInit(out int intValue); | ||
| Unsafe.SkipInit(out uint uintValue); |
There was a problem hiding this comment.
This is more extensive than it needs to be, but that's ok.
|
@jkotas, do we want/need a similar method in S.P.Corelib ( If so, I can get that up as part of this. |
|
Sounds good. There are a few places where we can use it in CoreLib and replace the current "take the pointer" workarounds. |
* Adding Unsafe.SkipInit * Removing the "where T : struct" constraint from Unsafe.SkipInit * Adding tests for Unsafe.SkipInit Commit migrated from dotnet/corefx@cd97cf5
This resolves https://github.com/dotnet/corefx/issues/38585 by exposing the
Unsafe.SkipInitmethod in System.Runtime.CompilerServices