Skip to content

Commit aea9106

Browse files
committed
Changes required for swift-4.1-branch port to Android
1 parent f406f74 commit aea9106

26 files changed

+76
-24
lines changed

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ CF_EXPORT double kCFCoreFoundationVersionNumber;
448448
#define kCFCoreFoundationVersionNumber_iOS_9_x_Max 1299
449449
#endif
450450

451+
#ifdef __ANDROID__
452+
typedef uint16_t _swift_rc_type;
453+
#else
454+
typedef uint32_t _swift_rc_type;
455+
#endif
456+
451457
#if __LLP64__
452458
typedef unsigned long long CFTypeID;
453459
typedef unsigned long long CFOptionFlags;

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ extern void __CFGenericValidateType_(CFTypeRef cf, CFTypeID type, const char *fu
216216
#define __CFBitfield64GetValue(V, N1, N2) (((V) & __CFBitfield64Mask(N1, N2)) >> (N2))
217217
#define __CFBitfield64SetValue(V, N1, N2, X) ((V) = ((V) & ~__CFBitfield64Mask(N1, N2)) | ((((uint64_t)X) << (N2)) & __CFBitfield64Mask(N1, N2)))
218218

219-
#if __LP64__
219+
#if __LP64__ || defined(__ANDROID__)
220220
typedef uint64_t __CFInfoType;
221221
#define __CFInfoMask(N1, N2) __CFBitfield64Mask(N1, N2)
222222
#else

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ CF_EXPORT CFStringRef CFCopyFullUserName(void) {
297297
uid_t euid;
298298
__CFGetUGIDs(&euid, NULL);
299299
struct passwd *upwd = getpwuid(euid ? euid : getuid());
300+
#ifdef __ANDROID__
301+
#define pw_gecos pw_name
302+
#endif
300303
if (upwd && upwd->pw_gecos) {
301304
result = CFStringCreateWithCString(kCFAllocatorSystemDefault, upwd->pw_gecos, kCFPlatformInterfaceStringEncoding);
302305
}

CoreFoundation/Base.subproj/CFRuntime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ 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+
_swift_rc_type _swift_strong_rc;
197+
_swift_rc_type _swift_weak_rc;
198198
// This is for CF's use, and must match _NSCFType layout
199199
_Atomic(uint64_t) _cfinfoa;
200200
} CFRuntimeBase;

CoreFoundation/Base.subproj/CFUtilities.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ void CFLog1(CFLogLevel lev, CFStringRef message) {
10001000
CFStringGetCString(message, buffer, maxLength, encoding);
10011001

10021002
__android_log_print(priority, tag, "%s", buffer);
1003+
fprintf(stderr, "%s\n", buffer);
10031004

10041005
if (buffer != &stack_buffer[0]) free(buffer);
10051006
#else

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((n
403403
static inline int _direntNameLength(struct dirent *entry) {
404404
#ifdef _D_EXACT_NAMLEN // defined on Linux
405405
return _D_EXACT_NAMLEN(entry);
406+
#elseif defined(__ANDROID__)
407+
return strlen(entry->d_name);
406408
#else
407409
return entry->d_namlen;
408410
#endif

CoreFoundation/PlugIn.subproj/CFBundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static CFBundleRef _CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL,
714714

715715
bundle->_url = newURL;
716716

717-
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
717+
#if !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS && !defined(__ANDROID__)
718718
bundle->_isFHSInstalledBundle = _CFBundleURLIsForFHSInstalledBundle(newURL);
719719
#endif
720720

CoreFoundation/PlugIn.subproj/CFBundle_Main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,20 @@ static CFBundleRef _CFBundleGetMainBundleAlreadyLocked(void) {
7979
CFStringRef str = NULL;
8080
CFURLRef executableURL = NULL, bundleURL = NULL;
8181
_initedMainBundle = true;
82+
#ifdef __ANDROID__
83+
const char *bundlePath = getenv("CFFIXED_USER_HOME") ?: getenv("TMPDIR") ?: "/data/local/tmp";
84+
CFStringRef bundleRef = CFStringCreateWithFileSystemRepresentation(kCFAllocatorNull, bundlePath);
85+
bundleURL = CFRetain(CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, bundleRef,
86+
PLATFORM_PATH_STYLE, false));
87+
CFRelease(bundleRef);
88+
#else
8289
processPath = _CFProcessPath();
8390
if (processPath) {
8491
str = CFStringCreateWithFileSystemRepresentation(kCFAllocatorSystemDefault, processPath);
8592
if (!executableURL) executableURL = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, str, PLATFORM_PATH_STYLE, false);
8693
}
8794
if (executableURL) bundleURL = _CFBundleCopyBundleURLForExecutableURL(executableURL);
95+
#endif
8896
if (bundleURL) {
8997
// make sure that main bundle has executable path
9098
//??? what if we are not the main executable in the bundle?

CoreFoundation/Preferences.subproj/CFPreferences.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,11 @@ static CFURLRef _CFPreferencesURLForStandardDomainWithSafetyLevel(CFStringRef do
440440
CFURLRef theURL = NULL;
441441
CFAllocatorRef prefAlloc = __CFPreferencesAllocator();
442442
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_WINDOWS
443+
#ifdef __ANDROID__
444+
CFURLRef prefDir = CFBundleCopyBundleURL(CFBundleGetMainBundle());
445+
#else
443446
CFURLRef prefDir = _preferencesDirectoryForUserHostSafetyLevel(userName, hostName, safeLevel);
447+
#endif
444448
CFStringRef appName;
445449
CFStringRef fileName;
446450
Boolean mustFreeAppName = false;

CoreFoundation/String.subproj/CFString.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ 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+
_swift_rc_type _swift_strong_rc;
159+
_swift_rc_type _swift_weak_rc;
160160
uint64_t _cfinfoa;
161161
} _base;
162162
uint8_t *_ptr;

0 commit comments

Comments
 (0)