Skip to content

Commit 6213cba

Browse files
committed
CONST_STRING_DECL() problem resolved
1 parent 60e6b73 commit 6213cba

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ CF_PRIVATE Boolean __CFProcessIsRestricted();
339339
#define STACK_BUFFER_DECL(T, N, C) T N[C]
340340
#endif
341341

342+
#ifdef __ANDROID__
343+
// Avoids crashes on Android
344+
// https://bugs.swift.org/browse/SR-2587
345+
// https://bugs.swift.org/browse/SR-2588
346+
// Seemed to be a linker/relocation? problem.
347+
// CFStrings using CONST_STRING_DECL() were not working
348+
// Applies reference to _NSCFConstantString's isa here
349+
// rather than using a linker option to create an alias.
350+
#define __CFConstantStringClassReference _TMC10Foundation19_NSCFConstantString
351+
#endif
342352

343353
CF_EXPORT void * __CFConstantStringClassReferencePtr;
344354
#if defined(__CONSTANT_CFSTRINGS__)

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ void CFLog(CFLogLevel lev, CFStringRef format, ...) {
769769
void CFLog1(CFLogLevel lev, CFStringRef message) {
770770
#ifdef __ANDROID__
771771
android_LogPriority priority = ANDROID_LOG_UNKNOWN;
772-
switch ( lev ) {
772+
switch (lev) {
773773
case kCFLogLevelEmergency: priority = ANDROID_LOG_FATAL; break;
774774
case kCFLogLevelAlert: priority = ANDROID_LOG_ERROR; break;
775775
case kCFLogLevelCritical: priority = ANDROID_LOG_ERROR; break;
@@ -781,10 +781,13 @@ void CFLog1(CFLogLevel lev, CFStringRef message) {
781781
}
782782
CFIndex blen = message ? CFStringGetMaximumSizeForEncoding(CFStringGetLength(message), kCFStringEncodingUTF8) + 1 : 0;
783783
char *buf = message ? (char *)malloc(blen) : 0;
784-
if ( buf ) {
785-
CFStringGetCString(message, buf, blen, kCFStringEncodingUTF8);
784+
if (buf) {
785+
if (blen == 1)
786+
buf[0] = '\000';
787+
else
788+
CFStringGetCString(message, buf, blen, kCFStringEncodingUTF8);
786789
__android_log_print(priority, "Swift", "%s", buf);
787-
free( buf );
790+
free(buf);
788791
}
789792
#else
790793
CFLog(lev, CFSTR("%@"), message);

CoreFoundation/String.subproj/CFString.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,16 +1264,12 @@ CF_PRIVATE CFStringRef __CFStringCreateImmutableFunnel3(
12641264
contentsDeallocator = __CFGetDefaultAllocator();
12651265
}
12661266

1267-
#ifndef __ANDROID__
1268-
// https://bugs.swift.org/browse/SR-2587
1269-
// crashes String.swift, line 51 when creating String from zero length Data
12701267
if ((NULL != kCFEmptyString) && (numBytes == 0) && _CFAllocatorIsSystemDefault(alloc)) { // If we are using the system default allocator, and the string is empty, then use the empty string!
12711268
if (noCopy && (contentsDeallocator != kCFAllocatorNull)) { // See 2365208... This change was done after Sonata; before we didn't free the bytes at all (leak).
12721269
CFAllocatorDeallocate(contentsDeallocator, (void *)bytes);
12731270
}
12741271
return (CFStringRef)CFRetain(kCFEmptyString); // Quick exit; won't catch all empty strings, but most
12751272
}
1276-
#endif
12771273

12781274
// At this point, contentsDeallocator is either same as alloc, or kCFAllocatorNull, or something else, but not NULL
12791275

Foundation/NSURLSession/NSURLSessionTask.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,9 @@ fileprivate extension URLSessionTask {
630630
var result = [("Connection", "keep-alive"),
631631
("User-Agent", userAgentString),
632632
]
633-
#if !os(Android)
634-
// Crashes on Android https://bugs.swift.org/browse/SR-2588
635633
if let language = NSLocale.current.languageCode {
636634
result.append(("Accept-Language", language))
637635
}
638-
#endif
639636
return result
640637
}
641638
/// Any header values that should be removed from the ones set by libcurl

android/package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
#
3-
# prepare binay package used to build Foundtion for Android
3+
# Prepare binary package used to build Foundation for Android
44
#
55

66
cd "$(dirname $0)" &&

0 commit comments

Comments
 (0)