Skip to content

Commit 622c5ff

Browse files
committed
Import CoreFoundation sources from High Sierra
1 parent cc8ec6a commit 622c5ff

File tree

170 files changed

+6516
-4778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+6516
-4778
lines changed

Diff for: CoreFoundation/AppServices.subproj/CFNotificationCenter.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFNotificationCenter.h
2-
Copyright (c) 1998-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 1998-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

Diff for: CoreFoundation/AppServices.subproj/CFUserNotification.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFUserNotification.c
2-
Copyright (c) 2000-2016, Apple Inc. All rights reserved.
2+
Copyright (c) 2000-2017, Apple Inc. All rights reserved.
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

Diff for: CoreFoundation/AppServices.subproj/CFUserNotification.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFUserNotification.h
2-
Copyright (c) 2000-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 2000-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
@@ -170,7 +170,7 @@ CF_EXPORT
170170
const CFStringRef kCFUserNotificationTextFieldValuesKey;
171171

172172
CF_EXPORT
173-
const CFStringRef kCFUserNotificationPopUpSelectionKey CF_AVAILABLE(10_3, NA);
173+
const CFStringRef kCFUserNotificationPopUpSelectionKey API_AVAILABLE(macos(10.3)) API_UNAVAILABLE(ios, watchos, tvos);
174174

175175
#if (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
176176
CF_EXPORT

Diff for: CoreFoundation/Base.subproj/CFAvailability.h

+52-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFAvailability.h
2-
Copyright (c) 2013-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 2013-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
@@ -10,23 +10,23 @@
1010
#if !defined(__COREFOUNDATION_CFAVAILABILITY__)
1111
#define __COREFOUNDATION_CFAVAILABILITY__ 1
1212

13-
#if DEPLOYMENT_RUNTIME_SWIFT
13+
#if __has_include(<CoreFoundation/TargetConditionals.h>)
1414
#include <CoreFoundation/TargetConditionals.h>
15-
#else
15+
#elif __has_include(<TargetConditionals.h>)
1616
#include <TargetConditionals.h>
17+
#else
18+
#error Missing header TargetConditionals.h
1719
#endif
1820

19-
#if DEPLOYMENT_RUNTIME_SWIFT
20-
#define API_AVAILABLE(...)
21-
#define API_DEPRECATED(...)
22-
#else
23-
#if (TARGET_OS_MAC || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32)
21+
#if __has_include(<Availability.h>) && __has_include(<os/Availability.h>) && __has_include(<AvailabilityMacros.h>)
2422
#include <Availability.h>
2523
#include <os/availability.h>
26-
2724
// Even if unused, these must remain here for compatibility, because projects rely on them being included.
2825
#include <AvailabilityMacros.h>
29-
#endif
26+
#else
27+
#define API_AVAILABLE(...)
28+
#define API_DEPRECATED(...)
29+
#define API_UNAVAILABLE(...)
3030
#endif
3131

3232
#ifndef __has_feature
@@ -112,14 +112,22 @@
112112
#endif
113113

