Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Adding Unsafe.SkipInit#41995

Merged
tannergooding merged 3 commits intodotnet:masterfrom
tannergooding:unsafe-skipinit
Oct 22, 2019
Merged

Adding Unsafe.SkipInit#41995
tannergooding merged 3 commits intodotnet:masterfrom
tannergooding:unsafe-skipinit

Conversation

@tannergooding
Copy link
Member

This resolves https://github.com/dotnet/corefx/issues/38585 by exposing the Unsafe.SkipInit method in System.Runtime.CompilerServices

@tannergooding
Copy link
Member Author

(need to fix to be unmanaged one second...)

@jkotas
Copy link
Member

jkotas commented Oct 22, 2019

Needs test

[Fact]
public static void SkipInit()
{
// Validate that calling with primitive types works.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more extensive than it needs to be, but that's ok.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@tannergooding
Copy link
Member Author

tannergooding commented Oct 22, 2019

@jkotas, do we want/need a similar method in S.P.Corelib (Internal.Runtime.CompilerServices.Unsafe)?

If so, I can get that up as part of this.

@jkotas
Copy link
Member

jkotas commented Oct 22, 2019

Sounds good. There are a few places where we can use it in CoreLib and replace the current "take the pointer" workarounds.

ltrzesniewski added a commit to ltrzesniewski/InlineIL.Fody that referenced this pull request Oct 22, 2019
@tannergooding tannergooding merged commit cd97cf5 into dotnet:master Oct 22, 2019
@karelz karelz added this to the 5.0 milestone Dec 19, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Adding Unsafe.SkipInit

* Removing the "where T : struct" constraint from Unsafe.SkipInit

* Adding tests for Unsafe.SkipInit


Commit migrated from dotnet/corefx@cd97cf5
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants