Skip to content

Commit 778dde9

Browse files
Merge pull request #4902 from kateinoigakukun/pr-46e15f9f0db9d9dafc392e43e83bc999af200c47
[wasm] Port CoreFoundation/String.subproj
2 parents 087a706 + e0c821f commit 778dde9

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ CF_INLINE size_t malloc_size(void *memblock) {
340340
#endif
341341
#endif
342342

343-
#if TARGET_OS_LINUX || TARGET_OS_BSD
343+
#if TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
344344
#include <sys/param.h>
345345
#endif
346346
#if TARGET_OS_WIN32 || TARGET_OS_LINUX

CoreFoundation/String.subproj/CFCharacterSetData.S

+11
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@
1111

1212
#if defined(__ELF__)
1313
.section .rodata
14+
#elif defined(__wasm__)
15+
.section .data.characterset_bitmap_data,"",@
1416
#endif
1517

1618
.global _C_LABEL(__CFCharacterSetBitmapData)
1719
_C_LABEL(__CFCharacterSetBitmapData):
1820
.incbin CF_CHARACTERSET_BITMAP
21+
#if defined(__wasm__)
22+
.size _C_LABEL(__CFCharacterSetBitmapData), . - _C_LABEL(__CFCharacterSetBitmapData)
23+
#endif
1924

2025
.global _C_LABEL(__CFCharacterSetBitmapDataEnd)
2126
_C_LABEL(__CFCharacterSetBitmapDataEnd):
2227
.byte 0
28+
#if defined(__wasm__)
29+
.size _C_LABEL(__CFCharacterSetBitmapDataEnd), . - _C_LABEL(__CFCharacterSetBitmapDataEnd)
30+
#endif
2331

2432
.global _C_LABEL(__CFCharacterSetBitmapDataSize)
2533
_C_LABEL(__CFCharacterSetBitmapDataSize):
2634
.int _C_LABEL(__CFCharacterSetBitmapDataEnd) - _C_LABEL(__CFCharacterSetBitmapData)
35+
#if defined(__wasm__)
36+
.size _C_LABEL(__CFCharacterSetBitmapDataSize), . - _C_LABEL(__CFCharacterSetBitmapDataSize)
37+
#endif
2738

2839
NO_EXEC_STACK_DIRECTIVE
2940
SAFESEH_REGISTRATION_DIRECTIVE

CoreFoundation/String.subproj/CFString.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
3939
#include <unistd.h>
4040
#endif
41+
#if TARGET_OS_WASI
42+
#include <sys/types.h> // for u_char
43+
#endif
4144

4245
#if defined(__GNUC__)
4346
#define LONG_DOUBLE_SUPPORT 1
@@ -6276,7 +6279,7 @@ enum {
62766279
CFFormatIncompleteSpecifierType = 43 /* special case for a trailing incomplete specifier */
62776280
};
62786281

6279-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
6282+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
62806283
/* Only come in here if spec->type is CFFormatLongType or CFFormatDoubleType. Pass in 0 for width or precision if not specified. Returns false if couldn't do the format (with the assumption the caller falls back to unlocalized).
62816284
*/
62826285
static Boolean __CFStringFormatLocalizedNumber(CFMutableStringRef output, CFLocaleRef locale, const CFPrintValue *values, const CFFormatSpec *spec, SInt32 width, SInt32 precision, Boolean hasPrecision) {
@@ -7493,7 +7496,7 @@ static Boolean __CFStringAppendFormatCore(CFMutableStringRef outputString, CFStr
74937496
switch (specs[curSpec].type) {
74947497
case CFFormatLongType:
74957498
case CFFormatDoubleType:
7496-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
7499+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
74977500
if (localizedFormatting && (specs[curSpec].flags & kCFStringFormatLocalizable)) { // We have a locale, so we do localized formatting
74987501
oldLength = __CFStringFormatOutputLengthIfNeeded();
74997502
if (__CFStringFormatLocalizedNumber(outputString, (CFLocaleRef)formatOptions, values, &specs[curSpec], width, precision, hasPrecision)) {

CoreFoundation/String.subproj/CFStringUtilities.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "CFString_Internal.h"
1919
#include <limits.h>
2020
#include <stdlib.h>
21-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
21+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
2222
#include <unicode/ucol.h>
2323
#include <unicode/ucoleitr.h>
2424
#endif
@@ -111,7 +111,7 @@ CFStringEncoding CFStringConvertIANACharSetNameToEncoding(CFStringRef charsetNam
111111

112112
encoding = __CFStringEncodingGetFromCanonicalName(name);
113113

114-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
114+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
115115
if (kCFStringEncodingInvalidId == encoding) encoding = __CFStringEncodingGetFromICUName(name);
116116
#endif
117117

@@ -262,7 +262,7 @@ CFStringEncoding CFStringGetMostCompatibleMacStringEncoding(CFStringEncoding enc
262262

263263
#define kCFStringCompareAllocationIncrement (128)
264264

265-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
265+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
266266

267267
// -------------------------------------------------------------------------------------------------
268268
// CompareSpecials - ignore case & diacritic differences
@@ -425,7 +425,7 @@ static UCollator *__CFStringCopyDefaultCollator(CFLocaleRef compareLocale) {
425425
return collator;
426426
}
427427

428-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
428+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
429429
static void __collatorFinalize(UCollator *collator) {
430430
CFLocaleRef locale = _CFGetTSD(__CFTSDKeyCollatorLocale);
431431
_CFSetTSD(__CFTSDKeyCollatorUCollator, NULL, NULL);
@@ -578,7 +578,7 @@ CF_PRIVATE CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *
578578
CFRange range1 = str1Range;
579579
CFRange range2 = str2Range;
580580
SInt32 order;
581-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
581+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
582582
Boolean isEqual;
583583
bool forcedOrdering = ((options & kCFCompareForcedOrdering) ? true : false);
584584

@@ -611,7 +611,7 @@ CF_PRIVATE CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *
611611
range2.location = __extendLocationBackward(range2.location - 1, str2, nonBaseBMP, punctBMP);
612612
}
613613

614-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
614+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
615615
// First we try to use the last one used on this thread, if the locale is the same,
616616
// otherwise we try to check out a default one, or then we create one.
617617
UCollator *threadCollator = _CFGetTSD(__CFTSDKeyCollatorUCollator);
@@ -633,7 +633,7 @@ CF_PRIVATE CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *
633633
range1.length = (str1Range.location + str1Range.length) - range1.location;
634634
range2.length = (str2Range.location + str2Range.length) - range2.location;
635635

636-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
636+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
637637
if ((NULL != collator) && (__CompareTextDefault(collator, options, characters1, range1.length, characters2, range2.length, &isEqual, &order) == 0 /* noErr */)) {
638638
compResult = ((isEqual && !forcedOrdering) ? kCFCompareEqualTo : ((order < 0) ? kCFCompareLessThan : kCFCompareGreaterThan));
639639
} else
@@ -709,7 +709,7 @@ CF_PRIVATE CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *
709709
}
710710
}
711711

712-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
712+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
713713
if ((NULL != collator) && (__CompareTextDefault(collator, options, characters1, range1.length, characters2, range2.length, &isEqual, &order) == 0 /* noErr */)) {
714714
if (isEqual) {
715715
if (forcedOrdering && (kCFCompareEqualTo == compResult) && (0 != order)) compResult = ((order < 0) ? kCFCompareLessThan : kCFCompareGreaterThan);
@@ -753,7 +753,7 @@ CF_PRIVATE CFComparisonResult _CFCompareStringsWithLocale(CFStringInlineBuffer *
753753
if (buffer2Len > 0) CFAllocatorDeallocate(kCFAllocatorSystemDefault, buffer2);
754754
}
755755

756-
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX
756+
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_LINUX || TARGET_OS_WASI
757757
if (collator == threadCollator) {
758758
// do nothing, already cached
759759
} else {

CoreFoundation/String.subproj/CFUniCharPropertyDatabase.S

+11
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,30 @@
1111

1212
#if defined(__ELF__)
1313
.section .rodata
14+
#elif defined(__wasm__)
15+
.section .data.unichar_property_database,"",@
1416
#endif
1517

1618
.global _C_LABEL(__CFUniCharPropertyDatabase)
1719
_C_LABEL(__CFUniCharPropertyDatabase):
1820
.incbin CF_CHARACTERSET_UNICHAR_DB
21+
#if defined(__wasm__)
22+
.size _C_LABEL(__CFUniCharPropertyDatabase), . - _C_LABEL(__CFUniCharPropertyDatabase)
23+
#endif
1924

2025
.global _C_LABEL(__CFUniCharPropertyDatabaseEnd)
2126
_C_LABEL(__CFUniCharPropertyDatabaseEnd):
2227
.byte 0
28+
#if defined(__wasm__)
29+
.size _C_LABEL(__CFUniCharPropertyDatabaseEnd), . - _C_LABEL(__CFUniCharPropertyDatabaseEnd)
30+
#endif
2331

2432
.global _C_LABEL(__CFUniCharPropertyDatabaseSize)
2533
_C_LABEL(__CFUniCharPropertyDatabaseSize):
2634
.int _C_LABEL(__CFUniCharPropertyDatabaseEnd) - _C_LABEL(__CFUniCharPropertyDatabase)
35+
#if defined(__wasm__)
36+
.size _C_LABEL(__CFUniCharPropertyDatabaseSize), . - _C_LABEL(__CFUniCharPropertyDatabaseSize)
37+
#endif
2738

2839
NO_EXEC_STACK_DIRECTIVE
2940
SAFESEH_REGISTRATION_DIRECTIVE

CoreFoundation/String.subproj/CFUnicodeData.S

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#if defined(__ELF__)
1313
.section .rodata
14+
#elif defined(__wasm__)
15+
.section .data.unicode_data,"",@
1416
#endif
1517

1618
#if defined(__BIG_ENDIAN__)
@@ -29,14 +31,23 @@ _C_LABEL(__CFUnicodeDataBSize):
2931
.global _C_LABEL(__CFUnicodeDataL)
3032
_C_LABEL(__CFUnicodeDataL):
3133
.incbin CF_CHARACTERSET_UNICODE_DATA_L
34+
#if defined(__wasm__)
35+
.size _C_LABEL(__CFUnicodeDataL), . - _C_LABEL(__CFUnicodeDataL)
36+
#endif
3237

3338
.global _C_LABEL(__CFUnicodeDataLEnd)
3439
_C_LABEL(__CFUnicodeDataLEnd):
3540
.byte 0
41+
#if defined(__wasm__)
42+
.size _C_LABEL(__CFUnicodeDataLEnd), . - _C_LABEL(__CFUnicodeDataLEnd)
43+
#endif
3644

3745
.global _C_LABEL(__CFUnicodeDataLSize)
3846
_C_LABEL(__CFUnicodeDataLSize):
3947
.int _C_LABEL(__CFUnicodeDataLEnd) - _C_LABEL(__CFUnicodeDataL)
48+
#if defined(__wasm__)
49+
.size _C_LABEL(__CFUnicodeDataLSize), . - _C_LABEL(__CFUnicodeDataLSize)
50+
#endif
4051
#endif
4152

4253
NO_EXEC_STACK_DIRECTIVE

0 commit comments

Comments
 (0)