Skip to content

Commit 4ad829c

Browse files
authored
Merge pull request swiftlang#63 from swiftwasm/master
[pull] swiftwasm from master
2 parents 8865ca6 + aa07812 commit 4ad829c

File tree

7 files changed

+31
-17
lines changed

7 files changed

+31
-17
lines changed

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ const char *_NSPrintForDebugger(void *cf) {
17431743
if (!desc) {
17441744
return "<no description>";
17451745
}
1746+
CFRelease(desc);
17461747
const char *cheapResult = CFStringGetCStringPtr((CFTypeRef)cf, kCFStringEncodingUTF8);
17471748
if (cheapResult) {
17481749
return cheapResult;

CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static void updateFormatter(CFDateIntervalFormatterRef dif) {
139139

140140
char localeBuffer[100] = {0};
141141
CFStringGetCString(localeID, localeBuffer, 100, kCFStringEncodingUTF8);
142-
142+
143143
UniChar timeZoneID[100] = {0};
144144
CFTimeZoneRef timeZone = dif->_timeZone;
145145
if (timeZone) {
@@ -186,6 +186,7 @@ static void updateFormatter(CFDateIntervalFormatterRef dif) {
186186
#endif
187187

188188
CFRelease(locale);
189+
CFRelease(localeID);
189190
CFRelease(timeZone);
190191
}
191192
}

Sources/FoundationNetworking/URLSession/URLSessionTask.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,20 @@ open class URLSessionTask : NSObject, NSCopying {
364364
*/
365365
open func cancel() {
366366
workQueue.sync {
367-
guard self.state == .running || self.state == .suspended else { return }
368-
self.state = .canceling
367+
let canceled = self.syncQ.sync { () -> Bool in
368+
guard self._state == .running || self._state == .suspended else { return true }
369+
self._state = .canceling
370+
return false
371+
}
372+
guard !canceled else { return }
369373
self._getProtocol { (urlProtocol) in
370374
self.workQueue.async {
371-
let urlError = URLError(_nsError: NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled, userInfo: nil))
375+
var info = [NSLocalizedDescriptionKey: "\(URLError.Code.cancelled)" as Any]
376+
if let url = self.originalRequest?.url {
377+
info[NSURLErrorFailingURLErrorKey] = url
378+
info[NSURLErrorFailingURLStringErrorKey] = url.absoluteString
379+
}
380+
let urlError = URLError(_nsError: NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled, userInfo: info))
372381
self.error = urlError
373382
if let urlProtocol = urlProtocol {
374383
urlProtocol.stopLoading()

Tests/Foundation/Tests/TestJSONEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ class TestJSONEncoder : XCTestCase {
623623
// UInt and Int
624624
func test_codingOfUIntMinMax() {
625625

626-
struct MyValue: Codable {
626+
struct MyValue: Encodable {
627627
let int64Min = Int64.min
628628
let int64Max = Int64.max
629629
let uint64Min = UInt64.min

Tests/Foundation/Tests/TestNSString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestNSString: LoopbackServerTest {
3333
let testString = "\u{00} This is a test string"
3434
let data = testString.data(using: .utf8)!
3535
XCTAssertEqual(data.count, 23)
36-
_ = data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) in
36+
data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) in
3737
if let text1 = NSString(bytes: bytes.baseAddress!, length: data.count, encoding: String.Encoding.utf8.rawValue) {
3838
XCTAssertEqual(text1.length, data.count)
3939
XCTAssertEqual(text1, testString as NSString)

Tests/Foundation/Tests/TestStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class TestStream : XCTestCase {
162162
XCTAssertEqual(try testSubdata(UInt64(str.count))!.count, 0) // It shouldbe end
163163

164164
do {
165-
try testSubdata(UInt64(str.count + 1)) // out of boundaries
165+
_ = try testSubdata(UInt64(str.count + 1)) // out of boundaries
166166
XCTFail()
167167
} catch let error as InputStream._Error {
168168
XCTAssertEqual(error, .cantSeekInputStream)

Tests/Foundation/Tests/TestURLSession.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class TestURLSession: LoopbackServerTest {
357357
config.timeoutIntervalForRequest = 5
358358
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/requestHeaders"
359359
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
360-
var expect = expectation(description: "POST \(urlString): get request headers")
360+
let expect = expectation(description: "POST \(urlString): get request headers")
361361
var req = URLRequest(url: URL(string: urlString)!)
362362
let headers = ["header1": "value1"]
363363
req.httpMethod = "POST"
@@ -384,7 +384,7 @@ class TestURLSession: LoopbackServerTest {
384384
config.httpAdditionalHeaders = ["header2": "svalue2", "header3": "svalue3", "header4": "svalue4"]
385385
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/requestHeaders"
386386
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
387-
var expect = expectation(description: "POST \(urlString) with additional headers")
387+
let expect = expectation(description: "POST \(urlString) with additional headers")
388388
var req = URLRequest(url: URL(string: urlString)!)
389389
let headers = ["header1": "rvalue1", "header2": "rvalue2", "Header4": "rvalue4"]
390390
req.httpMethod = "POST"
@@ -411,7 +411,7 @@ class TestURLSession: LoopbackServerTest {
411411
config.timeoutIntervalForRequest = 5
412412
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/Peru"
413413
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
414-
var expect = expectation(description: "GET \(urlString): no timeout")
414+
let expect = expectation(description: "GET \(urlString): no timeout")
415415
let req = URLRequest(url: URL(string: urlString)!)
416416
let task = session.dataTask(with: req) { (data, _, error) -> Void in
417417
defer { expect.fulfill() }
@@ -427,7 +427,7 @@ class TestURLSession: LoopbackServerTest {
427427
config.timeoutIntervalForRequest = 10
428428
let urlString = "http://127.0.0.1:-1/Peru"
429429
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
430-
var expect = expectation(description: "GET \(urlString): will timeout")
430+
let expect = expectation(description: "GET \(urlString): will timeout")
431431
var req = URLRequest(url: URL(string: "http://127.0.0.1:-1/Peru")!)
432432
req.timeoutInterval = 1
433433
let task = session.dataTask(with: req) { (data, _, error) -> Void in
@@ -754,7 +754,7 @@ class TestURLSession: LoopbackServerTest {
754754
var req = URLRequest(url: URL(string: urlString)!)
755755
req.timeoutInterval = 3
756756
let config = URLSessionConfiguration.default
757-
var expect = expectation(description: "GET \(urlString): timeout with redirection ")
757+
let expect = expectation(description: "GET \(urlString): timeout with redirection ")
758758
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
759759
let task = session.dataTask(with: req) { data, response, error in
760760
defer { expect.fulfill() }
@@ -1176,7 +1176,7 @@ class TestURLSession: LoopbackServerTest {
11761176
XCTAssertEqual(config.httpCookieStorage?.cookies?.count, 0)
11771177
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/requestCookies"
11781178
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
1179-
var expect = expectation(description: "POST \(urlString)")
1179+
let expect = expectation(description: "POST \(urlString)")
11801180
var req = URLRequest(url: URL(string: urlString)!)
11811181
req.httpMethod = "POST"
11821182
let task = session.dataTask(with: req) { (data, response, error) -> Void in
@@ -1201,7 +1201,7 @@ class TestURLSession: LoopbackServerTest {
12011201
emptyCookieStorage(storage: config.httpCookieStorage)
12021202
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/requestCookies"
12031203
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
1204-
var expect = expectation(description: "POST \(urlString)")
1204+
let expect = expectation(description: "POST \(urlString)")
12051205
var req = URLRequest(url: URL(string: urlString)!)
12061206
req.httpMethod = "POST"
12071207
let task = session.dataTask(with: req) { (data, response, error) -> Void in
@@ -1226,7 +1226,7 @@ class TestURLSession: LoopbackServerTest {
12261226
emptyCookieStorage(storage: config.httpCookieStorage)
12271227
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/redirectToEchoHeaders"
12281228
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
1229-
var expect = expectation(description: "POST \(urlString)")
1229+
let expect = expectation(description: "POST \(urlString)")
12301230
let req = URLRequest(url: URL(string: urlString)!)
12311231
let task = session.dataTask(with: req) { (data, _, error) -> Void in
12321232
defer { expect.fulfill() }
@@ -1294,7 +1294,7 @@ class TestURLSession: LoopbackServerTest {
12941294

12951295
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/requestCookies"
12961296
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
1297-
var expect = expectation(description: "POST \(urlString)")
1297+
let expect = expectation(description: "POST \(urlString)")
12981298
var req = URLRequest(url: URL(string: urlString)!)
12991299
req.httpMethod = "POST"
13001300
let task = session.dataTask(with: req) { (data, _, error) -> Void in
@@ -1404,7 +1404,7 @@ class TestURLSession: LoopbackServerTest {
14041404
config.timeoutIntervalForRequest = 5
14051405
let urlString = "http://127.0.0.1:\(TestURLSession.serverPort)/emptyPost"
14061406
let session = URLSession(configuration: config, delegate: nil, delegateQueue: nil)
1407-
var expect = expectation(description: "POST \(urlString): post with empty body")
1407+
let expect = expectation(description: "POST \(urlString): post with empty body")
14081408
var req = URLRequest(url: URL(string: urlString)!)
14091409
req.httpMethod = "POST"
14101410
let task = session.dataTask(with: req) { (_, response, error) -> Void in
@@ -1443,6 +1443,9 @@ class TestURLSession: LoopbackServerTest {
14431443
XCTAssertNotNil(error as? URLError)
14441444
if let urlError = error as? URLError {
14451445
XCTAssertEqual(urlError._nsError.code, NSURLErrorCancelled)
1446+
XCTAssertEqual(urlError.userInfo[NSURLErrorFailingURLErrorKey] as? URL, URL(string: urlString))
1447+
XCTAssertEqual(urlError.userInfo[NSURLErrorFailingURLStringErrorKey] as? String, urlString)
1448+
XCTAssertEqual(urlError.localizedDescription, "cancelled")
14461449
}
14471450

14481451
expect.fulfill()

0 commit comments

Comments
 (0)