Skip to content

Commit cd58f5c

Browse files
committed
Shims: adjust the ICU interface
The default ICU build will change the underlying type of the UChar type, with C++ using the builtin `char16_t` rather than `unsigned short`. This adjusts the interface to account for that. I've verified across Apple's implementation that they always use the `unsigned short` as the type for `UChar`. Since we cannot guarantee that the ICU interfaces are built the same way on all targets, especially when using the underlying system's ICU. Adjust the stubs implementation declaration to match the ICU header's declaration.
1 parent 15e8441 commit cd58f5c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

stdlib/public/SwiftShims/UnicodeShims.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,15 @@ typedef enum __swift_stdlib_UBreakIteratorType {
294294
} __swift_stdlib_UBreakIteratorType;
295295

296296
typedef struct __swift_stdlib_UBreakIterator __swift_stdlib_UBreakIterator;
297+
#if defined(__APPLE__)
297298
typedef __swift_uint16_t __swift_stdlib_UChar;
299+
#else
300+
#if defined(__cplusplus)
301+
typedef char16_t __swift_stdlib_UChar;
302+
#else
303+
typedef __swift_uint16_t __swift_stdlib_UChar;
304+
#endif
305+
#endif
298306

299307
SWIFT_RUNTIME_STDLIB_INTERFACE
300308
void __swift_stdlib_ubrk_close(__swift_stdlib_UBreakIterator *bi);

stdlib/public/stubs/UnicodeNormalization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ void swift::__swift_stdlib_ubrk_close(
301301

302302
swift::__swift_stdlib_UBreakIterator *swift::__swift_stdlib_ubrk_open(
303303
swift::__swift_stdlib_UBreakIteratorType type, const char *locale,
304-
const uint16_t *text, int32_t textLength, __swift_stdlib_UErrorCode *status) {
304+
const __swift_stdlib_UChar *text, int32_t textLength,
305+
__swift_stdlib_UErrorCode *status) {
305306
return ptr_cast<swift::__swift_stdlib_UBreakIterator>(
306307
ubrk_open(static_cast<UBreakIteratorType>(type), locale,
307308
reinterpret_cast<const UChar *>(text), textLength,

0 commit comments

Comments
 (0)