Skip to content

Revert SafeBuffer change around pointer initialization #63289

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

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public void AcquirePointer(ref byte* pointer)
if (_numBytes == Uninitialized)
throw NotInitialized();

pointer = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add pragma warning around this with reference to the issue?

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'm not a big fan of adding suppression for things we don't have enabled. We'd have an absolute ton of such suppression across SPC and the rest of the repo if we did that.


bool junk = false;
DangerousAddRef(ref junk);
pointer = (byte*)handle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ public unsafe void AcquirePointer_NotInitialized_ThrowsInvalidOperationException
Assert.Throws<InvalidOperationException>(() => wrapper.AcquirePointer(ref pointer));
}

[Fact]
public unsafe void AcquirePointer_Disposed_ThrowsObjectDisposedException()
{
var buffer = new SubBuffer(true);
buffer.Initialize(4);
buffer.Dispose();

byte* pointer = (byte*)12345;
Assert.Throws<ObjectDisposedException>(() => buffer.AcquirePointer(ref pointer));
Assert.True(pointer is null);
}

[Fact]
public void ReleasePointer_NotInitialized_ThrowsInvalidOperationException()
{
Expand Down