Skip to content

Revert "Import CoreFoundation sources from High Sierra" #1328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CoreFoundation/AppServices.subproj/CFNotificationCenter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFNotificationCenter.h
Copyright (c) 1998-2017, Apple Inc. and the Swift project authors
Copyright (c) 1998-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down
4 changes: 2 additions & 2 deletions CoreFoundation/AppServices.subproj/CFUserNotification.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFUserNotification.c
Copyright (c) 2000-2017, Apple Inc. All rights reserved.
Copyright (c) 2000-2016, Apple Inc. All rights reserved.

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down
6 changes: 3 additions & 3 deletions CoreFoundation/AppServices.subproj/CFUserNotification.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFUserNotification.h
Copyright (c) 2000-2017, Apple Inc. and the Swift project authors
Copyright (c) 2000-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down Expand Up @@ -170,7 +170,7 @@ CF_EXPORT
const CFStringRef kCFUserNotificationTextFieldValuesKey;

CF_EXPORT
const CFStringRef kCFUserNotificationPopUpSelectionKey API_AVAILABLE(macos(10.3)) API_UNAVAILABLE(ios, watchos, tvos);
const CFStringRef kCFUserNotificationPopUpSelectionKey CF_AVAILABLE(10_3, NA);

#if (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
CF_EXPORT
Expand Down
67 changes: 15 additions & 52 deletions CoreFoundation/Base.subproj/CFAvailability.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFAvailability.h
Copyright (c) 2013-2017, Apple Inc. and the Swift project authors
Copyright (c) 2013-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand All @@ -10,23 +10,23 @@
#if !defined(__COREFOUNDATION_CFAVAILABILITY__)
#define __COREFOUNDATION_CFAVAILABILITY__ 1

#if __has_include(<CoreFoundation/TargetConditionals.h>)
#if DEPLOYMENT_RUNTIME_SWIFT
#include <CoreFoundation/TargetConditionals.h>
#elif __has_include(<TargetConditionals.h>)
#include <TargetConditionals.h>
#else
#error Missing header TargetConditionals.h
#include <TargetConditionals.h>
#endif

#if __has_include(<Availability.h>) && __has_include(<os/Availability.h>) && __has_include(<AvailabilityMacros.h>)
#if DEPLOYMENT_RUNTIME_SWIFT
#define API_AVAILABLE(...)
#define API_DEPRECATED(...)
#else
#if (TARGET_OS_MAC || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32)
#include <Availability.h>
#include <os/availability.h>

// Even if unused, these must remain here for compatibility, because projects rely on them being included.
#include <AvailabilityMacros.h>
#else
#define API_AVAILABLE(...)
#define API_DEPRECATED(...)
#define API_UNAVAILABLE(...)
#endif
#endif

#ifndef __has_feature
Expand Down Expand Up @@ -112,22 +112,14 @@
#endif

// Enums and Options
#if __has_attribute(enum_extensibility)
#define __CF_ENUM_ATTRIBUTES __attribute__((enum_extensibility(open)))
#define __CF_OPTIONS_ATTRIBUTES __attribute__((flag_enum,enum_extensibility(open)))
#else
#define __CF_ENUM_ATTRIBUTES
#define __CF_OPTIONS_ATTRIBUTES
#endif

