Skip to content

Commit 1086b3b

Browse files
committed
Cater for new Swift reference count representation
1 parent 76995e8 commit 1086b3b

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

CoreFoundation/Base.subproj/CFBase.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,7 @@ CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE;
683683
#if DEPLOYMENT_RUNTIME_SWIFT
684684

685685
#define _CF_SWIFT_RC_PINNED_FLAG 0x1
686-
#define _CF_SWIFT_RC_FLAGS_COUNT 2
687-
#define _CF_CONSTANT_OBJECT_STRONG_RC ((1 << _CF_SWIFT_RC_FLAGS_COUNT) | _CF_SWIFT_RC_PINNED_FLAG)
686+
#define _CF_CONSTANT_OBJECT_STRONG_RC (_CF_SWIFT_RC_PINNED_FLAG)
688687

689688
#endif
690689

CoreFoundation/Base.subproj/CFInternal.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ CF_EXPORT void *__CFConstantStringClassReference[];
412412
#endif
413413

414414
#define CONST_STRING_DECL(S, V) \
415-
const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \
415+
const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \
416416
const CFStringRef S = (CFStringRef)&__##S;
417417

418418
#define PE_CONST_STRING_DECL(S, V) \
419-
const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \
419+
const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x000007c8U}, (uint8_t *)(V), sizeof(V) - 1}; \
420420
CF_PRIVATE const CFStringRef S = (CFStringRef)&__##S;
421421

422422

CoreFoundation/Base.subproj/CFRuntime.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ CFTypeRef _CFRuntimeCreateInstance(CFAllocatorRef allocator, CFTypeID typeID, CF
387387
CFRuntimeBase *memory = (CFRuntimeBase *)swift_allocObject(isa, size, align - 1);
388388

389389
// Zero the rest of the memory, starting at cfinfo
390-
memset(&memory->_cfinfoa, 0, size - (sizeof(memory->_cfisa) + sizeof(memory->_swift_strong_rc) + sizeof(memory->_swift_weak_rc)));
390+
memset(&memory->_cfinfoa, 0, size - (sizeof(memory->_cfisa) + sizeof(memory->_swift_rc)));
391391

392392
// Set up the cfinfo struct
393393
uint32_t *cfinfop = (uint32_t *)&(memory->_cfinfoa);

CoreFoundation/Base.subproj/CFRuntime.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,12 @@ CF_EXPORT void _CFRuntimeUnregisterClassWithTypeID(CFTypeID typeID);
193193
typedef struct __CFRuntimeBase {
194194
// This matches the isa and retain count storage in Swift
195195
uintptr_t _cfisa;
196-
uint32_t _swift_strong_rc;
197-
uint32_t _swift_weak_rc;
196+
uintptr_t _swift_rc;
198197
// This is for CF's use, and must match _NSCFType layout
199198
_Atomic(uint64_t) _cfinfoa;
200199
} CFRuntimeBase;
201200

202-
#define INIT_CFRUNTIME_BASE(...) {0, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x0000000000000080ULL}
201+
#define INIT_CFRUNTIME_BASE(...) {0, _CF_CONSTANT_OBJECT_STRONG_RC, 0x0000000000000080ULL}
203202

204203
#else
205204

CoreFoundation/String.subproj/CFString.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ CF_INLINE void __CFStrClearHasLengthAndNullBytes(CFMutableStringRef str) {
245245

246246
CF_INLINE Boolean __CFStrIsConstant(CFStringRef str) {
247247
#if DEPLOYMENT_RUNTIME_SWIFT
248-
return str->base._swift_strong_rc & _CF_SWIFT_RC_PINNED_FLAG;
248+
return str->base._swift_rc & _CF_SWIFT_RC_PINNED_FLAG;
249249
#else
250250
return __CFRuntimeIsConstant(str);
251251
#endif

CoreFoundation/String.subproj/CFString.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ since it is the default choice with Mac OS X developer tools.
155155
struct __CFConstStr {
156156
struct {
157157
uintptr_t _cfisa;
158-
uint32_t _swift_strong_rc;
159-
uint32_t _swift_weak_rc;
158+
uintptr_t _swift_rc;
160159
uint64_t _cfinfoa;
161160
} _base;
162161
uint8_t *_ptr;
@@ -175,12 +174,12 @@ struct __CFConstStr {
175174

176175
#if __BIG_ENDIAN__
177176
#define CFSTR(cStr) ({ \
178-
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
177+
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
179178
(CFStringRef)&str; \
180179
})
181180
#else
182181
#define CFSTR(cStr) ({ \
183-
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
182+
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
184183
(CFStringRef)&str; \
185184
})
186185
#endif

Foundation/NSCFString.swift

+4-5
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ internal final class _NSCFConstantString : _NSCFString {
6161
internal var _ptr : UnsafePointer<UInt8> {
6262
// FIXME: Split expression as a work-around for slow type
6363
// checking (tracked by SR-5322).
64-
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size
65-
let offTemp2 = MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
66-
let offset = offTemp1 + offTemp2
64+
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<uintptr_t>.size
65+
let offset = offTemp1 + MemoryLayout<_CFInfo>.size
6766
let ptr = Unmanaged.passUnretained(self).toOpaque()
6867
return ptr.load(fromByteOffset: offset, as: UnsafePointer<UInt8>.self)
6968
}
7069

7170
private var _lenOffset : Int {
7271
// FIXME: Split expression as a work-around for slow type
7372
// checking (tracked by SR-5322).
74-
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<Int32>.size
75-
let offTemp2 = MemoryLayout<Int32>.size + MemoryLayout<_CFInfo>.size
73+
let offTemp1 = MemoryLayout<OpaquePointer>.size + MemoryLayout<uintptr_t>.size
74+
let offTemp2 = MemoryLayout<_CFInfo>.size
7675
return offTemp1 + offTemp2 + MemoryLayout<UnsafePointer<UInt8>>.size
7776
}
7877

0 commit comments

Comments
 (0)