diff --git a/CoreFoundation/Base.subproj/CFBase.h b/CoreFoundation/Base.subproj/CFBase.h index 0dc06b1e76..34ca2f80e9 100644 --- a/CoreFoundation/Base.subproj/CFBase.h +++ b/CoreFoundation/Base.subproj/CFBase.h @@ -683,8 +683,7 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE; #if DEPLOYMENT_RUNTIME_SWIFT #define _CF_SWIFT_RC_PINNED_FLAG 0x1 -#define _CF_SWIFT_RC_FLAGS_COUNT 2 -#define _CF_CONSTANT_OBJECT_STRONG_RC ((1 << _CF_SWIFT_RC_FLAGS_COUNT) | _CF_SWIFT_RC_PINNED_FLAG) +#define _CF_CONSTANT_OBJECT_STRONG_RC (_CF_SWIFT_RC_PINNED_FLAG) #endif diff --git a/CoreFoundation/Base.subproj/CFInternal.h b/CoreFoundation/Base.subproj/CFInternal.h index 6cf37b3839..ccc58ee68f 100644 --- a/CoreFoundation/Base.subproj/CFInternal.h +++ b/CoreFoundation/Base.subproj/CFInternal.h @@ -412,11 +412,11 @@ CF_EXPORT void *__CFConstantStringClassReference[]; #endif #define CONST_STRING_DECL(S, V) \ -const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \ +const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \ const CFStringRef S = (CFStringRef)&__##S; #define PE_CONST_STRING_DECL(S, V) \ -const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \ +const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \ CF_PRIVATE const CFStringRef S = (CFStringRef)&__##S; diff --git a/CoreFoundation/Base.subproj/CFRuntime.c b/CoreFoundation/Base.subproj/CFRuntime.c index da9d2c0d09..386770b241 100644 --- a/CoreFoundation/Base.subproj/CFRuntime.c +++ b/CoreFoundation/Base.subproj/CFRuntime.c @@ -387,7 +387,7 @@ CFTypeRef _CFRuntimeCreateInstance(CFAllocatorRef allocator, CFTypeID typeID, CF CFRuntimeBase *memory = (CFRuntimeBase *)swift_allocObject(isa, size, align - 1); // Zero the rest of the memory, starting at cfinfo - memset(&memory->_cfinfoa, 0, size - (sizeof(memory->_cfisa) + sizeof(memory->_swift_strong_rc) + sizeof(memory->_swift_weak_rc))); + memset(&memory->_cfinfoa, 0, size - (sizeof(memory->_cfisa) + sizeof(memory->_swift_rc))); // Set up the cfinfo struct uint32_t *cfinfop = (uint32_t *)&(memory->_cfinfoa); diff --git a/CoreFoundation/Base.subproj/CFRuntime.h b/CoreFoundation/Base.subproj/CFRuntime.h index d7aa26cfc9..84a056505f 100644 --- a/CoreFoundation/Base.subproj/CFRuntime.h +++ b/CoreFoundation/Base.subproj/CFRuntime.h @@ -193,13 +193,12 @@ CF_EXPORT void _CFRuntimeUnregisterClassWithTypeID(CFTypeID typeID); typedef struct __CFRuntimeBase { // This matches the isa and retain count storage in Swift uintptr_t _cfisa; - uint32_t _swift_strong_rc; - uint32_t _swift_weak_rc; + uintptr_t _swift_rc; // This is for CF's use, and must match _NSCFType layout _Atomic(uint64_t) _cfinfoa; } CFRuntimeBase; -#define INIT_CFRUNTIME_BASE(...) {0, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x0000000000000080ULL} +#define INIT_CFRUNTIME_BASE(...) {0, _CF_CONSTANT_OBJECT_STRONG_RC, 0x0000000000000080ULL} #else diff --git a/CoreFoundation/String.subproj/CFString.c b/CoreFoundation/String.subproj/CFString.c index b1f4fa3633..a71d96ca3a 100644 --- a/CoreFoundation/String.subproj/CFString.c +++ b/CoreFoundation/String.subproj/CFString.c @@ -245,7 +245,7 @@ CF_INLINE void __CFStrClearHasLengthAndNullBytes(CFMutableStringRef str) { CF_INLINE Boolean __CFStrIsConstant(CFStringRef str) { #if DEPLOYMENT_RUNTIME_SWIFT - return str->base._swift_strong_rc & _CF_SWIFT_RC_PINNED_FLAG; + return str->base._swift_rc & _CF_SWIFT_RC_PINNED_FLAG; #else return __CFRuntimeIsConstant(str); #endif diff --git a/CoreFoundation/String.subproj/CFString.h b/CoreFoundation/String.subproj/CFString.h index 2793bfbe24..d818f2ae27 100644 --- a/CoreFoundation/String.subproj/CFString.h +++ b/CoreFoundation/String.subproj/CFString.h @@ -155,8 +155,7 @@ since it is the default choice with Mac OS X developer tools. struct __CFConstStr { struct { uintptr_t _cfisa; - uint32_t _swift_strong_rc; - uint32_t _swift_weak_rc; + uintptr_t _swift_rc; uint64_t _cfinfoa; } _base; uint8_t *_ptr; @@ -175,12 +174,12 @@ struct __CFConstStr { #if __BIG_ENDIAN__ #define CFSTR(cStr) ({ \ - static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \ + static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \ (CFStringRef)&str; \ }) #else #define CFSTR(cStr) ({ \ - static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \ + static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \ (CFStringRef)&str; \ }) #endif diff --git a/Foundation/NSCFString.swift b/Foundation/NSCFString.swift index 92177ca9e5..638de7e449 100644 --- a/Foundation/NSCFString.swift +++ b/Foundation/NSCFString.swift @@ -61,9 +61,8 @@ internal final class _NSCFConstantString : _NSCFString { internal var _ptr : UnsafePointer { // FIXME: Split expression as a work-around for slow type // checking (tracked by SR-5322). - let offTemp1 = MemoryLayout.size + MemoryLayout.size - let offTemp2 = MemoryLayout.size + MemoryLayout<_CFInfo>.size - let offset = offTemp1 + offTemp2 + let offTemp1 = MemoryLayout.size + MemoryLayout.size + let offset = offTemp1 + MemoryLayout<_CFInfo>.size let ptr = Unmanaged.passUnretained(self).toOpaque() return ptr.load(fromByteOffset: offset, as: UnsafePointer.self) } @@ -71,8 +70,8 @@ internal final class _NSCFConstantString : _NSCFString { private var _lenOffset : Int { // FIXME: Split expression as a work-around for slow type // checking (tracked by SR-5322). - let offTemp1 = MemoryLayout.size + MemoryLayout.size - let offTemp2 = MemoryLayout.size + MemoryLayout<_CFInfo>.size + let offTemp1 = MemoryLayout.size + MemoryLayout.size + let offTemp2 = MemoryLayout<_CFInfo>.size return offTemp1 + offTemp2 + MemoryLayout>.size }