Skip to content

Commit d62c232

Browse files
Merge remote-tracking branch 'apple/master'
2 parents 276c55c + dc4fa2d commit d62c232

File tree

198 files changed

+20171
-3333
lines changed

Some content is hidden

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

198 files changed

+20171
-3333
lines changed

CoreFoundation/Base.subproj/CFBase.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -875,15 +875,7 @@ void _CFRuntimeSetCFMPresent(void *addr) {
875875

876876

877877
extern void __HALT() {
878-
#if defined(__ppc__)
879-
__asm__("trap");
880-
#elif defined(__i386__) || defined(__x86_64__)
881-
#if defined(_MSC_VER)
882-
__asm int 3;
883-
#else
884-
__asm__("int3");
885-
#endif
886-
#endif
878+
__builtin_trap();
887879
}
888880

889881

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
#include <stdbool.h>
8181
#endif
8282

83-
#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)
83+
#if ((TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) && !DEPLOYMENT_RUNTIME_SWIFT
8484
#include <libkern/OSTypes.h>
8585
#endif
8686

@@ -124,6 +124,7 @@
124124
typedef UInt8 UTF8Char;
125125
#endif
126126

127+
127128
#if !defined(CF_EXTERN_C_BEGIN)
128129
#if defined(__cplusplus)
129130
#define CF_EXTERN_C_BEGIN extern "C" {
@@ -231,14 +232,6 @@ CF_EXTERN_C_BEGIN
231232
#define CF_AUTOMATED_REFCOUNT_UNAVAILABLE
232233
#endif
233234

234-
#if DEPLOYMENT_RUNTIME_SWIFT
235-
#ifndef CF_ASSUME_NONNULL_BEGIN
236-
#define CF_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
237-
#endif
238-
#ifndef CF_ASSUME_NONNULL_BEGIN
239-
#define CF_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
240-
#endif
241-
#endif
242235

243236
#ifndef CF_IMPLICIT_BRIDGING_ENABLED
244237
#if __has_feature(arc_cf_code_audited)
@@ -647,9 +640,9 @@ void CFRelease(CFTypeRef cf);
647640
#else
648641
CF_EXPORT
649642
CFTypeRef CFAutorelease(CFTypeRef CF_RELEASES_ARGUMENT arg) CF_AVAILABLE(10_9, 7_0);
650-
#endif
651643
CF_EXPORT
652644
CFIndex CFGetRetainCount(CFTypeRef cf);
645+
#endif
653646

654647
CF_EXPORT
655648
Boolean CFEqual(CFTypeRef cf1, CFTypeRef cf2);

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ CF_EXTERN_C_BEGIN
9797
#include <CoreFoundation/CFLogUtilities.h>
9898
#include <CoreFoundation/CFRuntime.h>
9999
#include <limits.h>
100-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX
100+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
101101
#include <xlocale.h>
102102
#include <unistd.h>
103103
#include <sys/time.h>
@@ -169,6 +169,14 @@ CF_PRIVATE CFIndex __CFActiveProcessorCount();
169169
#else
170170
#error Compiler not supported
171171
#endif
172+
#elif defined(__ppc__) || (__arm__)
173+
#if defined(__GNUC__)
174+
#define HALT do {asm __volatile__("trap"); kill(getpid(), 9); __builtin_unreachable(); } while (0)
175+
#elif defined(_MSC_VER)
176+
#define HALT do { DebugBreak(); abort(); __builtin_unreachable(); } while (0)
177+
#else
178+
#error Compiler not supported
179+
#endif
172180
#endif
173181

174182
#if defined(DEBUG)
@@ -495,7 +503,7 @@ CF_INLINE Boolean __CFLockTry(volatile CFLock_t *lock) {
495503
return (InterlockedCompareExchange((LONG volatile *)lock, ~0, 0) == 0);
496504
}
497505

498-
#elif DEPLOYMENT_TARGET_LINUX
506+
#elif DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
499507

500508
typedef int32_t CFLock_t;
501509
#define CFLockInit 0
@@ -654,6 +662,9 @@ CF_INLINE uintptr_t __CFISAForTypeID(CFTypeID typeID) {
654662
return (typeID < __CFRuntimeClassTableSize) ? __CFRuntimeObjCClassTable[typeID] : 0;
655663
}
656664

665+
/* For Swift, which can't allocate any CF objects until after the bridge is initialized */
666+
CF_PRIVATE void __CFNumberInitialize(void);
667+
657668
/* See comments in CFBase.c
658669
*/
659670
#define FAULT_CALLBACK(V)
@@ -794,7 +805,7 @@ CF_EXPORT void _NS_pthread_setname_np(const char *name);
794805
#define pthread_setname_np _NS_pthread_setname_np
795806
#endif
796807

797-
#if DEPLOYMENT_TARGET_WINDOWS
808+
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
798809
// replacement for DISPATCH_QUEUE_OVERCOMMIT until we get a bug fix in dispatch on Windows
799810
// <rdar://problem/7923891> dispatch on Windows: Need queue_private.h
800811
#define DISPATCH_QUEUE_OVERCOMMIT 2
@@ -855,7 +866,6 @@ CF_INLINE long qos_class_main() {
855866
CF_INLINE long qos_class_self() {
856867
return QOS_CLASS_DEFAULT;
857868
}
858-
859869
#endif
860870

861871
// Returns a generic dispatch queue for when you want to just throw some work

CoreFoundation/Base.subproj/CFLogUtilities.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
CF_EXTERN_C_BEGIN
2626

2727

28-
enum { // Legal level values for CFLog()
28+
typedef CF_ENUM(int32_t, CFLogLevel) { // Legal level values for CFLog()
2929
kCFLogLevelEmergency = 0,
3030
kCFLogLevelAlert = 1,
3131
kCFLogLevelCritical = 2,
@@ -36,7 +36,7 @@ enum { // Legal level values for CFLog()
3636
kCFLogLevelDebug = 7,
3737
};
3838

39-
CF_EXPORT void CFLog(int32_t level, CFStringRef format, ...);
39+
CF_EXPORT void CFLog(CFLogLevel level, CFStringRef format, ...);
4040
/* Passing in a level value which is outside the range of 0-7 will cause the the call to do nothing.
4141
CFLog() logs the message using the asl.h API, and uses the level parameter as the log level.
4242
Note that the asl subsystem ignores some log levels by default.
@@ -45,6 +45,10 @@ CF_EXPORT void CFLog(int32_t level, CFStringRef format, ...);
4545
If you care about performance, you shouldn't be logging.
4646
*/
4747

48+
#if DEPLOYMENT_RUNTIME_SWIFT
49+
CF_EXPORT void CFLog1(CFLogLevel lev, CFStringRef message);
50+
#endif
51+
4852
CF_EXTERN_C_END
4953

5054
#endif /* ! __COREFOUNDATION_CFLOGUTILITIES__ */

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ CF_PRIVATE void __CFFinalizeWindowsThreadData() {
563563
#endif
564564

565565

566-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX
566+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
567567
static pthread_key_t __CFTSDIndexKey;
568568
#endif
569569

@@ -1062,7 +1062,7 @@ CF_PRIVATE int _NS_gettimeofday(struct timeval *tv, struct timezone *tz) {
10621062
#pragma mark -
10631063
#pragma mark Linux OSAtomic
10641064

1065-
#if DEPLOYMENT_TARGET_LINUX
1065+
#if defined(DEPLOYMENT_TARGET_LINUX) || defined(DEPLOYMENT_TARGET_FREEBSD)
10661066

10671067
bool OSAtomicCompareAndSwapPtr(void *oldp, void *newp, void *volatile *dst)
10681068
{
@@ -1272,6 +1272,18 @@ int _CFOpenFile(const char *path, int opts) {
12721272
}
12731273
#endif
12741274

1275+
#if DEPLOYMENT_RUNTIME_SWIFT
1276+
CF_PRIVATE char **_CFEnviron(void) {
1277+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
1278+
return *_NSGetEnviron();
1279+
#elif DEPLOYMENT_TARGET_WINDOWS
1280+
return _environ;
1281+
#else
1282+
return environ;
1283+
#endif
1284+
}
1285+
#endif
1286+
12751287
void *_CFReallocf(void *ptr, size_t size) {
12761288
#if DEPLOYMENT_TARGET_WINDOWS | DEPLOYMENT_TARGET_LINUX
12771289
void *mem = realloc(ptr, size);

CoreFoundation/Base.subproj/CFPriv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,9 @@ CF_EXPORT CFMessagePortRef _CFMessagePortCreateLocalEx(CFAllocatorRef allocator,
563563

564564
#endif
565565

566-
#if TARGET_OS_MAC || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_LINUX
566+
#if TARGET_OS_MAC || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
567567
#include <pthread.h>
568-
#else
568+
#elif !TARGET_OS_LINUX
569569
// Avoid including the pthread header
570570
#ifndef HAVE_STRUCT_TIMESPEC
571571
#define HAVE_STRUCT_TIMESPEC 1

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ __kCFReleaseEvent = 29
5555

5656
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
5757
#include <malloc.h>
58+
#elif DEPLOYMENT_TARGET_FREEBSD
59+
#include <stdlib.h> // malloc()
5860
#else
5961
#include <malloc/malloc.h>
6062
#endif
@@ -484,7 +486,7 @@ enum {
484486
#if DEPLOYMENT_TARGET_MACOSX
485487
#define NUM_EXTERN_TABLES 8
486488
#define EXTERN_TABLE_IDX(O) (((uintptr_t)(O) >> 8) & 0x7)
487-
#elif DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
489+
#elif DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
488490
#define NUM_EXTERN_TABLES 1
489491
#define EXTERN_TABLE_IDX(O) 0
490492
#else
@@ -722,11 +724,7 @@ static CFLock_t __CFRuntimeExternRefCountTableLock = CFLockInit;
722724
#endif
723725

724726
#if DEPLOYMENT_RUNTIME_SWIFT
725-
CFIndex CFGetRetainCount(CFTypeRef cf) {
726-
extern size_t swift_retainCount(void *object);
727-
// size_t and CFIndex aren't really the same, but you are already playing with fire by calling this function.
728-
return (CFIndex)swift_retainCount((void *)cf);
729-
}
727+
// using CFGetRetainCount is very dangerous; there is no real reason to use it in the swift version of CF.
730728
#else
731729
static uint64_t __CFGetFullRetainCount(CFTypeRef cf) {
732730
if (NULL == cf) { CRSetCrashLogMessage("*** __CFGetFullRetainCount() called with NULL ***"); HALT; }
@@ -988,7 +986,7 @@ CF_PRIVATE Boolean __CFInitialized = 0;
988986
// move the next 2 lines down into the #if below, and make it static, after Foundation gets off this symbol on other platforms
989987
CF_EXPORT pthread_t _CFMainPThread;
990988
pthread_t _CFMainPThread = kNilPthreadT;
991-
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_IPHONESIMULATOR
989+
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_IPHONESIMULATOR || DEPLOYMENT_TARGET_LINUX
992990

993991
CF_EXPORT pthread_t _CF_pthread_main_thread_np(void);
994992
pthread_t _CF_pthread_main_thread_np(void) {
@@ -1137,7 +1135,7 @@ void __CFInitialize(void) {
11371135
#if (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI) && !DEPLOYMENT_RUNTIME_SWIFT
11381136
CFMachPortGetTypeID();
11391137
#endif
1140-
#if (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS) && !DEPLOYMENT_RUNTIME_SWIFT
1138+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
11411139
__CFStreamInitialize();
11421140
#endif
11431141
#if DEPLOYMENT_TARGET_WINDOWS
@@ -1161,6 +1159,7 @@ void __CFInitialize(void) {
11611159
#endif
11621160
#endif
11631161
#if DEPLOYMENT_RUNTIME_SWIFT
1162+
_CFKeyedArchiverUIDGetTypeID();
11641163
#ifndef __CFInitializeSwift
11651164
#if TARGET_OS_LINUX
11661165
#define __CFInitializeSwift _TF10Foundation19__CFInitializeSwiftFT_T_
@@ -1171,6 +1170,7 @@ void __CFInitialize(void) {
11711170
extern void __CFInitializeSwift();
11721171
__CFInitializeSwift();
11731172
#endif
1173+
__CFNumberInitialize(); /* needs to happen after Swift bridge is initialized */
11741174
{
11751175
CFIndex idx, cnt = 0;
11761176
char **args = NULL;
@@ -1811,8 +1811,11 @@ const char *_NSPrintForDebugger(void *cf) {
18111811
#if DEPLOYMENT_RUNTIME_SWIFT
18121812

18131813
// For CF functions with 'Get' semantics, the compiler currently assumes that the result is autoreleased and must be retained. It does so on all platforms by emitting a call to objc_retainAutoreleasedReturnValue. On Darwin, this is implemented by the ObjC runtime. On Linux, there is no runtime, and therefore we have to stub it out here ourselves. The compiler will eventually call swift_release to balance the retain below. This is a workaround until the compiler no longer emits this callout on Linux.
1814-
CFTypeRef objc_retainAutoreleasedReturnValue(CFTypeRef cf) {
1815-
if (cf) return CFRetain(cf);
1814+
void * objc_retainAutoreleasedReturnValue(void *obj) {
1815+
if (obj) {
1816+
swift_retain(obj);
1817+
return obj;
1818+
}
18161819
else return NULL;
18171820
}
18181821

CoreFoundation/Base.subproj/CFUUID.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ CFUUIDRef CFUUIDCreate(CFAllocatorRef alloc) {
271271
long rStatus = UuidCreate(&u);
272272
if (RPC_S_OK != rStatus && RPC_S_UUID_LOCAL_ONLY != rStatus) retval = 1;
273273
memmove(&bytes, &u, sizeof(bytes));
274-
#elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
274+
#elif DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_LINUX
275275
static Boolean useV1UUIDs = false, checked = false;
276276
uuid_t uuid;
277277
if (!checked) {

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,13 @@ static CFStringRef copySystemVersionPath(CFStringRef suffix) {
309309
if (!simulatorRoot) simulatorRoot = "/";
310310
return CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("%s%@"), simulatorRoot, suffix);
311311
#else
312-
return suffix;
312+
return CFStringCreateCopy(kCFAllocatorSystemDefault, suffix);
313313
#endif
314314
}
315315

316316

317317
CFDictionaryRef _CFCopySystemVersionDictionary(void) {
318+
// TODO: Populate this dictionary differently on non-Darwin platforms
318319
CFStringRef path = copySystemVersionPath(CFSTR("/System/Library/CoreServices/SystemVersion.plist"));
319320
CFPropertyListRef plist = _CFCopyVersionDictionary(path);
320321
CFRelease(path);
@@ -605,7 +606,7 @@ static void __CFLogCString(int32_t lev, const char *message, size_t length, char
605606
char *uid = NULL;
606607
int bannerLen;
607608
bannerLen = 0;
608-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
609+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
609610
// The banner path may use CF functions, but the rest of this function should not. It may be called at times when CF is not fully setup or torn down.
610611
if (withBanner) {
611612
double dummy;
@@ -753,14 +754,19 @@ CF_PRIVATE void _CFLogSimple(int32_t lev, char *format, ...) {
753754
va_end(args);
754755
}
755756

756-
void CFLog(int32_t lev, CFStringRef format, ...) {
757+
void CFLog(CFLogLevel lev, CFStringRef format, ...) {
757758
va_list args;
758759
va_start(args, format);
759760
_CFLogvEx3(NULL, NULL, NULL, NULL, lev, format, args, __builtin_return_address(0));
760761
va_end(args);
761762
}
762763

763-
764+
#if DEPLOYMENT_RUNTIME_SWIFT
765+
// Temporary as Swift cannot import varag C functions
766+
void CFLog1(CFLogLevel lev, CFStringRef message) {
767+
CFLog(lev, CFSTR("%@"), message);
768+
}
769+
#endif
764770

765771
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
766772

@@ -1081,7 +1087,7 @@ CF_PRIVATE Boolean _CFReadMappedFromFile(CFStringRef path, Boolean map, Boolean
10811087
if (0LL == statBuf.st_size) {
10821088
bytes = malloc(8); // don't return constant string -- it's freed!
10831089
length = 0;
1084-
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX
1090+
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
10851091
} else if (map) {
10861092
if((void *)-1 == (bytes = mmap(0, (size_t)statBuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0))) {
10871093
int32_t savederrno = errno;
@@ -1255,6 +1261,9 @@ CFDictionaryRef __CFGetEnvironment() {
12551261
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
12561262
extern char ***_NSGetEnviron();
12571263
char **envp = *_NSGetEnviron();
1264+
#elif DEPLOYMENT_TARGET_FREEBSD
1265+
extern char **environ;
1266+
char **envp = environ;
12581267
#elif DEPLOYMENT_TARGET_LINUX
12591268
#ifndef environ
12601269
#define environ __environ

0 commit comments

Comments
 (0)