Skip to content

Commit f1d1bcd

Browse files
committed
Fix endianness issues in Foundation
1 parent df449af commit f1d1bcd

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ CF_PRIVATE Boolean __CFProcessIsRestricted();
363363
CF_EXPORT void * __CFConstantStringClassReferencePtr;
364364
CF_EXPORT void *__CFConstantStringClassReference[];
365365

366+
#if __CF_BIG_ENDIAN__
367+
#define CFINFO {0x00, 0x00, 0x07, 0xc8}
368+
#elif __CF_LITTLE_ENDIAN__
369+
#define CFINFO {0xc8, 0x07, 0x00, 0x00}
370+
#endif
371+
372+
366373
#ifdef __CONSTANT_CFSTRINGS__
367374

368375
#if DEPLOYMENT_RUNTIME_SWIFT
@@ -373,59 +380,53 @@ CF_EXPORT void *__CFConstantStringClassReference[];
373380
#define CONST_STRING_SECTION
374381
#endif
375382

383+
376384
// TODO: Pinned retain count for constants?
377385
#define CONST_STRING_DECL(S, V) \
378-
const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
386+
const struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
379387
const CFStringRef S = (CFStringRef)&__##S;
380388

381389
#define PE_CONST_STRING_DECL(S, V) \
382-
const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
390+
const static struct __CFConstStr __##S CONST_STRING_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
383391
CF_PRIVATE const CFStringRef S = (CFStringRef)&__##S;
384392

393+
385394
#else
386395

387396
#define CONST_STRING_DECL(S, V) \
388-
const struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
397+
const struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
389398
const CFStringRef S = (CFStringRef)&__##S;
390399

391400
#define PE_CONST_STRING_DECL(S, V) \
392-
const static struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
401+
const static struct __CFConstStr __##S = {{(uintptr_t)&__CFConstantStringClassReference, _CFSWIFT_RC_INIT CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
393402
CF_PRIVATE const CFStringRef S = (CFStringRef)&__##S;
394403

404+
395405
#endif
396406

397407
#else
398408

399409
struct CF_CONST_STRING {
400410
CFRuntimeBase _base;
401411
uint8_t *_ptr;
412+
#if defined(__s390x__)
413+
uint64_t _length;
414+
#else
402415
uint32_t _length;
416+
#endif
403417
};
404418

405419
CF_EXPORT int __CFConstantStringClassReference[];
406420

407421
/* CFNetwork also has a copy of the CONST_STRING_DECL macro (for use on platforms without constant string support in cc); please warn cfnetwork-core@group.apple.com of any necessary changes to this macro. -- REW, 1/28/2002 */
408422

409-
#if __CF_BIG_ENDIAN__
410-
411-
#define CONST_STRING_DECL(S, V) \
412-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0x00, 0x00, 0x07, 0xc8}}, (uint8_t *)V, sizeof(V) - 1}; \
413-
const CFStringRef S = (CFStringRef) & __ ## S ## __;
414-
#define PE_CONST_STRING_DECL(S, V) \
415-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0x00, 0x00, 0x07, 0xc8}}, (uint8_t *)V, sizeof(V) - 1}; \
416-
CF_PRIVATE const CFStringRef S = (CFStringRef) & __ ## S ## __;
417-
418-
#elif __CF_LITTLE_ENDIAN__
419-
420423
#define CONST_STRING_DECL(S, V) \
421-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
424+
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
422425
const CFStringRef S = (CFStringRef) & __ ## S ## __;
423426
#define PE_CONST_STRING_DECL(S, V) \
424-
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, {0xc8, 0x07, 0x00, 0x00}}, (uint8_t *)(V), sizeof(V) - 1}; \
427+
static struct CF_CONST_STRING __ ## S ## __ = {{(uintptr_t)&__CFConstantStringClassReference, CFINFO}, (uint8_t *)(V), sizeof(V) - 1}; \
425428
CF_PRIVATE const CFStringRef S = (CFStringRef) & __ ## S ## __;
426429

427-
#endif
428-
429430
#endif // __CONSTANT_CFSTRINGS__
430431

431432
CF_EXPORT bool __CFOASafe;

CoreFoundation/String.subproj/CFString.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ struct __CFConstStr {
165165
uint8_t _pad[4];
166166
} _base;
167167
uint8_t *_ptr;
168+
#if defined(__s390x__)
169+
uint64_t _length;
170+
#else
168171
uint32_t _length;
172+
#endif
169173
};
170174

171175
#if DEPLOYMENT_TARGET_LINUX
@@ -174,10 +178,17 @@ struct __CFConstStr {
174178
#define CONST_STRING_LITERAL_SECTION
175179
#endif
176180

181+
#if __BIG_ENDIAN__
182+
#define CFSTR(cStr) ({ \
183+
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0x00, 0x00, 0x07, 0xc8}, {0x00, 0x00, 0x00, 0x00}}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
184+
(CFStringRef)&str; \
185+
})
186+
#else
177187
#define CFSTR(cStr) ({ \
178188
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&__CFConstantStringClassReference, _CF_CONSTANT_OBJECT_STRONG_RC, 0, {0xc8, 0x07, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00}}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
179189
(CFStringRef)&str; \
180190
})
191+
#endif
181192

182193
#else
183194

0 commit comments

Comments
 (0)