Skip to content

Add File.Append/WriteAllText/Bytes{Async} overloads for span/memory - #103308

Merged
stephentoub merged 3 commits into
dotnet:mainfrom
stephentoub:filespanmemory
Jun 14, 2024
Merged

Add File.Append/WriteAllText/Bytes{Async} overloads for span/memory#103308
stephentoub merged 3 commits into
dotnet:mainfrom
stephentoub:filespanmemory

Conversation

@stephentoub

Copy link
Copy Markdown
Member

Closes #99823

@ghost ghost added the area-System.IO label Jun 11, 2024
@ghost

ghost commented Jun 11, 2024

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.
@ghost

ghost commented Jun 11, 2024

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Comment thread src/libraries/System.Private.CoreLib/src/System/IO/File.cs
@jozkee

jozkee commented Jun 13, 2024

Copy link
Copy Markdown
Member

CI error seems related:

Process terminated. Assertion failed.
   at System.IO.RandomAccess.QueueAsyncWriteFile(SafeFileHandle handle, ReadOnlyMemory`1 buffer, Int64 fileOffset, CancellationToken cancellationToken, OSFileStreamStrategy strategy) in /_/src/libraries/System.Private.CoreLib/src/System/IO/RandomAccess.Windows.cs:line 375
   at System.IO.File.<WriteAllBytesAsync>g__Core|103_0(String path, ReadOnlyMemory`1 bytes, CancellationToken cancellationToken) in /_/src/libraries/System.Private.CoreLib/src/System/IO/File.cs:line 1281
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 38
   at System.IO.File.WriteAllBytesAsync(String path, ReadOnlyMemory`1 bytes, CancellationToken cancellationToken) in /_/src/libraries/System.Private.CoreLib/src/System/IO/File.cs:line 1274
   at System.IO.Tests.File_ReadWriteAllBytesAsync.EmptyContentCreatesFileAsync() in /_/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/ReadWriteAllBytesAsync.cs:line 45
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs:line 290
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 179
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs:line 354
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext() in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncTaskMethodBuilderT.cs:line 350
   at Xunit.Sdk.AsyncTestSyncContext.<>c__DisplayClass7_0.<Post>b__0() in /_/src/xunit.execution/Sdk/AsyncTestSyncContext.cs:line 58
   at Xunit.Sdk.XunitWorkerThread.<>c.<QueueUserWorkItem>b__5_0(Object _) in /_/src/common/XunitWorkerThread.cs:line 37
   at System.Threading.Tasks.Task.InnerInvoke() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2402
   at System.Threading.Tasks.Task.<>c.<.cctor>b__292_0(Object obj) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2382
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 179
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:line 2342
   at System.Threading.Tasks.ThreadPoolTaskScheduler.<>c.<.cctor>b__10_0(Object s) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs:line 35
   at System.Threading.Thread.StartCallback() in /_/src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs:line 100
----- end Thu 06/13/2024 22:21:34.45 ----- exit code -2146232797 ----------------------------------------------------------
@stephentoub

Copy link
Copy Markdown
Member Author

CI error seems related

Yes, it looks like it's an existing gap with the existing RandomAccess APIs, when being passed an empty Memory<T>. It ends up pinning and getting back a null pointer, which the assert doesn't like. I'll fix it as part of this.

@stephentoub

Copy link
Copy Markdown
Member Author

/ba-g all test failures are known

@stephentoub
stephentoub merged commit 37d1a8e into dotnet:main Jun 14, 2024
@stephentoub
stephentoub deleted the filespanmemory branch June 14, 2024 22:11
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.