114114
// Enums and Options
115+
#if __has_attribute(enum_extensibility)
116+
#define __CF_ENUM_ATTRIBUTES __attribute__((enum_extensibility(open)))
117+
#define __CF_OPTIONS_ATTRIBUTES __attribute__((flag_enum,enum_extensibility(open)))
118+
#else
119+
#define __CF_ENUM_ATTRIBUTES
120+
#define __CF_OPTIONS_ATTRIBUTES
121+
#endif
122+
115123
#define __CF_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME
116124
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
117-
#define __CF_NAMED_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
118-
#define __CF_ANON_ENUM(_type) enum : _type
125+
#define __CF_NAMED_ENUM(_type, _name) enum __CF_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
126+
#define __CF_ANON_ENUM(_type) enum __CF_ENUM_ATTRIBUTES : _type
119127
#if (__cplusplus)
120-
#define CF_OPTIONS(_type, _name) _type _name; enum : _type
128+
#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _type
121129
#else
122-
#define CF_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
130+
#define CF_OPTIONS(_type, _name) enum __CF_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type
123131
#endif
124132
#else
125133
#define __CF_NAMED_ENUM(_type, _name) _type _name; enum
@@ -156,11 +164,40 @@ CF_ENUM(CFIndex) {
156164
#if DEPLOYMENT_RUNTIME_SWIFT
157165
#define CF_STRING_ENUM
158166
#define CF_EXTENSIBLE_STRING_ENUM
167+
168+
#define CF_TYPED_ENUM
169+
#define CF_TYPED_EXTENSIBLE_ENUM
159170
#else
160171
#define CF_STRING_ENUM _CF_TYPED_ENUM
161172
#define CF_EXTENSIBLE_STRING_ENUM _CF_TYPED_EXTENSIBLE_ENUM
173+
174+
#define CF_TYPED_ENUM _CF_TYPED_ENUM
175+
#define CF_TYPED_EXTENSIBLE_ENUM _CF_TYPED_EXTENSIBLE_ENUM
176+
#endif
177+
178+
#define __CF_ERROR_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME
179+
#if ((__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))) && __has_attribute(ns_error_domain)
180+
#define __CF_NAMED_ERROR_ENUM(_domain, _name) enum __attribute__((ns_error_domain(_domain))) _name : CFIndex _name; enum _name : CFIndex
181+
#define __CF_ANON_ERROR_ENUM(_domain) enum __attribute__((ns_error_domain(_domain))) : CFIndex
182+
#else
183+
#define __CF_NAMED_ERROR_ENUM(_domain, _name) __CF_NAMED_ENUM(CFIndex, _name)
184+
#define __CF_ANON_ERROR_ENUM(_domain) __CF_ANON_ENUM(CFIndex)
162185
#endif
163186

187+
/* CF_ERROR_ENUM supports the use of one or two arguments. The first argument is always the domain specifier for the enum. The second argument is an optional name of the typedef for the macro. When specifying a name for of the typedef, you must precede the macro with 'typedef' like so:
188+
189+
typedef CF_ERROR_ENUM(kCFSomeErrorDomain, SomeErrorCodes) {
190+
...
191+
};
192+
193+
If you do not specify a typedef name, do not use 'typedef', like so:
194+
195+
CF_ERROR_ENUM(kCFSomeErrorDomain) {
196+
...
197+
};
198+
*/
199+
#define CF_ERROR_ENUM(...) __CF_ERROR_ENUM_GET_MACRO(__VA_ARGS__, __CF_NAMED_ERROR_ENUM, __CF_ANON_ERROR_ENUM)(__VA_ARGS__)
200+
164201
// Extension availability macros
165202
#define CF_EXTENSION_UNAVAILABLE(_msg) __OS_EXTENSION_UNAVAILABLE(_msg)
166203
#define CF_EXTENSION_UNAVAILABLE_MAC(_msg) __OSX_EXTENSION_UNAVAILABLE(_msg)

Diff for: CoreFoundation/Base.subproj/CFBase.c

+38-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFBase.c
2-
Copyright (c) 1998-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 1998-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
@@ -533,12 +533,7 @@ static CFAllocatorRef __CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorC
533533
if (__CFOASafe) __CFSetLastAllocationEventName(memory, "CFAllocator");
534534
}
535535
memset(memory, 0, sizeof(CFRuntimeBase));
536-
#if __LP64__
537-
memory->_base._rc = 1;
538-
#else
539-
memory->_base._cfinfo[CF_RC_BITS] = 1;
540-
#endif
541-
memory->_base._cfinfo[CF_INFO_BITS] = 0;
536+
__CFRuntimeSetRC(memory, 1);
542537
_CFAllocatorSetInstanceTypeIDAndIsa(memory);
543538
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
544539
memory->size = __CFAllocatorCustomSize;
@@ -758,6 +753,41 @@ void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context
758753
// -------- -------- -------- -------- -------- -------- -------- --------
759754

760755

756+
757+
static void __CFReallocationFailed(void *ptr, CFStringRef reason, void (^reallocationFailureHandler)(void *original, _Bool *outRecovered)) {
758+
_Bool recovered = false;
759+
if (reallocationFailureHandler) {
760+
reallocationFailureHandler(ptr, &recovered);
761+
}
762+
763+
if (!recovered) {
764+
CRSetCrashLogMessage("Failed to grow buffer");
765+
HALT;
766+
}
767+
}
768+
769+
770+
void *__CFSafelyReallocate(void *destination, size_t newCapacity, void (^reallocationFailureHandler)(void *original, _Bool *outRecovered)) {
771+
void *const reallocated = realloc(destination, newCapacity);
772+
if (__builtin_expect(reallocated == NULL, false)) {
773+
__CFReallocationFailed(destination, CFSTR("realloc"), reallocationFailureHandler);
774+
}
775+
return reallocated;
776+
}
777+
778+
779+
void *__CFSafelyReallocateWithAllocator(CFAllocatorRef allocator, void *destination, size_t newCapacity, CFOptionFlags options, void (^reallocationFailureHandler)(void *original, _Bool *outRecovered)) {
780+
void *reallocated = CFAllocatorReallocate(allocator, destination, newCapacity, options);
781+
// NOTE: important difference in behavior between realloc vs CFAllocateReallocate NULL+0 -> NULL for allocators!
782+
if (__builtin_expect(reallocated == NULL, false) && !(destination == NULL && newCapacity == 0)) {
783+
__CFReallocationFailed(destination, CFSTR("realloc"), reallocationFailureHandler);
784+
}
785+
return reallocated;
786+
}
787+
788+
789+
790+
761791
CFRange __CFRangeMake(CFIndex loc, CFIndex len) {
762792
CFRange range;
763793
range.location = loc;

Diff for: CoreFoundation/Base.subproj/CFBase.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFBase.h
2-
Copyright (c) 1998-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 1998-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
@@ -66,6 +66,10 @@
6666
#if defined(__GNUC__) || TARGET_OS_WIN32
6767
#include <stdint.h>
6868
#include <stdbool.h>
69+
#endif
70+
71+
#if __BLOCKS__ && ((TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
72+
#include <Block.h>
6973
#endif
7074

7175
#if ((TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) && !DEPLOYMENT_RUNTIME_SWIFT
@@ -135,11 +139,9 @@
135139
#endif
136140
#endif
137141
#else
138-
#if defined(__cplusplus)
139-
#define CF_EXPORT extern "C"
140-
#else
141-
#define CF_EXPORT extern
142-
#endif
142+
143+
#define CF_EXPORT extern
144+
143145
#endif
144146

145147
CF_EXTERN_C_BEGIN
@@ -654,7 +656,7 @@ void CFRelease(CFTypeRef cf);
654656
#if DEPLOYMENT_RUNTIME_SWIFT
655657
#else
656658
CF_EXPORT
657-
CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) CF_AVAILABLE(10_9, 7_0);
659+
CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) API_AVAILABLE(macos(10.9), ios(7.0), watchos(2.0), tvos(9.0));
658660

