Skip to content

[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

Merged
merged 4 commits into from
Jan 22, 2022

Conversation

compnerd
Copy link
Member

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)

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

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)
@compnerd compnerd requested a review from a team as a code owner January 20, 2022 18:03
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

CC: @shahmishal @mikeash

@shahmishal
Copy link
Member

@compnerd

Unexpectedly Passed Tests (1):
  Swift(windows-x86_64) :: Concurrency/Runtime/async_taskgroup_throw_rethrow.swift

We need to re-enable this test?

@compnerd
Copy link
Member Author

compnerd commented Jan 20, 2022

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
@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

Ah, yeah, seems that the other tests are similarly now passing.

@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd compnerd changed the title stdlib: change the console to UTF-8 on start [5.5] stdlib: change the console to UTF-8 on start Jan 22, 2022
@shahmishal shahmishal merged commit 8e8b9a1 into swiftlang:release/5.5 Jan 22, 2022
@compnerd compnerd deleted the 5.5.3-unicode branch January 22, 2022 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants