Skip to content

Commit dd12300

Browse files
authored
Merge branch 'master' into NSLocalizedDescription
2 parents f9b2c18 + 0063f33 commit dd12300

19 files changed

+62
-219
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131

3232
#endif
3333

34+
#if defined(__ANDROID__)
35+
#include <linux/prctl.h>
36+
#endif
37+
3438
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_WINDOWS
3539
#define kCFPlatformInterfaceStringEncoding kCFStringEncodingUTF8
3640
#else
@@ -1319,6 +1323,8 @@ _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (*
13191323
CF_SWIFT_EXPORT void _CFThreadSetName(const char *_Nullable name) {
13201324
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
13211325
pthread_setname_np(name);
1326+
#elif defined(__ANDROID__)
1327+
prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0);
13221328
#elif DEPLOYMENT_TARGET_LINUX
13231329
pthread_setname_np(pthread_self(), name);
13241330
#endif
@@ -1327,6 +1333,8 @@ CF_SWIFT_EXPORT void _CFThreadSetName(const char *_Nullable name) {
13271333
CF_SWIFT_EXPORT int _CFThreadGetName(char *buf, int length) {
13281334
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
13291335
return pthread_getname_np(pthread_self(), buf, length);
1336+
#elif defined(__ANDROID__)
1337+
prctl(PR_GET_NAME, (unsigned long) buf, 0, 0, 0);
13301338
#elif DEPLOYMENT_TARGET_LINUX
13311339
return pthread_getname_np(pthread_self(), buf, length);
13321340
#endif

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include <CoreFoundation/ForFoundationOnly.h>
2828
#include <fts.h>
2929
#include <pthread.h>
30+
#ifndef __ANDROID__
3031
#include <execinfo.h>
32+
#endif
3133

3234
_CF_EXPORT_SCOPE_BEGIN
3335

CoreFoundation/URL.subproj/CFURL.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#include <unistd.h>
2626
#include <sys/stat.h>
2727
#include <sys/types.h>
28-
#if __has_include(<sys/syslog.h>)
29-
#include <sys/syslog.h>
30-
#else
28+
#if DEPLOYMENT_TARGET_ANDROID
3129
#include <syslog.h>
30+
#else
31+
#include <sys/syslog.h>
3232
#endif
3333
#include <CoreFoundation/CFURLPriv.h>
3434
#endif

CoreFoundation/URL.subproj/CFURLSessionInterface.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const char *CFURLSessionErrorDescription(int value) {
3535
return curl_easy_strerror(value);
3636
}
3737

38-
3938
CFURLSessionEasyHandle _Nonnull CFURLSessionEasyHandleInit() {
4039
return curl_easy_init();
4140
}

Foundation/HTTPCookieStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ open class HTTPCookieStorage: NSObject {
4949
let bundlePath = Bundle.main.bundlePath
5050
var bundleName = bundlePath.components(separatedBy: "/").last!
5151
if let range = bundleName.range(of: ".", options: String.CompareOptions.backwards, range: nil, locale: nil) {
52-
bundleName = bundleName.substring(to: range.lowerBound)
52+
bundleName = String(bundleName[..<range.lowerBound])
5353
}
5454
let cookieFolderPath = _CFXDGCreateDataHomePath()._swiftObject + "/" + bundleName
5555
cookieFilePath = filePath(path: cookieFolderPath, fileName: "/.cookies." + cookieStorageName, bundleName: bundleName)

Foundation/Host.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ open class Host: NSObject {
6565
}
6666

6767
internal func _resolveCurrent() {
68+
#if !os(Android)
6869
var ifaddr: UnsafeMutablePointer<ifaddrs>? = nil
6970
if getifaddrs(&ifaddr) != 0 {
7071
return
@@ -88,6 +89,7 @@ open class Host: NSObject {
8889
}
8990
ifa = ifaValue.ifa_next
9091
}
92+
#endif
9193
}
9294

9395
internal func _resolve() {
@@ -138,7 +140,7 @@ open class Host: NSObject {
138140
}
139141
let sa_len: socklen_t = socklen_t((family == AF_INET6) ? MemoryLayout<sockaddr_in6>.size : MemoryLayout<sockaddr_in>.size)
140142
let lookupInfo = { (content: inout [String], flags: Int32) in
141-
if getnameinfo(info.ai_addr, sa_len, host, socklen_t(NI_MAXHOST), nil, 0, flags) == 0 {
143+
if getnameinfo(info.ai_addr, sa_len, host, numericCast(NI_MAXHOST), nil, 0, flags) == 0 {
142144
content.append(String(cString: host))
143145
}
144146
}

Foundation/NSLog.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public func NSLogv(_ format: String, _ args: CVaListPointer) {
3333
CFLog1(kCFLogLevelWarning, message._cfObject)
3434
#else
3535
CFLog1(Int32(kCFLogLevelWarning), message._cfObject)
36+
#if os(Android)
37+
print(message)
38+
#endif
3639
#endif
3740
}
3841

Foundation/Thread.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ open class Thread : NSObject {
250250
_cancelled = true
251251
}
252252

253-
253+
#if !os(Android)
254254
private class func backtraceAddresses<T>(_ body: (UnsafeMutablePointer<UnsafeMutableRawPointer?>, Int) -> [T]) -> [T] {
255255
// Same as swift/stdlib/public/runtime/Errors.cpp backtrace
256256
let maxSupportedStackDepth = 128;
@@ -284,6 +284,15 @@ open class Thread : NSObject {
284284
return symbols
285285
})
286286
}
287+
#else
288+
open class var callStackReturnAddresses: [NSNumber] {
289+
NSUnimplemented()
290+
}
291+
292+
open class var callStackSymbols: [String] {
293+
NSUnimplemented()
294+
}
295+
#endif
287296
}
288297

289298
extension NSNotification.Name {

Foundation/URLSession/http/EasyHandle.swift

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ internal final class _EasyHandle {
5757
fileprivate var pauseState: _PauseState = []
5858
internal var timeoutTimer: _TimeoutSource!
5959
private var errorBuffer = [UInt8](repeating: 0, count: 1000)
60-
#if os(Android)
61-
static fileprivate var _CAInfoFile: UnsafeMutablePointer<Int8>?
62-
#endif
6360

6461
init(delegate: _EasyHandleDelegate) {
6562
self.delegate = delegate
@@ -174,20 +171,20 @@ extension _EasyHandle {
174171
errorBuffer.withUnsafeMutableBufferPointer {
175172
try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionERRORBUFFER, $0.baseAddress).asError()
176173
}
177-
#if os(Android)
178-
// See https://curl.haxx.se/docs/sslcerts.html
179-
// For SSL to work you need "cacert.pem" to be accessable
180-
// at the path pointed to by the URLSessionCAInfo env var.
181-
// Downloadable here: https://curl.haxx.se/ca/cacert.pem
182-
if let caInfo = _EasyHandle._CAInfoFile {
183-
if String(cString: caInfo) == "UNSAFE_SSL_NOVERIFY" {
184-
try! CFURLSession_easy_setopt_int(rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0).asError()
185-
}
186-
else {
187-
try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionCAINFO, caInfo).asError()
188-
}
174+
#if os(Android)
175+
// See https://curl.haxx.se/docs/sslcerts.html
176+
// For SSL on Android you need a "cacert.pem" to be
177+
// accessible at the path pointed to by this env var.
178+
// Downloadable here: https://curl.haxx.se/ca/cacert.pem
179+
if let caInfo = getenv("URLSessionCertificateAuthorityInfoFile") {
180+
if String(cString: caInfo) == "INSECURE_SSL_NO_VERIFY" {
181+
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0).asError()
182+
}
183+
else {
184+
try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionCAINFO, caInfo).asError()
189185
}
190-
#endif
186+
}
187+
#endif
191188
//TODO: Added in libcurl 7.45.0
192189
//TODO: Set default protocol for schemeless URLs
193190
//CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
@@ -634,19 +631,6 @@ extension _EasyHandle._CurlStringList {
634631
}
635632
}
636633

637-
#if os(Android)
638-
extension URLSession {
639-
640-
public static func setCAInfoFile(_ _CAInfoFile: String) {
641-
free(_EasyHandle._CAInfoFile)
642-
_CAInfoFile.withCString {
643-
_EasyHandle._CAInfoFile = strdup($0)
644-
}
645-
}
646-
647-
}
648-
#endif
649-
650634
extension CFURLSessionEasyCode : Equatable {
651635
public static func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
652636
return lhs.value == rhs.value

TestFoundation/TestHTTPCookieStorage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class TestHTTPCookieStorage: XCTestCase {
230230
let bundlePath = Bundle.main.bundlePath
231231
var bundleName = "/" + bundlePath.components(separatedBy: "/").last!
232232
if let range = bundleName.range(of: ".", options: String.CompareOptions.backwards, range: nil, locale: nil) {
233-
bundleName = bundleName.substring(to: range.lowerBound)
233+
bundleName = String(bundleName[..<range.lowerBound])
234234
}
235235
if let xdg_data_home = getenv("XDG_DATA_HOME") {
236236
destPath = String(utf8String: xdg_data_home)! + bundleName + "/.cookies.shared"
@@ -251,7 +251,7 @@ class TestHTTPCookieStorage: XCTestCase {
251251
let exeName = "/xdgTestHelper/xdgTestHelper"
252252
#endif
253253

254-
task.launchPath = bundlePath.substring(to: pathIndex!) + exeName
254+
task.launchPath = bundlePath[..<pathIndex!] + exeName
255255
var environment = ProcessInfo.processInfo.environment
256256
let testPath = NSHomeDirectory() + "/TestXDG"
257257
environment["XDG_DATA_HOME"] = testPath

TestFoundation/TestOperationQueue.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,35 @@ class AsyncOperation: Operation {
175175

176176
override internal(set) var isExecuting: Bool {
177177
get {
178-
return _executing
178+
lock.lock()
179+
let wasExecuting = _executing
180+
lock.unlock()
181+
return wasExecuting
179182
}
180183
set {
181-
if _executing != newValue {
184+
if isExecuting != newValue {
182185
willChangeValue(forKey: "isExecuting")
186+
lock.lock()
183187
_executing = newValue
188+
lock.unlock()
184189
didChangeValue(forKey: "isExecuting")
185190
}
186191
}
187192
}
188193

189194
override internal(set) var isFinished: Bool {
190195
get {
191-
return _finished
196+
lock.lock()
197+
let wasFinished = _finished
198+
lock.unlock()
199+
return wasFinished
192200
}
193201
set {
194-
if _finished != newValue {
202+
if isFinished != newValue {
195203
willChangeValue(forKey: "isFinished")
204+
lock.lock()
196205
_finished = newValue
206+
lock.unlock()
197207
didChangeValue(forKey: "isFinished")
198208
}
199209
}
@@ -213,10 +223,8 @@ class AsyncOperation: Operation {
213223

214224
queue.async {
215225
sleep(1)
216-
self.lock.lock()
217226
self.isExecuting = false
218227
self.isFinished = true
219-
self.lock.unlock()
220228
}
221229
}
222230

TestFoundation/TestProcess.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private func parseEnv(_ env: String) throws -> [String: String] {
334334
guard let range = line.range(of: "=") else {
335335
throw Error.InvalidEnvironmentVariable(line)
336336
}
337-
result[line.substring(to: range.lowerBound)] = line.substring(from: range.upperBound)
337+
result[String(line[..<range.lowerBound])] = String(line[range.upperBound...])
338338
}
339339
return result
340340
}

TestFoundation/TestXMLParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ class TestXMLParser : XCTestCase {
8686
return xmlUnderTest
8787
}
8888
if let open = encoding.range(of: "(") {
89-
encoding = encoding.substring(from: open.upperBound)
89+
encoding = String(encoding[open.upperBound...])
9090
}
9191
if let close = encoding.range(of: ")") {
92-
encoding = encoding.substring(to: close.lowerBound)
92+
encoding = String(encoding[..<close.lowerBound])
9393
}
9494
return "<?xml version='1.0' encoding='\(encoding.uppercased())' standalone='no'?>\n\(xmlUnderTest)\n"
9595
}

android/README.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

android/builder.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

android/install.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)