-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.5] stdlib: change the console to UTF-8 on start #40929
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
This adjusts the Windows console to switch the codepage to UTF-8. This is important as the default codepage (CP437) does not allow for UTF-8 output, but expects ASCII. However, strings in Swift are assumed to be UTF-8, which means that there is now a conversion mismatch. Because the console mode persists beyond the duration of the application as it is state local to the console and not the C runtime, we should restore the state of the console before termination. We do this by registering a termination handler via `atexit`. This means that an abnormal termination (e.g. via `fatalError`) will irrevocably alter the state of the console (interestingly enough, `chcp` will still report the original console codepage even though the console will internally be set to UTF-8). Fixes: SR-13807 (cherry picked from commit 9847cab)
@swift-ci please test |
CC: @shahmishal @mikeash |
We need to re-enable this test? |
Hmm, that is intriguing ... it is enabled on main. I just am not sure what it picked up to now pass on 5.5. It might be the LLVM fix? Afterall, the 5.5.2 and 5.5.3 changes are to fix the concurrency runtime issues. |
Enable the test that was previously failing on 5.5. This has been stable on main for a while, and seems to also be now passing on 5.5
@swift-ci please test Windows platform |
Ah, yeah, seems that the other tests are similarly now passing. |
@swift-ci please test Windows platform |
@swift-ci please test |
This adjusts the Windows console to switch the codepage to UTF-8. This
is important as the default codepage (CP437) does not allow for UTF-8
output, but expects ASCII. However, strings in Swift are assumed to be
UTF-8, which means that there is now a conversion mismatch.
Because the console mode persists beyond the duration of the application
as it is state local to the console and not the C runtime, we should
restore the state of the console before termination. We do this by
registering a termination handler via
atexit
. This means that anabnormal termination (e.g. via
fatalError
) will irrevocably alter thestate of the console (interestingly enough,
chcp
will still report theoriginal console codepage even though the console will internally be set
to UTF-8).
Fixes: SR-13807
(cherry picked from commit 9847cab)
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.