#define __CF_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum))
#define __CF_NAMED_ENUM(_type, _name) enum __CF_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
#define __CF_ANON_ENUM(_type) enum __CF_ENUM_ATTRIBUTES : _type
#define __CF_NAMED_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
#define __CF_ANON_ENUM(_type) enum : _type
#if (__cplusplus)
#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _type
#define CF_OPTIONS(_type, _name) _type _name; enum : _type
#else
#define CF_OPTIONS(_type, _name) enum __CF_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type
#define CF_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
#endif
#else
#define __CF_NAMED_ENUM(_type, _name) _type _name; enum
Expand Down Expand Up @@ -164,40 +156,11 @@ CF_ENUM(CFIndex) {
#if DEPLOYMENT_RUNTIME_SWIFT
#define CF_STRING_ENUM
#define CF_EXTENSIBLE_STRING_ENUM

#define CF_TYPED_ENUM
#define CF_TYPED_EXTENSIBLE_ENUM
#else
#define CF_STRING_ENUM _CF_TYPED_ENUM
#define CF_EXTENSIBLE_STRING_ENUM _CF_TYPED_EXTENSIBLE_ENUM

#define CF_TYPED_ENUM _CF_TYPED_ENUM
#define CF_TYPED_EXTENSIBLE_ENUM _CF_TYPED_EXTENSIBLE_ENUM
#endif

#define __CF_ERROR_ENUM_GET_MACRO(_1, _2, NAME, ...) NAME
#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)
#define __CF_NAMED_ERROR_ENUM(_domain, _name) enum __attribute__((ns_error_domain(_domain))) _name : CFIndex _name; enum _name : CFIndex
#define __CF_ANON_ERROR_ENUM(_domain) enum __attribute__((ns_error_domain(_domain))) : CFIndex
#else
#define __CF_NAMED_ERROR_ENUM(_domain, _name) __CF_NAMED_ENUM(CFIndex, _name)
#define __CF_ANON_ERROR_ENUM(_domain) __CF_ANON_ENUM(CFIndex)
#endif

/* 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:

typedef CF_ERROR_ENUM(kCFSomeErrorDomain, SomeErrorCodes) {
...
};

If you do not specify a typedef name, do not use 'typedef', like so:

CF_ERROR_ENUM(kCFSomeErrorDomain) {
...
};
*/
#define CF_ERROR_ENUM(...) __CF_ERROR_ENUM_GET_MACRO(__VA_ARGS__, __CF_NAMED_ERROR_ENUM, __CF_ANON_ERROR_ENUM)(__VA_ARGS__)

// Extension availability macros
#define CF_EXTENSION_UNAVAILABLE(_msg) __OS_EXTENSION_UNAVAILABLE(_msg)
#define CF_EXTENSION_UNAVAILABLE_MAC(_msg) __OSX_EXTENSION_UNAVAILABLE(_msg)
Expand Down
46 changes: 8 additions & 38 deletions CoreFoundation/Base.subproj/CFBase.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFBase.c
Copyright (c) 1998-2017, Apple Inc. and the Swift project authors
Copyright (c) 1998-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down Expand Up @@ -533,7 +533,12 @@ static CFAllocatorRef __CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorC
if (__CFOASafe) __CFSetLastAllocationEventName(memory, "CFAllocator");
}
memset(memory, 0, sizeof(CFRuntimeBase));
__CFRuntimeSetRC(memory, 1);
#if __LP64__
memory->_base._rc = 1;
#else
memory->_base._cfinfo[CF_RC_BITS] = 1;
#endif
memory->_base._cfinfo[CF_INFO_BITS] = 0;
_CFAllocatorSetInstanceTypeIDAndIsa(memory);
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
memory->size = __CFAllocatorCustomSize;
Expand Down Expand Up @@ -753,41 +758,6 @@ void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context
// -------- -------- -------- -------- -------- -------- -------- --------



static void __CFReallocationFailed(void *ptr, CFStringRef reason, void (^reallocationFailureHandler)(void *original, _Bool *outRecovered)) {
_Bool recovered = false;
if (reallocationFailureHandler) {
reallocationFailureHandler(ptr, &recovered);
}

if (!recovered) {
CRSetCrashLogMessage("Failed to grow buffer");
HALT;
}
}


void *__CFSafelyReallocate(void *destination, size_t newCapacity, void (^reallocationFailureHandler)(void *original, _Bool *outRecovered)) {
void *const reallocated = realloc(destination, newCapacity);
if (__builtin_expect(reallocated == NULL, false)) {
__CFReallocationFailed(destination, CFSTR("realloc"), reallocationFailureHandler);
}
return reallocated;
}


void *__CFSafelyReallocateWithAllocator(CFAllocatorRef allocator, void *destination, size_t newCapacity, CFOptionFlags options, void (^reallocationFailureHandler)(void *original, _Bool *outRecovered)) {
void *reallocated = CFAllocatorReallocate(allocator, destination, newCapacity, options);
// NOTE: important difference in behavior between realloc vs CFAllocateReallocate NULL+0 -> NULL for allocators!
if (__builtin_expect(reallocated == NULL, false) && !(destination == NULL && newCapacity == 0)) {
__CFReallocationFailed(destination, CFSTR("realloc"), reallocationFailureHandler);
}
return reallocated;
}




