Skip to content

Commit 26f7659

Browse files
authored
Merge pull request #9265 from milseman/tls_ftw
[stdlib] Unicode 9 and Thread Local Storage
2 parents 7b927e5 + 2af0ace commit 26f7659

File tree

13 files changed

+640
-19
lines changed

13 files changed

+640
-19
lines changed

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ double _swift_stdlib_squareRoot(double _self) {
111111
return __builtin_sqrt(_self);
112112
}
113113

114+
// TLS - thread local storage
115+
116+
#if defined(__linux__)
117+
typedef unsigned int __swift_pthread_key_t;
118+
#else
119+
typedef unsigned long __swift_pthread_key_t;
120+
#endif
121+
122+
SWIFT_RUNTIME_STDLIB_INTERFACE
123+
int _swift_stdlib_pthread_key_create(
124+
__swift_pthread_key_t * _Nonnull key, void
125+
(* _Nullable destructor)(void * _Nullable )
126+
);
127+
128+
SWIFT_RUNTIME_STDLIB_INTERFACE
129+
void * _Nullable _swift_stdlib_pthread_getspecific(__swift_pthread_key_t key);
130+
131+
SWIFT_RUNTIME_STDLIB_INTERFACE
132+
int _swift_stdlib_pthread_setspecific(
133+
__swift_pthread_key_t key, const void * _Nullable value
134+
);
135+
114136
// TODO: Remove horrible workaround when importer does Float80 <-> long double.
115137
#if (defined __i386__ || defined __x86_64__) && !defined _MSC_VER
116138
static inline SWIFT_ALWAYS_INLINE

stdlib/public/SwiftShims/UnicodeShims.h

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,218 @@ __swift_int32_t _swift_stdlib_unicode_strToLower(
109109
__swift_uint16_t *Destination, __swift_int32_t DestinationCapacity,
110110
const __swift_uint16_t *Source, __swift_int32_t SourceLength);
111111

