Skip to content

The Monterey Merge #3058

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 6 commits into from
Sep 10, 2021
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
9 changes: 9 additions & 0 deletions CoreFoundation/AppServices.subproj/CFUserNotification.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static void _CFUserNotificationMachPortCallBack(CFMachPortRef port, void *m, CFI
}

SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification, CFTimeInterval timeout, CFOptionFlags *responseFlags) {
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
CHECK_FOR_FORK();
SInt32 retval = ERR_SUCCESS;
mach_msg_timeout_t msgtime = (timeout > 0.0 && 1000.0 * timeout < INT_MAX) ? (mach_msg_timeout_t)(1000.0 * timeout) : 0;
Expand Down Expand Up @@ -343,11 +344,15 @@ SInt32 CFUserNotificationReceiveResponse(CFUserNotificationRef userNotification,
}

CFStringRef CFUserNotificationGetResponseValue(CFUserNotificationRef userNotification, CFStringRef key, CFIndex idx) {
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
CHECK_FOR_FORK();
CFStringRef retval = NULL;
CFTypeRef value = NULL;
if (userNotification && userNotification->_responseDictionary) {
value = CFDictionaryGetValue(userNotification->_responseDictionary, key);
if (value == NULL) {
return NULL;
}
if (CFGetTypeID(value) == CFStringGetTypeID()) {
if (0 == idx) retval = (CFStringRef)value;
} else if (CFGetTypeID(value) == CFArrayGetTypeID()) {
Expand All @@ -358,11 +363,13 @@ CFStringRef CFUserNotificationGetResponseValue(CFUserNotificationRef userNotific
}

CFDictionaryRef CFUserNotificationGetResponseDictionary(CFUserNotificationRef userNotification) {
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
CHECK_FOR_FORK();
return userNotification ? userNotification->_responseDictionary : NULL;
}

SInt32 CFUserNotificationUpdate(CFUserNotificationRef userNotification, CFTimeInterval timeout, CFOptionFlags flags, CFDictionaryRef dictionary) {
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
CHECK_FOR_FORK();
SInt32 retval = ERR_SUCCESS;
if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) {
Expand All @@ -373,6 +380,7 @@ SInt32 CFUserNotificationUpdate(CFUserNotificationRef userNotification, CFTimeIn
}

SInt32 CFUserNotificationCancel(CFUserNotificationRef userNotification) {
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
CHECK_FOR_FORK();
SInt32 retval = ERR_SUCCESS;
if (userNotification && MACH_PORT_NULL != userNotification->_replyPort) {
Expand All @@ -383,6 +391,7 @@ SInt32 CFUserNotificationCancel(CFUserNotificationRef userNotification) {
}

CFRunLoopSourceRef CFUserNotificationCreateRunLoopSource(CFAllocatorRef allocator, CFUserNotificationRef userNotification, CFUserNotificationCallBack callout, CFIndex order) {
CF_ASSERT_TYPE_OR_NULL(_kCFRuntimeIDCFUserNotification, userNotification);
CHECK_FOR_FORK();
CFRunLoopSourceRef source = NULL;
if (userNotification && callout && !userNotification->_machPort && MACH_PORT_NULL != userNotification->_replyPort) {
Expand Down
6 changes: 3 additions & 3 deletions CoreFoundation/Base.subproj/CFAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@
#define __CF_ENUM_FIXED_IS_AVAILABLE (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && (__has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum)))

#if __CF_ENUM_FIXED_IS_AVAILABLE
#define __CF_NAMED_ENUM(_type, _name) int __CF_ENUM_ ## _name; enum __CF_ENUM_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type
#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_CLOSED_ENUM(_type, _name) int __CF_ENUM_ ## _name; enum __CF_CLOSED_ENUM_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type
#define CF_CLOSED_ENUM(_type, _name) enum __CF_CLOSED_ENUM_ATTRIBUTES _name : _type _name; enum _name : _type
#if (__cplusplus)
#define CF_OPTIONS(_type, _name) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _type
#else
#define CF_OPTIONS(_type, _name) int __CF_OPTIONS_ ## _name; enum __CF_OPTIONS_ATTRIBUTES _name : _type; typedef enum _name _name; enum _name : _type
#define CF_OPTIONS(_type, _name) enum __CF_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to revert these macro patches when building for Android, finagolfin/swift-android-sdk@dba89d2, or building CoreFoundation fails with this error:

error: non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators? [-Welaborated-enum-base]

I checked the preprocessed source produced with and without these macro changes and got the following diff:

--- a/cf.i	2021-09-16 07:54:13.941791291 +0000
+++ b/cf.i	2021-09-16 08:08:32.447061538 +0000
@@ -199,7 +199,7 @@
 typedef __attribute__((objc_bridge(id))) CFTypeRef CFPropertyListRef;
 
 
-typedef int __CF_ENUM_CFComparisonResult; enum __attribute__((enum_extensibility(open))) CFComparisonResult : CFIndex; typedef enum CFComparisonResult CFComparisonResult; enum CFComparisonResult : CFIndex {
+typedef enum __attribute__((enum_extensibility(open))) CFComparisonResult : CFIndex CFComparisonResult; enum CFComparisonResult : CFIndex {
     kCFCompareLessThan = -1L,
     kCFCompareEqualTo = 0,
     kCFCompareGreaterThan = 1

I don't know what to make of that C gibberish so if anybody else knows how to fix it, I'd appreciate it.

#endif
#else
#define __CF_NAMED_ENUM(_type, _name) _type _name; enum
Expand Down
39 changes: 20 additions & 19 deletions CoreFoundation/Base.subproj/CFBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct __CFAllocator {
};

CF_INLINE uintptr_t __CFISAForCFAllocator(void) {
return __CFRuntimeObjCClassTable[_kCFRuntimeIDCFAllocator];
return _GetCFRuntimeObjcClassAtIndex(_kCFRuntimeIDCFAllocator);
}

CF_INLINE CFAllocatorRetainCallBack __CFAllocatorGetRetainFunction(const CFAllocatorContext *context) {
Expand Down Expand Up @@ -478,7 +478,7 @@ void CFAllocatorSetDefault(CFAllocatorRef allocator) {
}
#endif
#if TARGET_OS_MAC
if (allocator && allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (allocator && _CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return; // require allocator to this function to be an allocator
}
#endif
Expand All @@ -505,7 +505,7 @@ static CFAllocatorRef __CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorC
CFAllocatorAllocateCallBack allocateFunc;
void *retainedInfo;
#if TARGET_OS_MAC
if (allocator && kCFAllocatorUseContext != allocator && allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (allocator && kCFAllocatorUseContext != allocator && _CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return NULL; // require allocator to this function to be an allocator
}
#endif
Expand Down Expand Up @@ -588,15 +588,15 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
}

#if defined(DEBUG) && TARGET_OS_MAC
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
}
#else
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
#endif
if (0 == size) return NULL;
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return malloc_zone_malloc((malloc_zone_t *)allocator, size);
}
#endif
Expand All @@ -619,15 +619,15 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
}

#if defined(DEBUG) && TARGET_OS_MAC
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
}
#else
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
#endif
if (NULL == ptr && 0 < newsize) {
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return malloc_zone_malloc((malloc_zone_t *)allocator, newsize);
}
#endif
Expand All @@ -640,7 +640,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
}
if (NULL != ptr && 0 == newsize) {
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
#if defined(DEBUG)
size_t size = malloc_size(ptr);
if (size) memset(ptr, 0xCC, size);
Expand All @@ -657,7 +657,7 @@ void *CFAllocatorReallocate(CFAllocatorRef allocator, void *ptr, CFIndex newsize
}
if (NULL == ptr && 0 == newsize) return NULL;
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return malloc_zone_realloc((malloc_zone_t *)allocator, ptr, newsize);
}
#endif
Expand All @@ -675,14 +675,14 @@ void CFAllocatorDeallocate(CFAllocatorRef allocator, void *ptr) {
}

#if defined(DEBUG) && TARGET_OS_MAC
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
}
#else
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
#endif
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
#if defined(DEBUG)
size_t size = malloc_size(ptr);
if (size) memset(ptr, 0xCC, size);
Expand All @@ -704,15 +704,15 @@ CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex siz
allocator = __CFGetDefaultAllocator();
}

#if defined(DEBUG) && TARGET_OS_MAC
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
#if TARGET_OS_MAC
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
}
#else
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
#endif
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return malloc_good_size(size);
}
#endif
Expand All @@ -729,16 +729,16 @@ void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context
allocator = __CFGetDefaultAllocator();
}

#if defined(DEBUG) && TARGET_OS_MAC
if (allocator->_base._cfisa == __CFISAForCFAllocator()) {
#if TARGET_OS_MAC
if (_CFTypeGetClass(allocator) == __CFISAForCFAllocator()) {
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
}
#else
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
#endif
CFAssert1(0 == context->version, __kCFLogAssertion, "%s(): context version not initialized to 0", __PRETTY_FUNCTION__);
#if TARGET_OS_MAC
if (allocator->_base._cfisa != __CFISAForCFAllocator()) { // malloc_zone_t *
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
return;
}
#endif
Expand Down Expand Up @@ -808,7 +808,7 @@ struct __CFNull {

DECLARE_STATIC_CLASS_REF(NSNull);

static struct __CFNull _CF_CONSTANT_OBJECT_BACKING __kCFNull = {
struct __CFNull _CF_CONSTANT_OBJECT_BACKING __kCFNull = {
INIT_CFRUNTIME_BASE_WITH_CLASS(NSNull, _kCFRuntimeIDCFNull)
};
const CFNullRef kCFNull = &__kCFNull;
Expand Down Expand Up @@ -853,7 +853,8 @@ void _CFRuntimeSetCFMPresent(void *addr) {
/* Keep this assembly at the bottom of the source file! */


extern void __HALT() {
extern void __HALT(void);
void __HALT() {
__builtin_trap();
}

Expand Down
22 changes: 22 additions & 0 deletions CoreFoundation/Base.subproj/CFBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#if !defined(__COREFOUNDATION_CFBASE__)
#define __COREFOUNDATION_CFBASE__ 1

#if __has_include(<CoreFoundation/TargetConditionals.h>)
#include <CoreFoundation/TargetConditionals.h>
#else
#include <TargetConditionals.h>
#endif

#include <CoreFoundation/CFAvailability.h>

#if (defined(__CYGWIN32__) || defined(_WIN32)) && !defined(__WIN32__)
Expand Down Expand Up @@ -690,6 +695,23 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
#define _CF_CONSTANT_OBJECT_STRONG_RC ((uintptr_t)_CF_SWIFT_RC_PINNED_FLAG)
#endif

#if __has_include(<ptrauth.h>)
#include <ptrauth.h>
#endif

#ifndef __ptrauth_objc_isa_pointer
#define __ptrauth_objc_isa_pointer
#endif

#define ISA_PTRAUTH_DISCRIMINATOR 0x6AE1
#if defined(__ptrauth_objc_isa_uintptr)
#define __ptrauth_cf_objc_isa_pointer __ptrauth_objc_isa_uintptr
#elif defined(__arm64e__) && defined(__PTRAUTH_INTRINSICS__) && __has_feature(ptrauth_objc_isa)
#define __ptrauth_cf_objc_isa_pointer __ptrauth_restricted_intptr(ptrauth_key_objc_isa_pointer, 1, ISA_PTRAUTH_DISCRIMINATOR)
#else
#define __ptrauth_cf_objc_isa_pointer
#endif

CF_EXTERN_C_END

#endif /* ! __COREFOUNDATION_CFBASE__ */
Expand Down
7 changes: 7 additions & 0 deletions CoreFoundation/Base.subproj/CFFileUtilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
}
}

#if TARGET_OS_MAC
struct dirent buffer;
#endif
struct dirent *dp;
int err;

Expand All @@ -387,7 +390,11 @@ CF_PRIVATE CFMutableArrayRef _CFCreateContentsOfDirectory(CFAllocatorRef alloc,
}
files = CFArrayCreateMutable(alloc, 0, & kCFTypeArrayCallBacks);

#if TARGET_OS_MAC
while((0 == readdir_r(dirp, &buffer, &dp)) && dp) {
#else
while((dp = readdir(dirp))) {
#endif
CFURLRef fileURL;
unsigned namelen = strlen(dp->d_name);

Expand Down
Loading