CFRange __CFRangeMake(CFIndex loc, CFIndex len) {
CFRange range;
range.location = loc;
Expand Down
18 changes: 8 additions & 10 deletions CoreFoundation/Base.subproj/CFBase.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFBase.h
Copyright (c) 1998-2017, Apple Inc. and the Swift project authors
Copyright (c) 1998-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down Expand Up @@ -66,10 +66,6 @@
#if defined(__GNUC__) || TARGET_OS_WIN32
#include <stdint.h>
#include <stdbool.h>
#endif

#if __BLOCKS__ && ((TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
#include <Block.h>
#endif

#if ((TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) && !DEPLOYMENT_RUNTIME_SWIFT
Expand Down Expand Up @@ -139,9 +135,11 @@
#endif
#endif
#else

#define CF_EXPORT extern

#if defined(__cplusplus)
#define CF_EXPORT extern "C"
#else
#define CF_EXPORT extern
#endif
#endif

CF_EXTERN_C_BEGIN
Expand Down Expand Up @@ -656,7 +654,7 @@ void CFRelease(CFTypeRef cf);
#if DEPLOYMENT_RUNTIME_SWIFT
#else
CF_EXPORT
CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) API_AVAILABLE(macos(10.9), ios(7.0), watchos(2.0), tvos(9.0));
CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) CF_AVAILABLE(10_9, 7_0);

CF_EXPORT
CFIndex CFGetRetainCount(CFTypeRef cf);
Expand Down
4 changes: 2 additions & 2 deletions CoreFoundation/Base.subproj/CFByteOrder.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFByteOrder.h
Copyright (c) 1995-2017, Apple Inc. and the Swift project authors
Copyright (c) 1995-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down
29 changes: 8 additions & 21 deletions CoreFoundation/Base.subproj/CFFileUtilities.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* CFFileUtilities.c
Copyright (c) 1999-2017, Apple Inc. and the Swift project authors
Copyright (c) 1999-2016, Apple Inc. and the Swift project authors

Portions Copyright (c) 2014-2017, Apple Inc. and the Swift project authors
Portions Copyright (c) 2014-2016 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
Expand Down Expand Up @@ -594,10 +594,6 @@ CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, B
return _CFGetPathProperties(alloc, path, exists, posixMode, size, modTime, ownerID, dirContents);
}

CF_PRIVATE bool _CFURLExists(CFURLRef url) {
Boolean exists;
return url && (0 == _CFGetFileProperties(kCFAllocatorSystemDefault, url, &exists, NULL, NULL, NULL, NULL, NULL)) && exists;
}

#if DEPLOYMENT_TARGET_WINDOWS
#define WINDOWS_PATH_SEMANTICS
Expand Down Expand Up @@ -1096,22 +1092,15 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
for (CFIndex i = 0; i < CFArrayGetCount(stuffToPrefix); i++) {
CFStringRef onePrefix = CFArrayGetValueAtIndex(stuffToPrefix, i);
// Note: CFStringGetBytes does not null-terminate - we will do that below
CFIndex usedBufLen = 0;
startAt += CFStringGetBytes(onePrefix, CFRangeMake(0, CFStringGetLength(onePrefix)), CFStringFileSystemEncoding(), 0, false, (UInt8 *)fullPathToFile + startAt, sizeof(fullPathToFile) - startAt, &usedBufLen);
if (startAt > 0) { // Add a / if the string did not have one
// In some cases, startAt and usedBufLen differ (e.g. the num of bytes returned is less than the number written to the buffer).
if (startAt < usedBufLen) {
if (fullPathToFile[usedBufLen - 1] != (char)_CFGetSlash()) {
fullPathToFile[usedBufLen] = (char)_CFGetSlash();
startAt += (usedBufLen - startAt) + 1;
}
} else {
if (fullPathToFile[startAt - 1] != (char)_CFGetSlash()) {
fullPathToFile[startAt++] = (char)_CFGetSlash();
}
startAt += CFStringGetBytes(onePrefix, CFRangeMake(0, CFStringGetLength(onePrefix)), CFStringFileSystemEncoding(), 0, false, (UInt8 *)fullPathToFile + startAt, sizeof(fullPathToFile) - startAt, NULL);
if (startAt > 0) {
// Add a / if the string did not have one
if (fullPathToFile[startAt - 1] != (char)_CFGetSlash()) {
fullPathToFile[startAt++] = (char)_CFGetSlash();
}
}
}

fullPathToFile[startAt] = 0;
}

Expand Down Expand Up @@ -1178,7 +1167,6 @@ CF_PRIVATE void _CFIterateDirectory(CFStringRef directoryPath, Boolean appendSla
#endif
}


#if DEPLOYMENT_RUNTIME_SWIFT

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

#endif

Loading