112+
typedef enum __swift_stdlib_UErrorCode {
113+
__swift_stdlib_U_USING_FALLBACK_WARNING = -128,
114+
__swift_stdlib_U_ERROR_WARNING_START = -128,
115+
__swift_stdlib_U_USING_DEFAULT_WARNING = -127,
116+
__swift_stdlib_U_SAFECLONE_ALLOCATED_WARNING = -126,
117+
__swift_stdlib_U_STATE_OLD_WARNING = -125,
118+
__swift_stdlib_U_STRING_NOT_TERMINATED_WARNING = -124,
119+
__swift_stdlib_U_SORT_KEY_TOO_SHORT_WARNING = -123,
120+
__swift_stdlib_U_AMBIGUOUS_ALIAS_WARNING = -122,
121+
__swift_stdlib_U_DIFFERENT_UCA_VERSION = -121,
122+
__swift_stdlib_U_PLUGIN_CHANGED_LEVEL_WARNING = -120,
123+
__swift_stdlib_U_ERROR_WARNING_LIMIT,
124+
__swift_stdlib_U_ZERO_ERROR = 0,
125+
__swift_stdlib_U_ILLEGAL_ARGUMENT_ERROR = 1,
126+
__swift_stdlib_U_MISSING_RESOURCE_ERROR = 2,
127+
__swift_stdlib_U_INVALID_FORMAT_ERROR = 3,
128+
__swift_stdlib_U_FILE_ACCESS_ERROR = 4,
129+
__swift_stdlib_U_INTERNAL_PROGRAM_ERROR = 5,
130+
__swift_stdlib_U_MESSAGE_PARSE_ERROR = 6,
131+
__swift_stdlib_U_MEMORY_ALLOCATION_ERROR = 7,
132+
__swift_stdlib_U_INDEX_OUTOFBOUNDS_ERROR = 8,
133+
__swift_stdlib_U_PARSE_ERROR = 9,
134+
__swift_stdlib_U_INVALID_CHAR_FOUND = 10,
135+
__swift_stdlib_U_TRUNCATED_CHAR_FOUND = 11,
136+
__swift_stdlib_U_ILLEGAL_CHAR_FOUND = 12,
137+
__swift_stdlib_U_INVALID_TABLE_FORMAT = 13,
138+
__swift_stdlib_U_INVALID_TABLE_FILE = 14,
139+
__swift_stdlib_U_BUFFER_OVERFLOW_ERROR = 15,
140+
__swift_stdlib_U_UNSUPPORTED_ERROR = 16,
141+
__swift_stdlib_U_RESOURCE_TYPE_MISMATCH = 17,
142+
__swift_stdlib_U_ILLEGAL_ESCAPE_SEQUENCE = 18,
143+
__swift_stdlib_U_UNSUPPORTED_ESCAPE_SEQUENCE = 19,
144+
__swift_stdlib_U_NO_SPACE_AVAILABLE = 20,
145+
__swift_stdlib_U_CE_NOT_FOUND_ERROR = 21,
146+
__swift_stdlib_U_PRIMARY_TOO_LONG_ERROR = 22,
147+
__swift_stdlib_U_STATE_TOO_OLD_ERROR = 23,
148+
__swift_stdlib_U_TOO_MANY_ALIASES_ERROR = 24,
149+
__swift_stdlib_U_ENUM_OUT_OF_SYNC_ERROR = 25,
150+
__swift_stdlib_U_INVARIANT_CONVERSION_ERROR = 26,
151+
__swift_stdlib_U_INVALID_STATE_ERROR = 27,
152+
__swift_stdlib_U_COLLATOR_VERSION_MISMATCH = 28,
153+
__swift_stdlib_U_USELESS_COLLATOR_ERROR = 29,
154+
__swift_stdlib_U_NO_WRITE_PERMISSION = 30,
155+
__swift_stdlib_U_STANDARD_ERROR_LIMIT,
156+
__swift_stdlib_U_BAD_VARIABLE_DEFINITION = 0x10000,
157+
__swift_stdlib_U_PARSE_ERROR_START = 0x10000,
158+
__swift_stdlib_U_MALFORMED_RULE,
159+
__swift_stdlib_U_MALFORMED_SET,
160+
__swift_stdlib_U_MALFORMED_SYMBOL_REFERENCE,
161+
__swift_stdlib_U_MALFORMED_UNICODE_ESCAPE,
162+
__swift_stdlib_U_MALFORMED_VARIABLE_DEFINITION,
163+
__swift_stdlib_U_MALFORMED_VARIABLE_REFERENCE,
164+
__swift_stdlib_U_MISMATCHED_SEGMENT_DELIMITERS,
165+
__swift_stdlib_U_MISPLACED_ANCHOR_START,
166+
__swift_stdlib_U_MISPLACED_CURSOR_OFFSET,
167+
__swift_stdlib_U_MISPLACED_QUANTIFIER,
168+
__swift_stdlib_U_MISSING_OPERATOR,
169+
__swift_stdlib_U_MISSING_SEGMENT_CLOSE,
170+
__swift_stdlib_U_MULTIPLE_ANTE_CONTEXTS,
171+
__swift_stdlib_U_MULTIPLE_CURSORS,
172+
__swift_stdlib_U_MULTIPLE_POST_CONTEXTS,
173+
__swift_stdlib_U_TRAILING_BACKSLASH,
174+
__swift_stdlib_U_UNDEFINED_SEGMENT_REFERENCE,
175+
__swift_stdlib_U_UNDEFINED_VARIABLE,
176+
__swift_stdlib_U_UNQUOTED_SPECIAL,
177+
__swift_stdlib_U_UNTERMINATED_QUOTE,
178+
__swift_stdlib_U_RULE_MASK_ERROR,
179+
__swift_stdlib_U_MISPLACED_COMPOUND_FILTER,
180+
__swift_stdlib_U_MULTIPLE_COMPOUND_FILTERS,
181+
__swift_stdlib_U_INVALID_RBT_SYNTAX,
182+
__swift_stdlib_U_INVALID_PROPERTY_PATTERN,
183+
__swift_stdlib_U_MALFORMED_PRAGMA,
184+
__swift_stdlib_U_UNCLOSED_SEGMENT,
185+
__swift_stdlib_U_ILLEGAL_CHAR_IN_SEGMENT,
186+
__swift_stdlib_U_VARIABLE_RANGE_EXHAUSTED,
187+
__swift_stdlib_U_VARIABLE_RANGE_OVERLAP,
188+
__swift_stdlib_U_ILLEGAL_CHARACTER,
189+
__swift_stdlib_U_INTERNAL_TRANSLITERATOR_ERROR,
190+
__swift_stdlib_U_INVALID_ID,
191+
__swift_stdlib_U_INVALID_FUNCTION,
192+
__swift_stdlib_U_PARSE_ERROR_LIMIT,
193+
__swift_stdlib_U_UNEXPECTED_TOKEN = 0x10100,
194+
__swift_stdlib_U_FMT_PARSE_ERROR_START = 0x10100,
195+
__swift_stdlib_U_MULTIPLE_DECIMAL_SEPARATORS,
196+
__swift_stdlib_U_MULTIPLE_DECIMAL_SEPERATORS =
197+
__swift_stdlib_U_MULTIPLE_DECIMAL_SEPARATORS,
198+
__swift_stdlib_U_MULTIPLE_EXPONENTIAL_SYMBOLS,
199+
__swift_stdlib_U_MALFORMED_EXPONENTIAL_PATTERN,
200+
__swift_stdlib_U_MULTIPLE_PERCENT_SYMBOLS,
201+
__swift_stdlib_U_MULTIPLE_PERMILL_SYMBOLS,
202+
__swift_stdlib_U_MULTIPLE_PAD_SPECIFIERS,
203+
__swift_stdlib_U_PATTERN_SYNTAX_ERROR,
204+
__swift_stdlib_U_ILLEGAL_PAD_POSITION,
205+
__swift_stdlib_U_UNMATCHED_BRACES,
206+
__swift_stdlib_U_UNSUPPORTED_PROPERTY,
207+
__swift_stdlib_U_UNSUPPORTED_ATTRIBUTE,
208+
__swift_stdlib_U_ARGUMENT_TYPE_MISMATCH,
209+
__swift_stdlib_U_DUPLICATE_KEYWORD,
210+
__swift_stdlib_U_UNDEFINED_KEYWORD,
211+
__swift_stdlib_U_DEFAULT_KEYWORD_MISSING,
212+
__swift_stdlib_U_DECIMAL_NUMBER_SYNTAX_ERROR,
213+
__swift_stdlib_U_FORMAT_INEXACT_ERROR,
214+
__swift_stdlib_U_FMT_PARSE_ERROR_LIMIT,
215+
__swift_stdlib_U_BRK_INTERNAL_ERROR = 0x10200,
216+
__swift_stdlib_U_BRK_ERROR_START = 0x10200,
217+
__swift_stdlib_U_BRK_HEX_DIGITS_EXPECTED,
218+
__swift_stdlib_U_BRK_SEMICOLON_EXPECTED,
219+
__swift_stdlib_U_BRK_RULE_SYNTAX,
220+
__swift_stdlib_U_BRK_UNCLOSED_SET,
221+
__swift_stdlib_U_BRK_ASSIGN_ERROR,
222+
__swift_stdlib_U_BRK_VARIABLE_REDFINITION,
223+
__swift_stdlib_U_BRK_MISMATCHED_PAREN,
224+
__swift_stdlib_U_BRK_NEW_LINE_IN_QUOTED_STRING,
225+
__swift_stdlib_U_BRK_UNDEFINED_VARIABLE,
226+
__swift_stdlib_U_BRK_INIT_ERROR,
227+
__swift_stdlib_U_BRK_RULE_EMPTY_SET,
228+
__swift_stdlib_U_BRK_UNRECOGNIZED_OPTION,
229+
__swift_stdlib_U_BRK_MALFORMED_RULE_TAG,
230+
__swift_stdlib_U_BRK_ERROR_LIMIT,
231+
__swift_stdlib_U_REGEX_INTERNAL_ERROR = 0x10300,
232+
__swift_stdlib_U_REGEX_ERROR_START = 0x10300,
233+
__swift_stdlib_U_REGEX_RULE_SYNTAX,
234+
__swift_stdlib_U_REGEX_INVALID_STATE,
235+
__swift_stdlib_U_REGEX_BAD_ESCAPE_SEQUENCE,
236+
__swift_stdlib_U_REGEX_PROPERTY_SYNTAX,
237+
__swift_stdlib_U_REGEX_UNIMPLEMENTED,
238+
__swift_stdlib_U_REGEX_MISMATCHED_PAREN,
239+
__swift_stdlib_U_REGEX_NUMBER_TOO_BIG,
240+
__swift_stdlib_U_REGEX_BAD_INTERVAL,
241+
__swift_stdlib_U_REGEX_MAX_LT_MIN,
242+
__swift_stdlib_U_REGEX_INVALID_BACK_REF,
243+
__swift_stdlib_U_REGEX_INVALID_FLAG,
244+
__swift_stdlib_U_REGEX_LOOK_BEHIND_LIMIT,
245+
__swift_stdlib_U_REGEX_SET_CONTAINS_STRING,
246+
#ifndef __swift_stdlib_U_HIDE_DEPRECATED_API
247+
__swift_stdlib_U_REGEX_OCTAL_TOO_BIG,
248+
#endif
249+
__swift_stdlib_U_REGEX_MISSING_CLOSE_BRACKET =
250+
__swift_stdlib_U_REGEX_SET_CONTAINS_STRING + 2,
251+
__swift_stdlib_U_REGEX_INVALID_RANGE,
252+
__swift_stdlib_U_REGEX_STACK_OVERFLOW,
253+
__swift_stdlib_U_REGEX_TIME_OUT,
254+
__swift_stdlib_U_REGEX_STOPPED_BY_CALLER,
255+
#ifndef __swift_stdlib_U_HIDE_DRAFT_API
256+
__swift_stdlib_U_REGEX_PATTERN_TOO_BIG,
257+
__swift_stdlib_U_REGEX_INVALID_CAPTURE_GROUP_NAME,
258+
#endif
259+
__swift_stdlib_U_REGEX_ERROR_LIMIT =
260+
__swift_stdlib_U_REGEX_STOPPED_BY_CALLER + 3,
261+
__swift_stdlib_U_IDNA_PROHIBITED_ERROR = 0x10400,
262+
__swift_stdlib_U_IDNA_ERROR_START = 0x10400,
263+
__swift_stdlib_U_IDNA_UNASSIGNED_ERROR,
264+
__swift_stdlib_U_IDNA_CHECK_BIDI_ERROR,
265+
__swift_stdlib_U_IDNA_STD3_ASCII_RULES_ERROR,
266+
__swift_stdlib_U_IDNA_ACE_PREFIX_ERROR,
267+
__swift_stdlib_U_IDNA_VERIFICATION_ERROR,
268+
__swift_stdlib_U_IDNA_LABEL_TOO_LONG_ERROR,
269+
__swift_stdlib_U_IDNA_ZERO_LENGTH_LABEL_ERROR,
270+
__swift_stdlib_U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR,
271+
__swift_stdlib_U_IDNA_ERROR_LIMIT,
272+
__swift_stdlib_U_STRINGPREP_PROHIBITED_ERROR =
273+
__swift_stdlib_U_IDNA_PROHIBITED_ERROR,
274+
__swift_stdlib_U_STRINGPREP_UNASSIGNED_ERROR =
275+
__swift_stdlib_U_IDNA_UNASSIGNED_ERROR,
276+
__swift_stdlib_U_STRINGPREP_CHECK_BIDI_ERROR =
277+
__swift_stdlib_U_IDNA_CHECK_BIDI_ERROR,
278+
__swift_stdlib_U_PLUGIN_ERROR_START = 0x10500,
279+
__swift_stdlib_U_PLUGIN_TOO_HIGH = 0x10500,
280+
__swift_stdlib_U_PLUGIN_DIDNT_SET_LEVEL,
281+
__swift_stdlib_U_PLUGIN_ERROR_LIMIT,
282+
__swift_stdlib_U_ERROR_LIMIT = __swift_stdlib_U_PLUGIN_ERROR_LIMIT
283+
} __swift_stdlib_UErrorCode;
284+
285+
typedef enum __swift_stdlib_UBreakIteratorType {
286+
__swift_stdlib_UBRK_CHARACTER = 0,
287+
__swift_stdlib_UBRK_WORD = 1,
288+
__swift_stdlib_UBRK_LINE = 2,
289+
__swift_stdlib_UBRK_SENTENCE = 3,
290+
#ifndef U_HIDE_DEPRECATED_API
291+
__swift_stdlib_UBRK_TITLE = 4,
292+
#endif
293+
__swift_stdlib_UBRK_COUNT = 5
294+
} __swift_stdlib_UBreakIteratorType;
295+
296+
typedef struct __swift_stdlib_UBreakIterator __swift_stdlib_UBreakIterator;
297+
typedef __swift_uint16_t __swift_stdlib_UChar;
298+
299+
SWIFT_RUNTIME_STDLIB_INTERFACE
300+
void __swift_stdlib_ubrk_close(__swift_stdlib_UBreakIterator *bi);
301+
302+
SWIFT_RUNTIME_STDLIB_INTERFACE
303+
__swift_stdlib_UBreakIterator *
304+
__swift_stdlib_ubrk_open(__swift_stdlib_UBreakIteratorType type,
305+
const char *_Null_unspecified locale,
306+
const __swift_stdlib_UChar *_Null_unspecified text,
307+
__swift_int32_t textLength,
308+
__swift_stdlib_UErrorCode *status);
309+
310+
SWIFT_RUNTIME_STDLIB_INTERFACE
311+
void __swift_stdlib_ubrk_setText(__swift_stdlib_UBreakIterator *bi,
312+
const __swift_stdlib_UChar *text,
313+
__swift_int32_t textLength,
314+
__swift_stdlib_UErrorCode *status);
315+
316+
SWIFT_RUNTIME_STDLIB_INTERFACE
317+
__swift_int32_t __swift_stdlib_ubrk_preceding(__swift_stdlib_UBreakIterator *bi,
318+
__swift_int32_t offset);
319+
320+
SWIFT_RUNTIME_STDLIB_INTERFACE
321+
__swift_int32_t __swift_stdlib_ubrk_following(__swift_stdlib_UBreakIterator *bi,
322+
__swift_int32_t offset);
323+
112324
#ifdef __cplusplus
113325
}} // extern "C", namespace swift
114326
#endif

