From 3bd92627316f9f3174143638ab6e7c3c282de523 Mon Sep 17 00:00:00 2001 From: Ahson Khan Date: Mon, 22 Jan 2018 13:57:11 -0800 Subject: Rename Pin offset to byteOffset and clean up Retain test (#26518) --- src/Common/src/CoreLib/System/Buffers/OwnedMemory.cs | 2 +- src/Common/tests/System/Buffers/NativeOwnedMemory.cs | 6 +++--- src/System.Memory/ref/System.Memory.cs | 2 +- src/System.Memory/tests/Memory/CustomMemoryForTest.cs | 6 +++--- src/System.Memory/tests/Memory/Retain.cs | 8 -------- src/System.Memory/tests/ReadOnlyMemory/Retain.cs | 8 -------- src/System.Runtime/ref/System.Runtime.cs | 2 +- 7 files changed, 9 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/Common/src/CoreLib/System/Buffers/OwnedMemory.cs b/src/Common/src/CoreLib/System/Buffers/OwnedMemory.cs index 6946addc80..0bad1d7777 100644 --- a/src/Common/src/CoreLib/System/Buffers/OwnedMemory.cs +++ b/src/Common/src/CoreLib/System/Buffers/OwnedMemory.cs @@ -43,7 +43,7 @@ namespace System.Buffers /// /// Returns a handle for the array that has been pinned and hence its address can be taken /// - public abstract MemoryHandle Pin(int offset = 0); + public abstract MemoryHandle Pin(int byteOffset = 0); /// /// Returns an array segment. diff --git a/src/Common/tests/System/Buffers/NativeOwnedMemory.cs b/src/Common/tests/System/Buffers/NativeOwnedMemory.cs index f68a70e074..dbe7380e51 100644 --- a/src/Common/tests/System/Buffers/NativeOwnedMemory.cs +++ b/src/Common/tests/System/Buffers/NativeOwnedMemory.cs @@ -53,10 +53,10 @@ namespace System.Buffers public override unsafe Span Span => new Span((void*)_ptr, _length); - public override unsafe MemoryHandle Pin(int offset = 0) + public override unsafe MemoryHandle Pin(int byteOffset = 0) { - if (offset < 0 || offset > _length) throw new ArgumentOutOfRangeException(nameof(offset)); - void* pointer = (void*)((byte*)_ptr + offset); + if (byteOffset < 0 || byteOffset > _length) throw new ArgumentOutOfRangeException(nameof(byteOffset)); + void* pointer = (void*)((byte*)_ptr + byteOffset); return new MemoryHandle(this, pointer); } diff --git a/src/System.Memory/ref/System.Memory.cs b/src/System.Memory/ref/System.Memory.cs index 529d181270..1ad8edb84a 100644 --- a/src/System.Memory/ref/System.Memory.cs +++ b/src/System.Memory/ref/System.Memory.cs @@ -226,7 +226,7 @@ namespace System.Buffers public abstract System.Span Span { get; } public void Dispose() { } protected abstract void Dispose(bool disposing); - public abstract System.Buffers.MemoryHandle Pin(int offset=0); + public abstract System.Buffers.MemoryHandle Pin(int byteOffset=0); public abstract bool Release(); public abstract void Retain(); protected internal abstract bool TryGetArray(out System.ArraySegment arraySegment); diff --git a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs index c8180303ee..d09f4f6642 100644 --- a/src/System.Memory/tests/Memory/CustomMemoryForTest.cs +++ b/src/System.Memory/tests/Memory/CustomMemoryForTest.cs @@ -39,14 +39,14 @@ namespace System.MemoryTests } } - public override MemoryHandle Pin(int offset = 0) + public override MemoryHandle Pin(int byteOffset = 0) { unsafe { Retain(); - if (offset < 0 || offset > _array.Length) throw new ArgumentOutOfRangeException(nameof(offset)); + if (byteOffset < 0 || (byteOffset/Unsafe.SizeOf()) > _array.Length) throw new ArgumentOutOfRangeException(nameof(byteOffset)); var handle = GCHandle.Alloc(_array, GCHandleType.Pinned); - return new MemoryHandle(this, Unsafe.Add((void*)handle.AddrOfPinnedObject(), offset), handle); + return new MemoryHandle(this, Unsafe.Add((void*)handle.AddrOfPinnedObject(), byteOffset), handle); } } diff --git a/src/System.Memory/tests/Memory/Retain.cs b/src/System.Memory/tests/Memory/Retain.cs index 4286685a0d..3a33817dff 100644 --- a/src/System.Memory/tests/Memory/Retain.cs +++ b/src/System.Memory/tests/Memory/Retain.cs @@ -116,14 +116,6 @@ namespace System.MemoryTests Memory memory = new int[0]; MemoryHandle handle = memory.Retain(pin: true); Assert.True(handle.HasPointer); - unsafe - { - int* pointer = (int*)handle.Pointer; - - GC.Collect(); - - Assert.True(pointer != null); - } handle.Dispose(); } diff --git a/src/System.Memory/tests/ReadOnlyMemory/Retain.cs b/src/System.Memory/tests/ReadOnlyMemory/Retain.cs index 386211195a..6f31b00cd0 100644 --- a/src/System.Memory/tests/ReadOnlyMemory/Retain.cs +++ b/src/System.Memory/tests/ReadOnlyMemory/Retain.cs @@ -51,14 +51,6 @@ namespace System.MemoryTests ReadOnlyMemory memory = new int[0]; MemoryHandle handle = memory.Retain(pin: true); Assert.True(handle.HasPointer); - unsafe - { - int* pointer = (int*)handle.Pointer; - - GC.Collect(); - - Assert.True(pointer != null); - } handle.Dispose(); } diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 8bd94ad237..78b33134a4 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -3728,7 +3728,7 @@ namespace System.Buffers public abstract System.Span Span { get; } public void Dispose() { } protected abstract void Dispose(bool disposing); - public abstract MemoryHandle Pin(int offset=0); + public abstract MemoryHandle Pin(int byteOffset=0); public abstract bool Release(); public abstract void Retain(); protected internal abstract bool TryGetArray(out System.ArraySegment arraySegment); -- cgit v1.2.3