Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jun 14, 2024

Conversation

stephentoub
Copy link
Member

Closes #99823

Copy link

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.

Copy link

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.

Copy link
Contributor

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

@jozkee
Copy link
Member

jozkee commented Jun 13, 2024

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
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
Member Author

/ba-g all test failures are known

@stephentoub stephentoub merged commit 37d1a8e into dotnet:main Jun 14, 2024
140 of 146 checks passed
@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add File.WriteAllBytes taking ReadOnlySpan<byte>
2 participants