summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml23
-rw-r--r--Thrift.podspec13
-rw-r--r--lib/swift/Sources/TBinaryProtocol.swift30
-rw-r--r--lib/swift/Sources/TCompactProtocol.swift10
-rw-r--r--lib/swift/Sources/TFramedTransport.swift8
-rw-r--r--lib/swift/Sources/TMap.swift8
-rw-r--r--lib/swift/Sources/TProtocol.swift13
-rw-r--r--lib/swift/Sources/TSSLSocketTransport.swift15
-rw-r--r--lib/swift/Sources/TSet.swift2
-rw-r--r--lib/swift/Sources/TSocketServer.swift1
-rw-r--r--lib/swift/Sources/TSocketTransport.swift16
-rw-r--r--lib/swift/Sources/TStreamTransport.swift15
-rw-r--r--lib/swift/Sources/TStruct.swift8
13 files changed, 96 insertions, 66 deletions
diff --git a/.travis.yml b/.travis.yml
index 4a399a60e..400cfa146 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -148,7 +148,28 @@ jobs:
env:
- JOB="Coverity Scan"
- SCRIPT="covscan.sh"
-
+
+ # ------------------------- phase: swift ------------------------
+ # We lint the podspec
+ - os: osx
+ osx_image: xcode10.1
+ language: swift
+ script:
+ - gem update cocoapods
+ - pod lib lint --allow-warnings --swift-version=3
+ env:
+ - JOB="pod lib lint"
+
+ - os: osx
+ osx_image: xcode10.2
+ language: swift
+ script:
+ - gem update cocoapods
+ - pod lib lint --allow-warnings --swift-version=4.0
+ - pod lib lint --allow-warnings --swift-version=4.2
+ - pod lib lint --allow-warnings --swift-version=5.0
+ env:
+ - JOB="pod lib lint"
### ------------------------- phase: osx --------------------------
# disabled due to the time delays it imposes on build jobs
diff --git a/Thrift.podspec b/Thrift.podspec
index cb1c9b292..4c8fa68ac 100644
--- a/Thrift.podspec
+++ b/Thrift.podspec
@@ -1,16 +1,15 @@
Pod::Spec.new do |s|
- s.name = "Thrift-swift3"
- s.version = "0.13.0"
+ s.name = 'Thrift'
+ s.version = '0.13.0'
s.summary = "Apache Thrift is a lightweight, language-independent software stack with an associated code generation mechanism for RPC."
s.description = <<-DESC
The Apache Thrift scalable cross-language software framework for networked services development combines a software stack with a code generation engine to build services that work efficiently and seamlessly between many programming languages.
DESC
- s.homepage = "http://thrift.apache.org"
+ s.homepage = 'https://thrift.apache.org'
s.license = { :type => 'Apache License, Version 2.0', :url => 'https://www.apache.org/licenses/LICENSE-2.0' }
- s.author = { "Apache Thrift Developers" => "dev@thrift.apache.org" }
+ s.author = { 'Apache Thrift Developers' => 'dev@thrift.apache.org' }
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.10'
- s.requires_arc = true
- s.source = { :git => "https://github.com/apache/thrift.git", :tag => "v0.13.0" }
- s.source_files = "lib/swift/Sources/*.swift"
+ s.source = { :git => 'https://github.com/apache/thrift.git', :tag => 'v0.13.0' }
+ s.source_files = 'lib/swift/Sources/*.swift'
end
diff --git a/lib/swift/Sources/TBinaryProtocol.swift b/lib/swift/Sources/TBinaryProtocol.swift
index a97249abc..85acce045 100644
--- a/lib/swift/Sources/TBinaryProtocol.swift
+++ b/lib/swift/Sources/TBinaryProtocol.swift
@@ -325,7 +325,7 @@ public class TBinaryProtocol: TProtocol {
}
public func write(_ value: UInt8) throws {
- let buff = Data(bytes: [value])
+ let buff = Data([value])
try ProtocolTransportTry(error: TProtocolError(message: "Transport write failed")) {
try self.transport.write(data: buff)
@@ -334,8 +334,8 @@ public class TBinaryProtocol: TProtocol {
public func write(_ value: Int16) throws {
var buff = Data()
- buff.append(Data(bytes: [UInt8(0xff & (value >> 8))]))
- buff.append(Data(bytes: [UInt8(0xff & (value))]))
+ buff.append(Data([UInt8(0xff & (value >> 8))]))
+ buff.append(Data([UInt8(0xff & (value))]))
try ProtocolTransportTry(error: TProtocolError(message: "Transport write failed")) {
try self.transport.write(data: buff)
}
@@ -343,10 +343,10 @@ public class TBinaryProtocol: TProtocol {
public func write(_ value: Int32) throws {
var buff = Data()
- buff.append(Data(bytes: [UInt8(0xff & (value >> 24))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 16))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 8))]))
- buff.append(Data(bytes: [UInt8(0xff & (value))]))
+ buff.append(Data([UInt8(0xff & (value >> 24))]))
+ buff.append(Data([UInt8(0xff & (value >> 16))]))
+ buff.append(Data([UInt8(0xff & (value >> 8))]))
+ buff.append(Data([UInt8(0xff & (value))]))
try ProtocolTransportTry(error: TProtocolError(message: "Transport write failed")) {
try self.transport.write(data: buff)
@@ -355,14 +355,14 @@ public class TBinaryProtocol: TProtocol {
public func write(_ value: Int64) throws {
var buff = Data()
- buff.append(Data(bytes: [UInt8(0xff & (value >> 56))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 48))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 40))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 32))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 24))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 16))]))
- buff.append(Data(bytes: [UInt8(0xff & (value >> 8))]))
- buff.append(Data(bytes: [UInt8(0xff & (value))]))
+ buff.append(Data([UInt8(0xff & (value >> 56))]))
+ buff.append(Data([UInt8(0xff & (value >> 48))]))
+ buff.append(Data([UInt8(0xff & (value >> 40))]))
+ buff.append(Data([UInt8(0xff & (value >> 32))]))
+ buff.append(Data([UInt8(0xff & (value >> 24))]))
+ buff.append(Data([UInt8(0xff & (value >> 16))]))
+ buff.append(Data([UInt8(0xff & (value >> 8))]))
+ buff.append(Data([UInt8(0xff & (value))]))
try ProtocolTransportTry(error: TProtocolError(message: "Transport write failed")) {
try self.transport.write(data: buff)
diff --git a/lib/swift/Sources/TCompactProtocol.swift b/lib/swift/Sources/TCompactProtocol.swift
index 59773c34a..5b302d38f 100644
--- a/lib/swift/Sources/TCompactProtocol.swift
+++ b/lib/swift/Sources/TCompactProtocol.swift
@@ -67,7 +67,7 @@ public class TCompactProtocol: TProtocol {
/// Mark: - TCompactProtocol helpers
func writebyteDirect(_ byte: UInt8) throws {
- let byte = Data(bytes: [byte])
+ let byte = Data([byte])
try ProtocolTransportTry(error: TProtocolError(message: "Transport Write Failed")) {
try self.transport.write(data: byte)
}
@@ -90,7 +90,7 @@ public class TCompactProtocol: TProtocol {
}
try ProtocolTransportTry(error: TProtocolError(message: "Transport Write Failed")) {
- try self.transport.write(data: Data(bytes: i32buf[0..<idx]))
+ try self.transport.write(data: Data(i32buf[0..<idx]))
}
}
@@ -111,9 +111,8 @@ public class TCompactProtocol: TProtocol {
}
try ProtocolTransportTry(error: TProtocolError(message: "Transport Write Failed")) {
- try self.transport.write(data: Data(bytes: varint64out[0..<idx]))
+ try self.transport.write(data: Data(varint64out[0..<idx]))
}
-
}
func writeCollectionBegin(_ elementType: TType, size: Int32) throws {
@@ -249,7 +248,6 @@ public class TCompactProtocol: TProtocol {
let got = String(format:"%2X", protocolId)
throw TProtocolError(message: "Wrong Protocol ID \(got)",
extendedError: .mismatchedProtocol(expected: expected, got: got))
-
}
let versionAndType: UInt8 = try read()
@@ -257,7 +255,6 @@ public class TCompactProtocol: TProtocol {
if version != TCompactProtocol.version {
throw TProtocolError(error: .badVersion(expected: "\(TCompactProtocol.version)",
got:"\(version)"))
-
}
let type = (versionAndType >> UInt8(TCType.typeShiftAmount)) & TCType.typeBits
@@ -485,7 +482,6 @@ public class TCompactProtocol: TProtocol {
}
lastFieldId = UInt8(fieldID)
-
}
public func writeFieldStop() throws {
diff --git a/lib/swift/Sources/TFramedTransport.swift b/lib/swift/Sources/TFramedTransport.swift
index ca385d6d3..59855eb9c 100644
--- a/lib/swift/Sources/TFramedTransport.swift
+++ b/lib/swift/Sources/TFramedTransport.swift
@@ -92,10 +92,10 @@ public class TFramedTransport: TTransport {
private func encodeFrameSize(size: UInt32) -> Data {
var data = Data()
- data.append(Data(bytes: [UInt8(0xff & (size >> 24))]))
- data.append(Data(bytes: [UInt8(0xff & (size >> 16))]))
- data.append(Data(bytes: [UInt8(0xff & (size >> 8))]))
- data.append(Data(bytes: [UInt8(0xff & (size))]))
+ data.append(Data([UInt8(0xff & (size >> 24))]))
+ data.append(Data([UInt8(0xff & (size >> 16))]))
+ data.append(Data([UInt8(0xff & (size >> 8))]))
+ data.append(Data([UInt8(0xff & (size))]))
return data
}
diff --git a/lib/swift/Sources/TMap.swift b/lib/swift/Sources/TMap.swift
index 898037739..dcf1481c6 100644
--- a/lib/swift/Sources/TMap.swift
+++ b/lib/swift/Sources/TMap.swift
@@ -21,7 +21,7 @@ public struct TMap<Key : TSerializable & Hashable, Value : TSerializable>: Colle
public typealias Storage = Dictionary<Key, Value>
public typealias Element = Storage.Element
public typealias Index = Storage.Index
- public typealias IndexDistance = Storage.IndexDistance
+ public typealias IndexDistance = Int
public typealias Indices = Storage.Indices
public typealias SubSequence = Storage.SubSequence
internal var storage = Storage()
@@ -33,11 +33,7 @@ public struct TMap<Key : TSerializable & Hashable, Value : TSerializable>: Colle
}
public mutating func updateValue(_ value: Value, forKey key: Key) -> Value? {
- return updateValue(value, forKey: key)
- }
-
- public mutating func removeAtIndex(_ index: DictionaryIndex<Key, Value>) -> (Key, Value) {
- return removeAtIndex(index)
+ return storage.updateValue(value, forKey: key)
}
public mutating func removeValueForKey(_ key: Key) -> Value? {
diff --git a/lib/swift/Sources/TProtocol.swift b/lib/swift/Sources/TProtocol.swift
index b111e71bb..b4e5dbe73 100644
--- a/lib/swift/Sources/TProtocol.swift
+++ b/lib/swift/Sources/TProtocol.swift
@@ -18,7 +18,6 @@
*/
import Foundation
-//
public enum TMessageType: Int32 {
case call = 1
@@ -99,19 +98,19 @@ public protocol TProtocol {
}
public extension TProtocol {
- public func writeFieldValue(_ value: TSerializable, name: String, type: TType, id: Int32) throws {
+ func writeFieldValue(_ value: TSerializable, name: String, type: TType, id: Int32) throws {
try writeFieldBegin(name: name, type: type, fieldID: id)
try value.write(to: self)
try writeFieldEnd()
}
- public func validateValue(_ value: Any?, named name: String) throws {
+ func validateValue(_ value: Any?, named name: String) throws {
if value == nil {
throw TProtocolError(error: .unknown, message: "Missing required value for field: \(name)")
}
}
- public func readResultMessageBegin() throws {
+ func readResultMessageBegin() throws {
let (_, type, _) = try readMessageBegin();
if type == .exception {
let x = try readException()
@@ -120,17 +119,17 @@ public extension TProtocol {
return
}
- public func readException() throws -> TApplicationError {
+ func readException() throws -> TApplicationError {
return try TApplicationError.read(from: self)
}
- public func writeException(messageName name: String, sequenceID: Int32, ex: TApplicationError) throws {
+ func writeException(messageName name: String, sequenceID: Int32, ex: TApplicationError) throws {
try writeMessageBegin(name: name, type: .exception, sequenceID: sequenceID)
try ex.write(to: self)
try writeMessageEnd()
}
- public func skip(type: TType) throws {
+ func skip(type: TType) throws {
switch type {
case .bool: _ = try read() as Bool
case .i8: _ = try read() as UInt8
diff --git a/lib/swift/Sources/TSSLSocketTransport.swift b/lib/swift/Sources/TSSLSocketTransport.swift
index c2b590266..d350f821e 100644
--- a/lib/swift/Sources/TSSLSocketTransport.swift
+++ b/lib/swift/Sources/TSSLSocketTransport.swift
@@ -20,6 +20,13 @@
import Foundation
import CoreFoundation
+#if !swift(>=4.2)
+// Swift 3/4 compatibility
+fileprivate extension RunLoopMode {
+ static let `default` = defaultRunLoopMode
+}
+#endif
+
#if os(Linux)
public class TSSLSocketTransport {
init(hostname: String, port: UInt16) {
@@ -98,18 +105,18 @@ public class TSSLSocketTransport: TStreamTransport {
CFReadStreamSetProperty(readStream?.takeRetainedValue(),
.SSLSettings,
- settings as CFTypeRef!)
+ settings as CFTypeRef)
CFWriteStreamSetProperty(writeStream?.takeRetainedValue(),
.SSLSettings,
- settings as CFTypeRef!)
+ settings as CFTypeRef)
inputStream = readStream!.takeRetainedValue()
- inputStream?.schedule(in: .current, forMode: .defaultRunLoopMode)
+ inputStream?.schedule(in: .current, forMode: .default)
inputStream?.open()
outputStream = writeStream!.takeRetainedValue()
- outputStream?.schedule(in: .current, forMode: .defaultRunLoopMode)
+ outputStream?.schedule(in: .current, forMode: .default)
outputStream?.open()
readStream?.release()
diff --git a/lib/swift/Sources/TSet.swift b/lib/swift/Sources/TSet.swift
index 1ecd170a5..6891c11e6 100644
--- a/lib/swift/Sources/TSet.swift
+++ b/lib/swift/Sources/TSet.swift
@@ -32,7 +32,7 @@ public struct TSet<Element : TSerializable & Hashable> : SetAlgebra, Hashable, C
public typealias Indices = Storage.Indices
public typealias Index = Storage.Index
- public typealias IndexDistance = Storage.IndexDistance
+ public typealias IndexDistance = Int
public typealias SubSequence = Storage.SubSequence
diff --git a/lib/swift/Sources/TSocketServer.swift b/lib/swift/Sources/TSocketServer.swift
index 0224e67b5..7367c7edc 100644
--- a/lib/swift/Sources/TSocketServer.swift
+++ b/lib/swift/Sources/TSocketServer.swift
@@ -105,7 +105,6 @@ class TSocketServer<InProtocol: TProtocol, OutProtocol: TProtocol, Processor: TP
[weak self] notification in
guard let strongSelf = self else { return }
strongSelf.connectionAccepted(strongSelf.socketFileHandle)
-
}
// tell socket to listen
diff --git a/lib/swift/Sources/TSocketTransport.swift b/lib/swift/Sources/TSocketTransport.swift
index 0316e37d7..21325033b 100644
--- a/lib/swift/Sources/TSocketTransport.swift
+++ b/lib/swift/Sources/TSocketTransport.swift
@@ -29,6 +29,13 @@
import Foundation
import CoreFoundation
+#if !swift(>=4.2)
+// Swift 3/4 compatibility
+fileprivate extension RunLoopMode {
+ static let `default` = defaultRunLoopMode
+}
+#endif
+
private struct Sys {
#if os(Linux)
static let read = Glibc.read
@@ -72,7 +79,7 @@ public class TCFSocketTransport: TStreamTransport {
var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault,
- hostname as CFString!,
+ hostname as CFString,
UInt32(port),
&readStream,
&writeStream)
@@ -88,11 +95,11 @@ public class TCFSocketTransport: TStreamTransport {
}
inputStream = readStream as InputStream
- inputStream.schedule(in: .current, forMode: .defaultRunLoopMode)
+ inputStream.schedule(in: .current, forMode: .default)
inputStream.open()
outputStream = writeStream as OutputStream
- outputStream.schedule(in: .current, forMode: .defaultRunLoopMode)
+ outputStream.schedule(in: .current, forMode: .default)
outputStream.open()
} else {
@@ -140,7 +147,6 @@ public class TSocketTransport : TTransport {
}
-
#if os(Linux)
let sock = socket(AF_INET, Int32(SOCK_STREAM.rawValue), 0)
var addr = sockaddr_in(sin_family: sa_family_t(AF_INET),
@@ -184,7 +190,7 @@ public class TSocketTransport : TTransport {
var buff = Array<UInt8>.init(repeating: 0, count: size)
let readBytes = Sys.read(socketDescriptor, &buff, size)
- return Data(bytes: buff[0..<readBytes])
+ return Data(buff[0..<readBytes])
}
public func write(data: Data) {
diff --git a/lib/swift/Sources/TStreamTransport.swift b/lib/swift/Sources/TStreamTransport.swift
index 26bc1b806..d9c957422 100644
--- a/lib/swift/Sources/TStreamTransport.swift
+++ b/lib/swift/Sources/TStreamTransport.swift
@@ -20,6 +20,13 @@
import Foundation
import CoreFoundation
+#if !swift(>=4.2)
+// Swift 3/4 compatibility
+fileprivate extension RunLoopMode {
+ static let `default` = defaultRunLoopMode
+}
+#endif
+
#if os(Linux)
/// Currently unavailable in Linux
/// Remove comments and build to fix
@@ -64,7 +71,7 @@ import CoreFoundation
if bytesRead <= 0 {
throw TTransportError(error: .notOpen)
}
- read.append(Data(bytes: buffer))
+ read.append(Data(buffer))
}
return read
}
@@ -85,7 +92,7 @@ import CoreFoundation
break
}
- read.append(Data(bytes: buffer))
+ read.append(Data(buffer))
}
return read
}
@@ -124,7 +131,7 @@ import CoreFoundation
input?.delegate = nil
input?.close()
- input?.remove(from: .current, forMode: .defaultRunLoopMode)
+ input?.remove(from: .current, forMode: .default)
input = nil
}
@@ -135,7 +142,7 @@ import CoreFoundation
}
output?.delegate = nil
output?.close()
- output?.remove(from: .current, forMode: .defaultRunLoopMode)
+ output?.remove(from: .current, forMode: .default)
output = nil
}
}
diff --git a/lib/swift/Sources/TStruct.swift b/lib/swift/Sources/TStruct.swift
index f172a32d1..38e51e702 100644
--- a/lib/swift/Sources/TStruct.swift
+++ b/lib/swift/Sources/TStruct.swift
@@ -29,10 +29,10 @@ public protocol TStruct : TSerializable {
}
public extension TStruct {
- public static var fieldIds: [String: (id: Int32, type: TType)] { return [:] }
- public static var thriftType: TType { return .struct }
+ static var fieldIds: [String: (id: Int32, type: TType)] { return [:] }
+ static var thriftType: TType { return .struct }
- public func write(to proto: TProtocol) throws {
+ func write(to proto: TProtocol) throws {
// Write struct name first
try proto.writeStructBegin(name: Self.structName)
@@ -45,7 +45,7 @@ public extension TStruct {
try proto.writeStructEnd()
}
- public var hashValue: Int {
+ var hashValue: Int {
let prime = 31
var result = 1
self.forEach { _, value, _ in