Skip to content

Commit 99e2421

Browse files
authored
Merge pull request #1735 from millenomi/cfstr
Add support for compiler-managed CFSTR() on non-Darwin systems
2 parents 439fe45 + c25f90c commit 99e2421

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ CF_PRIVATE Boolean __CFProcessIsRestricted(void);
421421

422422
CF_EXPORT void * __CFConstantStringClassReferencePtr;
423423

424-
#if DEPLOYMENT_RUNTIME_SWIFT
424+
#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC
425425

426426
#if DEPLOYMENT_TARGET_LINUX
427427
#define CONST_STRING_SECTION __attribute__((section(".cfstr.data")))

CoreFoundation/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ target_compile_options(CoreFoundation
363363
-fconstant-cfstrings
364364
-fdollars-in-identifiers
365365
-fexceptions)
366+
if(CF_DEPLOYMENT_SWIFT)
367+
target_compile_options(CoreFoundation
368+
PRIVATE
369+
-fcf-runtime-abi=swift)
370+
endif()
371+
366372
target_compile_options(CoreFoundation
367373
PRIVATE
368374
-Wno-shorten-64-to-32

CoreFoundation/String.subproj/CFString.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,16 @@ since it is the default choice with Mac OS X developer tools.
152152
#endif
153153

154154
#if DEPLOYMENT_RUNTIME_SWIFT
155+
#if TARGET_OS_MAC
156+
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s15SwiftFoundation19_NSCFConstantStringCN
157+
#else
158+
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s10Foundation19_NSCFConstantStringCN
159+
#endif
155160

156-
#if TARGET_OS_MAC
157-
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s15SwiftFoundation19_NSCFConstantStringCN
158-
#else
159-
#define _CF_CONSTANT_STRING_SWIFT_CLASS $s10Foundation19_NSCFConstantStringCN
161+
CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[];
160162
#endif
161163

162-
CF_EXPORT void *_CF_CONSTANT_STRING_SWIFT_CLASS[];
164+
#if DEPLOYMENT_RUNTIME_SWIFT && TARGET_OS_MAC
163165

164166
struct __CFConstStr {
165167
struct {
@@ -175,20 +177,14 @@ struct __CFConstStr {
175177
#endif // defined(__LP64__) || defined(__LLP64__)
176178
};
177179

178-
#if TARGET_OS_LINUX
179-
#define CONST_STRING_LITERAL_SECTION __attribute__((section(".cfstrlit.data")))
180-
#else
181-
#define CONST_STRING_LITERAL_SECTION
182-
#endif // TARGET_OS_LINUX
183-
184180
#if __BIG_ENDIAN__
185181
#define CFSTR(cStr) ({ \
186-
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
182+
static struct __CFConstStr str = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x00000000C8070000}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
187183
(CFStringRef)&str; \
188184
})
189185
#else // Little endian:
190186
#define CFSTR(cStr) ({ \
191-
static struct __CFConstStr str CONST_STRING_LITERAL_SECTION = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
187+
static struct __CFConstStr str = {{(uintptr_t)&_CF_CONSTANT_STRING_SWIFT_CLASS, _CF_CONSTANT_OBJECT_STRONG_RC, 0x07C8}, (uint8_t *)(cStr), sizeof(cStr) - 1}; \
192188
(CFStringRef)&str; \
193189
})
194190
#endif // __BIG_ENDIAN__

build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
'-Wno-int-conversion',
6464
'-Wno-unused-function',
6565
'-I./',
66+
'-fcf-runtime-abi=swift',
6667
])
6768

6869
swift_cflags += [

0 commit comments

Comments
 (0)