Skip to content

stdlib: map wchar_t to UInt16 on Windows #69105

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 1 commit into from
Oct 27, 2023

Conversation

compnerd
Copy link
Member

This is an ABI breaking change for Windows. WCHAR on Windows is mapped to short (-fshort-wchar makes it unsigned short). When C++ interop is enabled, WCHAR will be mapped to wchar_t which is then mapped to short (or unsigned short if -fshort-wchar is specified). Correct the mapping type to get the desired behaviour.

This is an ABI breaking change for Windows.  `WCHAR` on Windows is
mapped to `short` (`-fshort-wchar` makes it `unsigned short`).  When C++
interop is enabled, `WCHAR` will be mapped to `wchar_t` which is then
mapped to `short` (or `unsigned short` if `-fshort-wchar` is specified).
Correct the mapping type to get the desired behaviour.
@compnerd compnerd requested a review from a team as a code owner October 10, 2023 22:12
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@stephentyrone
Copy link
Contributor

@compnerd is this already on main?

@compnerd
Copy link
Member Author

@stephentyrone yeap!

@stephentyrone
Copy link
Contributor

Can you link to the PR against main here, please?

@compnerd
Copy link
Member Author

@stephentyrone #68397

@compnerd
Copy link
Member Author

This is dependent on #69328

@compnerd
Copy link
Member Author

Explanation: Adjust the mapping for CWideChar for Windows. Windows uses UTF-16 for unicode string representation, not UTF-32. This corrects the mapping which fixes a number of issues with Windows API calls.
Scope: This is an ABI breaking change on Windows, the other platforms are not impacted by the change as they use UTF-32.
Issue:
Risk: This would require testing for Windows to ensure that the tests do not regress.
Testing: Validated that we can now import functions that use wchar_t on Windows with C++ interop, ran through the unit tests. This change has been on main for a while now as well and has been tested with larger code bases.
Reviewer: @DougGregor

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! This is something we should probably note in the ChangeLog, since it's going to have an impact on Windows users

@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@compnerd compnerd merged commit 0ba5de9 into swiftlang:release/5.10 Oct 27, 2023
@compnerd compnerd deleted the wchar branch October 27, 2023 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants