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

Fixing Retain to return MemoryHandle with correct PinnedPointer #14248

Merged
merged 2 commits into from
Sep 29, 2017
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
12 changes: 12 additions & 0 deletions src/mscorlib/shared/System/Buffers/MemoryHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ public unsafe struct MemoryHandle : IDisposable
_handle = handle;
}

internal void AddOffset(int offset)
{
if (_pointer == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pointer);
}
else
{
_pointer = (void*)((byte*)_pointer + offset);
}
}

[CLSCompliant(false)]
public void* PinnedPointer => _pointer;

Expand Down
1 change: 1 addition & 0 deletions src/mscorlib/shared/System/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public unsafe MemoryHandle Retain(bool pin = false)
if (_index < 0)
{
memoryHandle = ((OwnedMemory<T>)_arrayOrOwnedMemory).Pin();
memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/mscorlib/shared/System/ReadOnlyMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public unsafe MemoryHandle Retain(bool pin = false)
if (_index < 0)
{
memoryHandle = ((OwnedMemory<T>)_arrayOrOwnedMemory).Pin();
memoryHandle.AddOffset((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>());
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/mscorlib/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ internal enum ExceptionArgument
s,
keyValuePair,
input,
ownedMemory
ownedMemory,
pointer
}

//
Expand Down