From 7463c7665cff55500806040ef6a4822c01efa0d8 Mon Sep 17 00:00:00 2001 From: mjmckp Date: Wed, 4 Oct 2017 20:15:47 +1100 Subject: [PATCH 1/8] Add toByref --- src/fsharp/FSharp.Core/nativeptr.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fsharp/FSharp.Core/nativeptr.fs b/src/fsharp/FSharp.Core/nativeptr.fs index bb70928c47c..30e63ebf5ed 100644 --- a/src/fsharp/FSharp.Core/nativeptr.fs +++ b/src/fsharp/FSharp.Core/nativeptr.fs @@ -49,3 +49,6 @@ module NativePtr = [] let inline stackalloc (count:int) : nativeptr<'T> = (# "localloc" (count * sizeof<'T>) : nativeptr<'T> #) + [] + [] + let inline toByref (address: nativeptr<'T>) : byref<'T> = (# "" address : 'T byref #) From e0ae3bafcf6cb06786c8ced037e9e9e526376e11 Mon Sep 17 00:00:00 2001 From: mjmckp Date: Wed, 4 Oct 2017 20:18:31 +1100 Subject: [PATCH 2/8] Add signature for toByref --- src/fsharp/FSharp.Core/nativeptr.fsi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fsharp/FSharp.Core/nativeptr.fsi b/src/fsharp/FSharp.Core/nativeptr.fsi index 0a5b959ff63..a7059de213b 100644 --- a/src/fsharp/FSharp.Core/nativeptr.fsi +++ b/src/fsharp/FSharp.Core/nativeptr.fsi @@ -81,3 +81,11 @@ namespace Microsoft.FSharp.NativeInterop [] [] val inline stackalloc : count:int -> nativeptr<'T> + + /// Converts a given typed native pointer to a managed pointer. + /// The input pointer. + /// The managed pointer. + [] + [] + [] + val inline toByref : nativeptr<'T> -> byref<'T> From 9acc748aca24accfab0e4f4f81c7cc049091944b Mon Sep 17 00:00:00 2001 From: mjmckp Date: Thu, 5 Oct 2017 09:27:22 +1100 Subject: [PATCH 3/8] toByref -> toByRef --- src/fsharp/FSharp.Core/nativeptr.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsharp/FSharp.Core/nativeptr.fs b/src/fsharp/FSharp.Core/nativeptr.fs index 30e63ebf5ed..29e2ecb67ae 100644 --- a/src/fsharp/FSharp.Core/nativeptr.fs +++ b/src/fsharp/FSharp.Core/nativeptr.fs @@ -50,5 +50,5 @@ module NativePtr = let inline stackalloc (count:int) : nativeptr<'T> = (# "localloc" (count * sizeof<'T>) : nativeptr<'T> #) [] - [] - let inline toByref (address: nativeptr<'T>) : byref<'T> = (# "" address : 'T byref #) + [] + let inline toByRef (address: nativeptr<'T>) : byref<'T> = (# "" address : 'T byref #) From 5e24da00c6b5b0ffcf82558db8039b7363eabb13 Mon Sep 17 00:00:00 2001 From: mjmckp Date: Thu, 5 Oct 2017 09:27:46 +1100 Subject: [PATCH 4/8] toByref -> toByRef --- src/fsharp/FSharp.Core/nativeptr.fsi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsharp/FSharp.Core/nativeptr.fsi b/src/fsharp/FSharp.Core/nativeptr.fsi index a7059de213b..47a0509e71f 100644 --- a/src/fsharp/FSharp.Core/nativeptr.fsi +++ b/src/fsharp/FSharp.Core/nativeptr.fsi @@ -87,5 +87,5 @@ namespace Microsoft.FSharp.NativeInterop /// The managed pointer. [] [] - [] - val inline toByref : nativeptr<'T> -> byref<'T> + [] + val inline toByRef : nativeptr<'T> -> byref<'T> From 8b625ef4fe42cbe9067299d11f3cce7dc60a82cb Mon Sep 17 00:00:00 2001 From: mjmckp Date: Wed, 11 Oct 2017 09:51:40 +1100 Subject: [PATCH 5/8] Add equivalent test for NativePtr.toByref --- .../Core/NativeInterop/stackalloc/ofDateTime01.fs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofDateTime01.fs b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofDateTime01.fs index a58902665f6..19c259bb0c7 100644 --- a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofDateTime01.fs +++ b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofDateTime01.fs @@ -15,4 +15,13 @@ module M3 = if not (NativeInterop.NativePtr.get data i = now) then noerr <- false + let later = now.AddDays 1. + for i = 0 to 99 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + datai <- later + for i = 0 to 99 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + if not (datai = later) then + noerr <- false + (if noerr then 0 else 1) |> exit From 2d6c565660608f067714c32fb611ee9e36bca985 Mon Sep 17 00:00:00 2001 From: mjmckp Date: Wed, 11 Oct 2017 09:56:55 +1100 Subject: [PATCH 6/8] Add corresponding test for NativePtr.toByRef --- .../Libraries/Core/NativeInterop/stackalloc/ofenum01.fs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofenum01.fs b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofenum01.fs index d10b2b70512..885f3b88ac3 100644 --- a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofenum01.fs +++ b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofenum01.fs @@ -19,4 +19,13 @@ module M6 = if not (NativeInterop.NativePtr.get data i = (if (i % 2)=0 then E.A else E.B)) then noerr <- false + for i = 0 to 9 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + datai <- (if (i % 2)=1 then E.A else E.B) + + for i = 0 to 9 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + if not (datai = (if (i % 2)=1 then E.A else E.B)) then + noerr <- false + (if noerr then 0 else 1) |> exit From 6960402ae77cbb17cb21e447fd3e0ed5c1b2ab76 Mon Sep 17 00:00:00 2001 From: mjmckp Date: Wed, 11 Oct 2017 10:01:20 +1100 Subject: [PATCH 7/8] Add corresponding test for NativePtr.toByRef --- .../Libraries/Core/NativeInterop/stackalloc/ofint01.fs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint01.fs b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint01.fs index a882d32448c..e81be3fa1b2 100644 --- a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint01.fs +++ b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint01.fs @@ -16,5 +16,14 @@ module M1 = if not (NativeInterop.NativePtr.get data i = (i*i)) then noerr <- false + for i = 0 to 99 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + datai <- 1-i + + for i = 0 to 99 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + if not (datai = 1-i) then + noerr <- false + (if noerr then 0 else 1) |> exit From 027d189e93076250dd90f3d301983f62e6a31dd7 Mon Sep 17 00:00:00 2001 From: mjmckp Date: Wed, 11 Oct 2017 10:03:34 +1100 Subject: [PATCH 8/8] Add corresponding test for NativePtr.toByRef --- .../Libraries/Core/NativeInterop/stackalloc/ofint6401.fs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint6401.fs b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint6401.fs index 182b80f3e42..401855c5de5 100644 --- a/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint6401.fs +++ b/tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint6401.fs @@ -14,5 +14,14 @@ module M2 = if not (NativeInterop.NativePtr.get data i = (int64 (i*i))) then noerr <- false + for i = 0 to 99 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + datai <- int64 (1-i) + + for i = 0 to 99 do + let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) + if not (datai = int64 (1-i)) then + noerr <- false + (if noerr then 0 else 1) |> exit