-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add SpanOfCharAsUtf8StringMarshaller and remove ValueUtf8Converter #121870
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
Conversation
…sage Co-authored-by: jkotas <[email protected]>
src/libraries/Common/src/Interop/Unix/System.Native/Interop.Rename.cs
Outdated
Show resolved
Hide resolved
…alueUtf8Converter Co-authored-by: jkotas <[email protected]>
src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: jkotas <[email protected]>
…delete string overloads, and remove ValueUtf8Converter Co-authored-by: jkotas <[email protected]>
Co-authored-by: jkotas <[email protected]>
|
Tagging subscribers to this area: @dotnet/area-system-io |
src/libraries/Common/src/System/Runtime/InteropServices/SpanOfCharAsUtf8StringMarshaller.cs
Outdated
Show resolved
Hide resolved
…CharAsUtf8StringMarshaller.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
|
/ba-g deadletter |
Make sure that the thread-local P/Invoke last error is not getting corrupted by marshalling post-actions.
Fixes #121868