Skip to content

Commit d73f0d3

Browse files
committed
Updated for 07-25 chain
1 parent 5b45384 commit d73f0d3

File tree

9 files changed

+37
-38
lines changed

9 files changed

+37
-38
lines changed

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0
1+
DEVELOPMENT-SNAPSHOT-2016-07-25-a

Sources/PerfectLib/Dir.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ public struct Dir {
146146
defer { closedir(dir) }
147147

148148
var ent = dirent()
149-
let entPtr = UnsafeMutablePointer<UnsafeMutablePointer<dirent>?>(allocatingCapacity: 1)
150-
defer { entPtr.deallocateCapacity(1) }
149+
let entPtr = UnsafeMutablePointer<UnsafeMutablePointer<dirent>?>.allocate(capacity: 1)
150+
defer { entPtr.deallocate(capacity: 1) }
151151

152152
while readDir(dir, &ent, entPtr) == 0 && entPtr.pointee != nil {
153153
let name = ent.d_name
@@ -165,13 +165,13 @@ public struct Dir {
165165
guard let (_, elem) = childGen.next() else {
166166
break
167167
}
168-
guard let elemI = elem as? Int8 where elemI != 0 else {
168+
guard let elemI = elem as? Int8, elemI != 0 else {
169169
break
170170
}
171171
nameBuf.append(elemI)
172172
}
173173
nameBuf.append(0)
174-
if let name = String(validatingUTF8: nameBuf) where !(name == "." || name == "..") {
174+
if let name = String(validatingUTF8: nameBuf), !(name == "." || name == "..") {
175175
if Int32(type) == Int32(DT_DIR) {
176176
try closure(name: name + "/")
177177
} else {

Sources/PerfectLib/File.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public class File {
107107
if !inPath.isEmpty && inPath[inPath.startIndex] == "~" {
108108
var wexp = wordexp_t()
109109
wordexp(inPath, &wexp, 0)
110-
if let resolved = wexp.we_wordv[0], pth = String(validatingUTF8: resolved) {
110+
if let resolved = wexp.we_wordv[0], let pth = String(validatingUTF8: resolved) {
111111
return pth
112112
}
113113
}
@@ -521,7 +521,7 @@ public final class TemporaryFile: File {
521521
public convenience init(withPrefix: String) {
522522
let template = withPrefix + "XXXXXX"
523523
let utf8 = template.utf8
524-
let name = UnsafeMutablePointer<Int8>(allocatingCapacity: utf8.count + 1)
524+
let name = UnsafeMutablePointer<Int8>.allocate(capacity: utf8.count + 1)
525525
var i = utf8.startIndex
526526
for index in 0..<utf8.count {
527527
name[index] = Int8(utf8[i])
@@ -532,7 +532,7 @@ public final class TemporaryFile: File {
532532
let fd = mkstemp(name)
533533
let tmpFileName = String(validatingUTF8: name)!
534534

535-
name.deallocateCapacity(utf8.count + 1)
535+
name.deallocate(capacity: utf8.count + 1)
536536

537537
self.init(tmpFileName, fd: fd)
538538
}

Sources/PerfectLib/JSONConvertible.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public extension JSONConvertibleObject {
9696
}
9797

9898
/// An error occurring during JSON conversion.
99-
public enum JSONConversionError: ErrorProtocol {
99+
public enum JSONConversionError: Error {
100100
/// The object did not suppport JSON conversion.
101101
case notConvertible(Any)
102102
/// A provided key was not a String.

Sources/PerfectLib/Log.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public struct Log {
147147
Log.logger.critical(message: message)
148148
}
149149

150-
@noreturn
151-
public static func terminal(message: String) {
150+
public static func terminal(message: String) -> Never {
152151
Log.logger.terminal(message: message)
153152
fatalError(message)
154153
}

Sources/PerfectLib/PerfectError.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Darwin
2828
#endif
2929

3030
/// Some but not all of the exception types which may be thrown by the system
31-
public enum PerfectError : ErrorProtocol {
31+
public enum PerfectError : Error {
3232
/// A network related error code and message.
3333
case networkError(Int32, String)
3434
/// A file system related error code and message.
@@ -39,8 +39,8 @@ public enum PerfectError : ErrorProtocol {
3939
case apiError(String)
4040
}
4141

42-
@noreturn
43-
func ThrowFileError(file: String = #file, function: String = #function, line: Int = #line) throws {
42+
43+
func ThrowFileError(file: String = #file, function: String = #function, line: Int = #line) throws -> Never {
4444
let err = errno
4545
let msg = String(validatingUTF8: strerror(err))!
4646

@@ -49,8 +49,8 @@ func ThrowFileError(file: String = #file, function: String = #function, line: In
4949
throw PerfectError.fileError(err, msg + " \(file) \(function) \(line)")
5050
}
5151

52-
@noreturn
53-
func ThrowSystemError(file: String = #file, function: String = #function, line: Int = #line) throws {
52+
53+
func ThrowSystemError(file: String = #file, function: String = #function, line: Int = #line) throws -> Never {
5454
let err = errno
5555
let msg = String(validatingUTF8: strerror(err))!
5656

@@ -59,8 +59,8 @@ func ThrowSystemError(file: String = #file, function: String = #function, line:
5959
throw PerfectError.systemError(err, msg + " \(file) \(function) \(line)")
6060
}
6161

62-
@noreturn
63-
func ThrowNetworkError(file: String = #file, function: String = #function, line: Int = #line) throws {
62+
63+
func ThrowNetworkError(file: String = #file, function: String = #function, line: Int = #line) throws -> Never {
6464
let err = errno
6565
let msg = String(validatingUTF8: strerror(err))!
6666

Sources/PerfectLib/SysProcess.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ public class SysProcess {
4848
typealias maybeCChar = UnsafeMutablePointer<CChar>?
4949

5050
let cArgsCount = args?.count ?? 0
51-
let cArgs = UnsafeMutablePointer<maybeCChar>(allocatingCapacity: cArgsCount + 2)
51+
let cArgs = UnsafeMutablePointer<maybeCChar>.allocate(capacity: cArgsCount + 2)
5252

5353
defer {
5454
cArgs.deinitialize(count: cArgsCount + 2)
55-
cArgs.deallocateCapacity(cArgsCount + 2)
55+
cArgs.deallocate(capacity: cArgsCount + 2)
5656
}
5757

5858
cArgs[0] = strdup(cmd)
@@ -63,9 +63,9 @@ public class SysProcess {
6363
}
6464

6565
let cEnvCount = env?.count ?? 0
66-
let cEnv = UnsafeMutablePointer<maybeCChar>(allocatingCapacity: cEnvCount + 1)
66+
let cEnv = UnsafeMutablePointer<maybeCChar>.allocate(capacity: cEnvCount + 1)
6767

68-
defer { cEnv.deinitialize(count: cEnvCount + 1) ; cEnv.deallocateCapacity(cEnvCount + 1) }
68+
defer { cEnv.deinitialize(count: cEnvCount + 1) ; cEnv.deallocate(capacity: cEnvCount + 1) }
6969

7070
cEnv[cEnvCount] = UnsafeMutablePointer<CChar>(nil)
7171
for idx in 0..<cEnvCount {

Sources/PerfectLib/Utilities.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,18 @@ public struct UUID {
283283
let uuid: uuid_t
284284

285285
public init() {
286-
let u = UnsafeMutablePointer<UInt8>(allocatingCapacity: sizeof(uuid_t.self))
286+
let u = UnsafeMutablePointer<UInt8>.allocate(capacity: sizeof(uuid_t.self))
287287
defer {
288-
u.deallocateCapacity(sizeof(uuid_t.self))
288+
u.deallocate(capacity: sizeof(uuid_t.self))
289289
}
290290
uuid_generate_random(u)
291291
self.uuid = UUID.uuidFromPointer(u)
292292
}
293293

294294
public init(_ string: String) {
295-
let u = UnsafeMutablePointer<UInt8>(allocatingCapacity: sizeof(uuid_t.self))
295+
let u = UnsafeMutablePointer<UInt8>.allocate(capacity: sizeof(uuid_t.self))
296296
defer {
297-
u.deallocateCapacity(sizeof(uuid_t.self))
297+
u.deallocate(capacity: sizeof(uuid_t.self))
298298
}
299299
uuid_parse(string, u)
300300
self.uuid = UUID.uuidFromPointer(u)
@@ -310,11 +310,11 @@ public struct UUID {
310310
}
311311

312312
public var string: String {
313-
let u = UnsafeMutablePointer<UInt8>(allocatingCapacity: sizeof(uuid_t.self))
314-
let unu = UnsafeMutablePointer<Int8>(allocatingCapacity: 37) // as per spec. 36 + null
313+
let u = UnsafeMutablePointer<UInt8>.allocate(capacity: sizeof(uuid_t.self))
314+
let unu = UnsafeMutablePointer<Int8>.allocate(capacity: 37) // as per spec. 36 + null
315315
defer {
316-
u.deallocateCapacity(sizeof(uuid_t.self))
317-
unu.deallocateCapacity(37)
316+
u.deallocate(capacity: sizeof(uuid_t.self))
317+
unu.deallocate(capacity: 37)
318318
}
319319
var uu = self.uuid
320320
memcpy(u, &uu, sizeof(uuid_t.self))
@@ -632,9 +632,9 @@ public func formatDate(_ date: Double, format: String, timezone inTimezone: Stri
632632
var time = time_t(date / 1000.0)
633633
gmtime_r(&time, &t)
634634
let maxResults = 1024
635-
let results = UnsafeMutablePointer<Int8>(allocatingCapacity: maxResults)
635+
let results = UnsafeMutablePointer<Int8>.allocate(capacity: maxResults)
636636
defer {
637-
results.deallocateCapacity(maxResults)
637+
results.deallocate(capacity: maxResults)
638638
}
639639
let res = strftime(results, maxResults, format, &t)
640640
if res > 0 {
@@ -701,8 +701,8 @@ import OpenSSL
701701

702702
extension String.UTF8View {
703703
var sha1: [UInt8] {
704-
let bytes = UnsafeMutablePointer<UInt8>(allocatingCapacity: Int(SHA_DIGEST_LENGTH))
705-
defer { bytes.deallocateCapacity(Int(SHA_DIGEST_LENGTH)) }
704+
let bytes = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(SHA_DIGEST_LENGTH))
705+
defer { bytes.deallocate(capacity: Int(SHA_DIGEST_LENGTH)) }
706706

707707
SHA1(Array<UInt8>(self), (self.count), bytes)
708708

Tests/PerfectLib/PerfectLibTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ class PerfectLibTests: XCTestCase {
267267
try server.bind(address: sock)
268268
server.listen()
269269

270-
let serverExpectation = self.expectation(withDescription: "server")
271-
let clientExpectation = self.expectation(withDescription: "client")
270+
let serverExpectation = self.expectation(description: "server")
271+
let clientExpectation = self.expectation(description: "client")
272272

273273
try server.accept(timeoutSeconds: NetEvent.noTimeout) {
274274
(inn: NetTCP?) -> () in
@@ -318,13 +318,13 @@ class PerfectLibTests: XCTestCase {
318318
clientExpectation.fulfill()
319319
}
320320
}
321-
self.waitForExpectations(withTimeout: 10000, handler: {
321+
self.waitForExpectations(timeout: 10000) {
322322
_ in
323323
server.close()
324324
client.close()
325325
testFile.close()
326326
testFile.delete()
327-
})
327+
}
328328
} catch PerfectError.networkError(let code, let msg) {
329329
XCTAssert(false, "Exception: \(code) \(msg)")
330330
} catch let e {

0 commit comments

Comments
 (0)