Repository navigation
Add SpanOfCharAsUtf8StringMarshaller and remove ValueUtf8Converter - #121870
Merged
Merged
Conversation
…sage Co-authored-by: jkotas <[email protected]>
jkotas
reviewed
Nov 21, 2025
jkotas
reviewed
Nov 21, 2025
jkotas
reviewed
Nov 21, 2025
…alueUtf8Converter Co-authored-by: jkotas <[email protected]>
jkotas
reviewed
Nov 21, 2025
Co-authored-by: jkotas <[email protected]>
Copilot
AI
changed the title
[WIP] Add Utf8SpanOfCharMarshaller implementation
Add SpanOfCharAsUtf8StringMarshaller for ReadOnlySpan<char> UTF-8 marshalling
Nov 21, 2025
jkotas
reviewed
Nov 21, 2025
…delete string overloads, and remove ValueUtf8Converter Co-authored-by: jkotas <[email protected]>
Copilot
AI
changed the title
Add SpanOfCharAsUtf8StringMarshaller for ReadOnlySpan<char> UTF-8 marshalling
Add SpanOfCharAsUtf8StringMarshaller and remove ValueUtf8Converter
Nov 21, 2025
Co-authored-by: jkotas <[email protected]>
jkotas
reviewed
Nov 21, 2025
jkotas
reviewed
Nov 21, 2025
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
jkotas
reviewed
Nov 21, 2025
…CharAsUtf8StringMarshaller.cs
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the manual ValueUtf8Converter helper with a proper custom marshaller SpanOfCharAsUtf8StringMarshaller to fix thread-local P/Invoke last error corruption. The issue occurred because the old pattern called dispose/cleanup operations before capturing the last error from P/Invoke calls, potentially overwriting error codes.
Key changes:
- Introduces
SpanOfCharAsUtf8StringMarshalleras a declarative marshaller forReadOnlySpan<char>to UTF-8 strings - Removes manual UTF-8 conversion code from Interop methods using
[MarshalUsing]attribute - Fixes operation ordering in
FileSystem.Unix.csto capture last error before cleanup
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/Common/src/System/Runtime/InteropServices/SpanOfCharAsUtf8StringMarshaller.cs | New custom marshaller implementation following the standard pattern, with proper memory management and null termination |
| src/libraries/Common/src/System/Text/ValueUtf8Converter.cs | Removed obsolete manual UTF-8 conversion helper |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.Stat.Span.cs | Simplified to use declarative marshalling instead of manual conversion |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.Rename.cs | Simplified to use declarative marshalling instead of manual conversion |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.ReadLink.cs | Simplified to use declarative marshalling instead of manual conversion |
| src/libraries/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs | Simplified to use declarative marshalling instead of manual conversion |
| src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs | Fixed operation order: GetLastError() now called before Dispose() to prevent error corruption; ValueStringBuilder now uses stack allocation |
| src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems | Updated reference from ValueUtf8Converter to SpanOfCharAsUtf8StringMarshaller |
| src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj | Updated reference from ValueUtf8Converter to SpanOfCharAsUtf8StringMarshaller |
| src/libraries/System.Net.Ping/src/System.Net.Ping.csproj | Updated reference from ValueUtf8Converter to SpanOfCharAsUtf8StringMarshaller |
| src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj | Updated reference from ValueUtf8Converter to SpanOfCharAsUtf8StringMarshaller |
| src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj | Updated reference from ValueUtf8Converter to SpanOfCharAsUtf8StringMarshaller |
| src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj | Updated reference from ValueUtf8Converter to SpanOfCharAsUtf8StringMarshaller |
AaronRobinsonMSFT
approved these changes
Nov 21, 2025
Member
|
/ba-g deadletter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make sure that the thread-local P/Invoke last error is not getting corrupted by marshalling post-actions.
Fixes #121868