Skip to content

Commit 2338aaf

Browse files
committed
The Ventura Core Foundation Merge
1 parent a9bf8d5 commit 2338aaf

File tree

110 files changed

+42021
-3882
lines changed

Some content is hidden

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

110 files changed

+42021
-3882
lines changed

CoreFoundation/AppServices.subproj/CFUserNotification.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct __CFUserNotification {
7676
CFOptionFlags _responseFlags;
7777
CFStringRef _sessionID;
7878
CFDictionaryRef _responseDictionary;
79-
CFMachPortRef _machPort;
79+
_Atomic(CFMachPortRef) _machPort;
8080
CFUserNotificationCallBack _callout;
8181
};
8282

@@ -116,10 +116,10 @@ CFTypeID CFUserNotificationGetTypeID(void) {
116116

117117
static void __CFUserNotificationDeallocate(CFTypeRef cf) {
118118
CFUserNotificationRef userNotification = (CFUserNotificationRef)cf;
119-
if (userNotification->_machPort) {
120-
CFMachPortInvalidate(userNotification->_machPort);
121-
CFRelease(userNotification->_machPort);
122-
userNotification->_machPort = NULL; // NOTE: this is still potentially racey and should probably have a CAS (for now this is just a stop-gap to reduce an already very rare crash potential) <rdar://problem/21077032>
119+
CFMachPortRef port = atomic_exchange(&userNotification->_machPort, NULL);
120+
if (port) {
121+
CFMachPortInvalidate(port);
122+
CFRelease(port);
123123
} else if (MACH_PORT_NULL != userNotification->_replyPort) {
124124
mach_port_mod_refs(mach_task_self(), userNotification->_replyPort, MACH_PORT_RIGHT_RECEIVE, -1);
125125
}
@@ -190,10 +190,10 @@ static SInt32 _CFUserNotificationSendRequest(CFAllocatorRef allocator, CFStringR
190190

191191
#if TARGET_OS_OSX
192192
const char *namebuffer = NOTIFICATION_PORT_NAME_MAC;
193-
const CFIndex nameLen = sizeof(NOTIFICATION_PORT_NAME_MAC);
193+
const nameLen = sizeof(NOTIFICATION_PORT_NAME_MAC);
194194
#else
195195
const char *namebuffer = NOTIFICATION_PORT_NAME_IOS;
196-
const CFIndex nameLen = sizeof(NOTIFICATION_PORT_NAME_IOS);
196+
const nameLen = sizeof(NOTIFICATION_PORT_NAME_IOS);
197197
#endif
198198

199199
if (sessionID) {
@@ -256,7 +256,10 @@ CFUserNotificationRef CFUserNotificationCreate(CFAllocatorRef allocator, CFTimeI
256256
mach_port_t replyPort = MACH_PORT_NULL;
257257

258258
if (!allocator) allocator = __CFGetDefaultAllocator();
259-
retval = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &replyPort);
259+
mach_port_options_t opts = {
260+
.flags = MPO_REPLY_PORT,
261+
};
262+
retval = mach_port_construct(mach_task_self(), &opts, 0, &replyPort);
260263
if (ERR_SUCCESS == retval && MACH_PORT_NULL != replyPort) retval = _CFUserNotificationSendRequest(allocator, sessionID, replyPort, token, timeout, flags, dictionary);
261264
if (ERR_SUCCESS == retval) {
262265
userNotification = (CFUserNotificationRef)_CFRuntimeCreateInstance(allocator, CFUserNotificationGetTypeID(), sizeof(struct __CFUserNotification) - sizeof(CFRuntimeBase), NULL);
@@ -290,9 +293,11 @@ static void _CFUserNotificationMachPortCallBack(CFMachPortRef port, void *m, CFI
290293
CFRelease(responseData);
291294
}
292295
}
293-
CFMachPortInvalidate(userNotification->_machPort);
294-
CFRelease(userNotification->_machPort);
295-
userNotification->_machPort = NULL;
296+
CFMachPortRef mp = atomic_exchange(&userNotification->_machPort, NULL);
297+
if (mp) {
298+
CFMachPortInvalidate(mp);
299+
CFRelease(mp);
300+
}
296301
mach_port_mod_refs(mach_task_self(), userNotification->_replyPort, MACH_PORT_RIGHT_RECEIVE, -1);
297302
userNotification->_replyPort = MACH_PORT_NULL;
298303
userNotification->_callout(userNotification, responseFlags);
@@ -327,10 +332,10 @@ SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification,
327332
CFRelease(responseData);
328333
}
329334
}
330-
if (userNotification->_machPort) {
331-
CFMachPortInvalidate(userNotification->_machPort);
332-
CFRelease(userNotification->_machPort);
333-
userNotification->_machPort = NULL;
335+
CFMachPortRef mp = atomic_exchange(&userNotification->_machPort, NULL);
336+
if (mp) {
337+
CFMachPortInvalidate(mp);
338+
CFRelease(mp);
334339
}
335340
mach_port_mod_refs(mach_task_self(), userNotification->_replyPort, MACH_PORT_RIGHT_RECEIVE, -1);
336341
userNotification->_replyPort = MACH_PORT_NULL;

CoreFoundation/Base.subproj/CFBase.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct __CFAllocator {
5959
};
6060

6161
CF_INLINE uintptr_t __CFISAForCFAllocator(void) {
62-
return _GetCFRuntimeObjcClassAtIndex(_kCFRuntimeIDCFAllocator);
62+
return __CFISAForTypeID(_kCFRuntimeIDCFAllocator);
6363
}
6464

6565
CF_INLINE CFAllocatorRetainCallBack __CFAllocatorGetRetainFunction(const CFAllocatorContext *context) {
@@ -853,8 +853,7 @@ void _CFRuntimeSetCFMPresent(void *addr) {
853853
/* Keep this assembly at the bottom of the source file! */
854854

855855

856-
extern void __HALT(void);
857-
void __HALT() {
856+
extern void __HALT() {
858857
__builtin_trap();
859858
}
860859

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ CF_EXTERN_C_BEGIN
306306
# define CF_SWIFT_NAME(_name)
307307
#endif
308308

309+
#if __has_attribute(__swift_attr__)
310+
# define CF_SWIFT_UNAVAILABLE_FROM_ASYNC(msg) __attribute__((__swift_attr__("@_unavailableFromAsync(message: \"" msg "\")")))
311+
#else
312+
# define CF_SWIFT_UNAVAILABLE_FROM_ASYNC(msg)
313+
#endif
314+
309315
#if __has_attribute(noescape)
310316
#define CF_NOESCAPE __attribute__((noescape))
311317
#else
@@ -324,6 +330,12 @@ CF_EXTERN_C_BEGIN
324330
#define CF_WARN_UNUSED_RESULT
325331
#endif
326332

333+
#if __has_attribute(fallthrough)
334+
#define CF_FALLTHROUGH __attribute__((fallthrough))
335+
#else
336+
#define CF_FALLTHROUGH
337+
#endif
338+
327339
#if !__has_feature(objc_generics_variance)
328340
#ifndef __covariant
329341
#define __covariant

CoreFoundation/Base.subproj/CFFileUtilities.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ static Boolean _CFReadBytesFromPathAndGetFD(CFAllocatorRef alloc, const char *pa
8787
struct statinfo statBuf;
8888

8989
*bytes = NULL;
90-
91-
90+
9291
int no_hang_fd = openAutoFSNoWait();
9392
*fd = open(path, O_RDONLY|extraOpenFlags|CF_OPENFLGS, 0666);
9493

@@ -123,7 +122,7 @@ static Boolean _CFReadBytesFromPathAndGetFD(CFAllocatorRef alloc, const char *pa
123122
desiredLength = maxLength;
124123
}
125124
*bytes = CFAllocatorAllocate(alloc, desiredLength, 0);
126-
if (!bytes) {
125+
if (*bytes == NULL) {
127126
close(*fd);
128127
*fd = -1;
129128
closeAutoFSNoWait(no_hang_fd);
@@ -504,7 +503,13 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
504503
return files;
505504
}
506505

507-
CF_PRIVATE SInt32 _CFGetPathProperties(CFAllocatorRef alloc, char *path, Boolean *exists, SInt32 *posixMode, int64_t *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents) {
506+
CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, Boolean *exists, SInt32 *posixMode, int64_t *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents) {
507+
char path[CFMaxPathSize];
508+
509+
if (!CFURLGetFileSystemRepresentation(pathURL, true, (uint8_t *)path, CFMaxPathLength)) {
510+
return -1;
511+
}
512+
508513
Boolean fileExists;
509514
Boolean isDirectory = false;
510515

@@ -592,17 +597,6 @@ CF_PRIVATE SInt32 _CFGetPathProperties(CFAllocatorRef alloc, char *path, Boolean
592597
return 0;
593598
}
594599

595-
CF_PRIVATE SInt32 _CFGetFileProperties(CFAllocatorRef alloc, CFURLRef pathURL, Boolean *exists, SInt32 *posixMode, int64_t *size, CFDateRef *modTime, SInt32 *ownerID, CFArrayRef *dirContents) {
596-
597-
char path[CFMaxPathSize];
598-
599-
if (!CFURLGetFileSystemRepresentation(pathURL, true, (uint8_t *)path, CFMaxPathLength)) {
600-
return -1;
601-
}
602-
603-
return _CFGetPathProperties(alloc, path, exists, posixMode, size, modTime, ownerID, dirContents);
604-
}
605-
606600
CF_PRIVATE bool _CFURLExists(CFURLRef url) {
607601
Boolean exists = false;
608602
return url && (0 == _CFGetFileProperties(kCFAllocatorSystemDefault, url, &exists, NULL, NULL, NULL, NULL, NULL)) && exists;
@@ -1240,7 +1234,7 @@ static CFStringRef _CFXDGCreateHome(void) {
12401234
}
12411235

12421236
/// a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME.
1243-
CF_CROSS_PLATFORM_EXPORT
1237+
CF_EXPORT_NONOBJC_ONLY
12441238
CFStringRef _CFXDGCreateDataHomePath(void) {
12451239
// $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
12461240
const char *dataHome = __CFgetenv("XDG_DATA_HOME");
@@ -1255,7 +1249,7 @@ CFStringRef _CFXDGCreateDataHomePath(void) {
12551249
}
12561250

12571251
/// a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME.
1258-
CF_CROSS_PLATFORM_EXPORT
1252+
CF_EXPORT_NONOBJC_ONLY
12591253
CFStringRef _CFXDGCreateConfigHomePath(void) {
12601254
// $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.
12611255
const char *configHome = __CFgetenv("XDG_CONFIG_HOME");
@@ -1270,7 +1264,7 @@ CFStringRef _CFXDGCreateConfigHomePath(void) {
12701264
}
12711265

12721266
/// a set of preference ordered base directories relative to which data files should be searched. This set of directories is defined by the environment variable $XDG_DATA_DIRS.
1273-
CF_CROSS_PLATFORM_EXPORT
1267+
CF_EXPORT_NONOBJC_ONLY
12741268
CFArrayRef _CFXDGCreateDataDirectoriesPaths(void) {
12751269
// $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be separated with a colon ':'.
12761270
// If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used.
@@ -1294,7 +1288,7 @@ CFArrayRef _CFXDGCreateDataDirectoriesPaths(void) {
12941288

12951289

12961290
/// a set of preference ordered base directories relative to which configuration files should be searched. This set of directories is defined by the environment variable $XDG_CONFIG_DIRS.
1297-
CF_CROSS_PLATFORM_EXPORT
1291+
CF_EXPORT_NONOBJC_ONLY
12981292
CFArrayRef _CFXDGCreateConfigDirectoriesPaths(void) {
12991293
// $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory. The directories in $XDG_CONFIG_DIRS should be separated with a colon ':'.
13001294
// If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used.
@@ -1316,7 +1310,7 @@ CFArrayRef _CFXDGCreateConfigDirectoriesPaths(void) {
13161310
}
13171311

13181312
/// a single base directory relative to which user-specific non-essential (cached) data should be written. This directory is defined by the environment variable $XDG_CACHE_HOME.
1319-
CF_CROSS_PLATFORM_EXPORT
1313+
CF_EXPORT_NONOBJC_ONLY
13201314
CFStringRef _CFXDGCreateCacheDirectoryPath(void) {
13211315
//$XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used.
13221316
const char *cacheHome = __CFgetenv("XDG_CACHE_HOME");
@@ -1332,7 +1326,7 @@ CFStringRef _CFXDGCreateCacheDirectoryPath(void) {
13321326
}
13331327

13341328
/// a single base directory relative to which user-specific runtime files and other file objects should be placed. This directory is defined by the environment variable $XDG_RUNTIME_DIR.
1335-
CF_CROSS_PLATFORM_EXPORT
1329+
CF_EXPORT_NONOBJC_ONLY
13361330
CFStringRef _CFXDGCreateRuntimeDirectoryPath(void) {
13371331
const char *runtimeDir = __CFgetenv("XDG_RUNTIME_DIR");
13381332
if (runtimeDir && strnlen(runtimeDir, CFMaxPathSize) > 1 && runtimeDir[0] == '/') {

0 commit comments

Comments
 (0)