stdlib/public/core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ set(SWIFTLIB_ESSENTIAL
6868
HashedCollectionsAnyHashableExtensions.swift
6969
Hashing.swift
7070
HeapBuffer.swift
71+
ICU.swift
7172
ImplicitlyUnwrappedOptional.swift
7273
Index.swift
7374
Indices.swift.gyb
@@ -132,6 +133,7 @@ set(SWIFTLIB_ESSENTIAL
132133
StringUTF8.swift
133134
Substring.swift.gyb
134135
SwiftNativeNSArray.swift
136+
ThreadLocalStorage.swift
135137
UIntBuffer.swift
136138
UnavailableStringAPIs.swift.gyb
137139
UnicodeEncoding.swift
@@ -177,6 +179,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
177179
list(APPEND swift_core_link_flags "-all_load")
178180
list(APPEND swift_core_framework_depends Foundation)
179181
list(APPEND swift_core_framework_depends CoreFoundation)
182+
list(APPEND swift_core_private_link_libraries icucore)
180183
else()
181184
# With the GNU linker the equivalent of -all_load is to tell the linker
182185
# --whole-archive before the archive and --no-whole-archive after (without

stdlib/public/core/GroupInfo.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"ASCII.swift",
88
"CString.swift",
99
"Character.swift",
10+
"ICU.swift",
1011
"StaticString.swift",
1112
"String.swift",
1213
"StringBridge.swift",
@@ -162,6 +163,7 @@
162163
"REPL.swift",
163164
"Runtime.swift",
164165
"Shims.swift",
166+
"ThreadLocalStorage.swift",
165167
"Unmanaged.swift",
166168
"Availability.swift",
167169
"CommandLine.swift",

stdlib/public/core/ICU.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===--- ICU.swift --------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
import SwiftShims
13+
14+
extension __swift_stdlib_UErrorCode {
15+
var isFailure: Bool { return rawValue > __swift_stdlib_U_ZERO_ERROR.rawValue }
16+
var isWarning: Bool { return rawValue < __swift_stdlib_U_ZERO_ERROR.rawValue }
17+
var isSuccess: Bool { return rawValue <= __swift_stdlib_U_ZERO_ERROR.rawValue }
18+
}

0 commit comments

Comments
 (0)