659661
CF_EXPORT
660662
CFIndex CFGetRetainCount(CFTypeRef cf);

Diff for: CoreFoundation/Base.subproj/CFByteOrder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFByteOrder.h
2-
Copyright (c) 1995-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 1995-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

Diff for: CoreFoundation/Base.subproj/CFFileUtilities.c

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* CFFileUtilities.c
2-
Copyright (c) 1999-2016, Apple Inc. and the Swift project authors
2+
Copyright (c) 1999-2017, Apple Inc. and the Swift project authors
33
4-
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
4+
Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
See http://swift.org/LICENSE.txt for license information
77
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
@@ -594,6 +594,10 @@ CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, B
594594
return _CFGetPathProperties(alloc, path, exists, posixMode, size, modTime, ownerID, dirContents);
595595
}
596596

597+
CF_PRIVATE bool _CFURLExists(CFURLRef url) {
598+
Boolean exists;
599+
return url && (0 == _CFGetFileProperties(kCFAllocatorSystemDefault, url, &exists, NULL, NULL, NULL, NULL, NULL)) && exists;
600+
}
597601

598602
#if DEPLOYMENT_TARGET_WINDOWS
599603
#define WINDOWS_PATH_SEMANTICS
@@ -1092,15 +1096,22 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
10921096
for (CFIndex i = 0; i < CFArrayGetCount(stuffToPrefix); i++) {
10931097
CFStringRef onePrefix = CFArrayGetValueAtIndex(stuffToPrefix, i);
10941098
// Note: CFStringGetBytes does not null-terminate - we will do that below
1095-
startAt += CFStringGetBytes(onePrefix, CFRangeMake(0, CFStringGetLength(onePrefix)), CFStringFileSystemEncoding(), 0, false, (UInt8 *)fullPathToFile + startAt, sizeof(fullPathToFile) - startAt, NULL);
1096-
if (startAt > 0) {
1097-
// Add a / if the string did not have one
1098-
if (fullPathToFile[startAt - 1] != (char)_CFGetSlash()) {
1099-
fullPathToFile[startAt++] = (char)_CFGetSlash();
1099+
CFIndex usedBufLen = 0;
1100+
startAt += CFStringGetBytes(onePrefix, CFRangeMake(0, CFStringGetLength(onePrefix)), CFStringFileSystemEncoding(), 0, false, (UInt8 *)fullPathToFile + startAt, sizeof(fullPathToFile) - startAt, &usedBufLen);
1101+
if (startAt > 0) { // Add a / if the string did not have one
1102+
// In some cases, startAt and usedBufLen differ (e.g. the num of bytes returned is less than the number written to the buffer).
1103+
if (startAt < usedBufLen) {
1104+
if (fullPathToFile[usedBufLen - 1] != (char)_CFGetSlash()) {
1105+
fullPathToFile[usedBufLen] = (char)_CFGetSlash();
1106+
startAt += (usedBufLen - startAt) + 1;
1107+
}
1108+
} else {
1109+
if (fullPathToFile[startAt - 1] != (char)_CFGetSlash()) {
1110+
fullPathToFile[startAt++] = (char)_CFGetSlash();
1111+
}
11001112
}
11011113
}
11021114
}
1103-
11041115
fullPathToFile[startAt] = 0;
11051116
}
11061117

@@ -1167,6 +1178,7 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
11671178
#endif
11681179
}
11691180

1181+
11701182
#if DEPLOYMENT_RUNTIME_SWIFT
11711183

11721184
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
@@ -1345,3 +1357,4 @@ CF_PRIVATE CFArrayRef _CFCreateCFArrayByTokenizingString(const char *values, cha
13451357
}
13461358

13471359
#endif
1360+

0 commit comments

Comments
 (0)