swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.59k stars 10.37k forks source link

[SR-13175] Swift.CWideChar should be an alias to Swift.Unicode.UTF16.CodeUnit #55617

Open dduan opened 4 years ago

dduan commented 4 years ago
Previous ID SR-13175
Radar None
Original Reporter @dduan
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: d3f9433fd64908e9337ff6efbf4f32db

Issue Description:

Today it is defined as an alias to {{Unicode.Scalar}}, which is a container struct for an {{UInt32}}. A better alias for it is {{Unicode.UTF16.CodeUnit}}.

belkadan commented 4 years ago

That's not correct; it's only a UTF-16 code unit on Windows.

grynspan commented 1 year ago

Neither of those types would be the right choice. One would expect CWideChar to map directly to wchar_t, such that a C function using wchar_t is directly interoperable with a Swift function using CWideChar (like how CInt and int are mapped today.)

Changing the definition of this type would most likely lead to binary compatibility problems on ABI-stable platforms (i.e. Darwin) so care would need to be taken. It might make more sense to deprecate CWideChar and replace it with e.g. typealias CWChar = wchar_t or equivalent.

grynspan commented 1 year ago

I'm going to take this issue and use it to conditionally declare CWideChar as a 16-bit type on Windows, since its current declaration is incorrect there. Everywhere else (POSIX-like, at least) has standardized on 32-bit/UCS-4/UTF-32.