Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7228139

Browse files
mjmckpKevinRansom
authored andcommitted
[FS-1044] Add NativePtr.toByRef (dotnet#3691)
* Add toByref* Add signature for toByref* toByref -> toByRef* toByref -> toByRef* Add equivalent test for NativePtr.toByref* Add corresponding test for NativePtr.toByRef* Add corresponding test for NativePtr.toByRef* Add corresponding test for NativePtr.toByRef
1 parent5d5a2d2 commit7228139

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

‎src/fsharp/FSharp.Core/nativeptr.fs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ module NativePtr =
4949
[<CompiledName("StackAllocate")>]
5050
let inlinestackalloc(count:int):nativeptr<'T>=(#"localloc"(count* sizeof<'T>): nativeptr<'T> #)
5151

52+
[<NoDynamicInvocation>]
53+
[<CompiledName("ToByRefInlined")>]
54+
let inlinetoByRef(address:nativeptr<'T>):byref<'T>=(#"" address: 'T byref #)

‎src/fsharp/FSharp.Core/nativeptr.fsi‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,11 @@ namespace Microsoft.FSharp.NativeInterop
8181
[<NoDynamicInvocation>]
8282
[<CompiledName("StackAllocate")>]
8383
val inlinestackalloc:count:int->nativeptr<'T>
84+
85+
/// <summary>Converts a given typed native pointer to a managed pointer.</summary>
86+
/// <param name="address">The input pointer.</param>
87+
/// <returns>The managed pointer.</returns>
88+
[<Unverifiable>]
89+
[<NoDynamicInvocation>]
90+
[<CompiledName("ToByRefInlined")>]
91+
val inlinetoByRef:nativeptr<'T>->byref<'T>

‎tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofDateTime01.fs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,13 @@ module M3 =
1515
ifnot(NativeInterop.NativePtr.get data i= now)then
1616
noerr<-false
1717

18+
letlater= now.AddDays1.
19+
for i=0to99do
20+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
21+
datai<- later
22+
for i=0to99do
23+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
24+
ifnot(datai= later)then
25+
noerr<-false
26+
1827
(if noerrthen0else1)|> exit

‎tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofenum01.fs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ module M6 =
1919
ifnot(NativeInterop.NativePtr.get data i=(if(i%2)=0then E.Aelse E.B))then
2020
noerr<-false
2121

22+
for i=0to9do
23+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
24+
datai<-(if(i%2)=1then E.Aelse E.B)
25+
26+
for i=0to9do
27+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
28+
ifnot(datai=(if(i%2)=1then E.Aelse E.B))then
29+
noerr<-false
30+
2231
(if noerrthen0else1)|> exit

‎tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint01.fs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,14 @@ module M1 =
1616
ifnot(NativeInterop.NativePtr.get data i=(i*i))then
1717
noerr<-false
1818

19+
for i=0to99do
20+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
21+
datai<-1-i
22+
23+
for i=0to99do
24+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
25+
ifnot(datai=1-i)then
26+
noerr<-false
27+
1928
(if noerrthen0else1)|> exit
2029

‎tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint6401.fs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,14 @@ module M2 =
1414
ifnot(NativeInterop.NativePtr.get data i=(int64(i*i)))then
1515
noerr<-false
1616

17+
for i=0to99do
18+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
19+
datai<- int64(1-i)
20+
21+
for i=0to99do
22+
letdatai= NativeInterop.NativePtr.toByRef(NativeInterop.NativePtr.add data i)
23+
ifnot(datai= int64(1-i))then
24+
noerr<-false
25+
1726
(if noerrthen0else1)|> exit
1827

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp