From 941acf398f0bcb49410af42bf792011fe25f7217 Mon Sep 17 00:00:00 2001 From: wyland Date: Mon, 8 Jul 2019 20:07:12 -0400 Subject: [PATCH 1/4] fixes for swift4 manifest and some swift4 deprecation errors --- .swift-version | 1 + Package.swift | 7 ++++++- Sources/TSSLSocketTransport.swift | 8 ++++++++ Sources/TSocketTransport.swift | 8 ++++++++ Sources/TStreamTransport.swift | 8 ++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..c4e41f9 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +4.0.3 diff --git a/Package.swift b/Package.swift index b533f60..dda3df6 100644 --- a/Package.swift +++ b/Package.swift @@ -1,3 +1,5 @@ +// swift-tools-version:4.0 + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -20,5 +22,8 @@ import PackageDescription let package = Package( - name: "Thrift" + name: "Thrift", + targets: [ + .target(name: "Thrift", path: "Sources") + ] ) diff --git a/Sources/TSSLSocketTransport.swift b/Sources/TSSLSocketTransport.swift index c2b5902..c21b5b3 100644 --- a/Sources/TSSLSocketTransport.swift +++ b/Sources/TSSLSocketTransport.swift @@ -105,11 +105,19 @@ public class TSSLSocketTransport: TStreamTransport { settings as CFTypeRef!) inputStream = readStream!.takeRetainedValue() + #if swift(>=4.0) + inputStream?.schedule(in: .current, forMode: RunLoop.Mode.default) + #else inputStream?.schedule(in: .current, forMode: .defaultRunLoopMode) + #endif inputStream?.open() outputStream = writeStream!.takeRetainedValue() + #if swift(>=4.0) + outputStream?.schedule(in: .current, forMode: RunLoop.Mode.default) + #else outputStream?.schedule(in: .current, forMode: .defaultRunLoopMode) + #endif outputStream?.open() readStream?.release() diff --git a/Sources/TSocketTransport.swift b/Sources/TSocketTransport.swift index 0316e37..e6a64ad 100644 --- a/Sources/TSocketTransport.swift +++ b/Sources/TSocketTransport.swift @@ -88,11 +88,19 @@ public class TCFSocketTransport: TStreamTransport { } inputStream = readStream as InputStream + #if swift(>=4.0) + inputStream.schedule(in: .current, forMode: RunLoop.Mode.default) + #else inputStream.schedule(in: .current, forMode: .defaultRunLoopMode) + #endif inputStream.open() outputStream = writeStream as OutputStream + #if swift(>=4.0) + outputStream.schedule(in: .current, forMode: RunLoop.Mode.default) + #else outputStream.schedule(in: .current, forMode: .defaultRunLoopMode) + #endif outputStream.open() } else { diff --git a/Sources/TStreamTransport.swift b/Sources/TStreamTransport.swift index 26bc1b8..da46137 100644 --- a/Sources/TStreamTransport.swift +++ b/Sources/TStreamTransport.swift @@ -124,7 +124,11 @@ import CoreFoundation input?.delegate = nil input?.close() + #if swift(>=4.0) + input?.remove(from: .current, forMode: RunLoop.Mode.default) + #else input?.remove(from: .current, forMode: .defaultRunLoopMode) + #endif input = nil } @@ -135,7 +139,11 @@ import CoreFoundation } output?.delegate = nil output?.close() + #if swift(>=4.0) + output?.remove(from: .current, forMode: RunLoop.Mode.default) + #else output?.remove(from: .current, forMode: .defaultRunLoopMode) + #endif output = nil } } From a9bc1ea4307b8cd3d4db5bf3f64b35b6e02d2326 Mon Sep 17 00:00:00 2001 From: wyland Date: Wed, 17 Jul 2019 13:35:57 -0400 Subject: [PATCH 2/4] migrated to swift4.2 and fixed warnings --- .swift-version | 2 +- Package.swift | 2 +- Sources/TMap.swift | 6 +++--- Sources/TSSLSocketTransport.swift | 12 ++---------- Sources/TSet.swift | 2 +- Sources/TSocketTransport.swift | 10 +--------- Sources/TStreamTransport.swift | 8 -------- 7 files changed, 9 insertions(+), 33 deletions(-) diff --git a/.swift-version b/.swift-version index c4e41f9..bf77d54 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.0.3 +4.2 diff --git a/Package.swift b/Package.swift index dda3df6..b80de1e 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:4.2 /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/Sources/TMap.swift b/Sources/TMap.swift index 8980377..52d7a43 100644 --- a/Sources/TMap.swift +++ b/Sources/TMap.swift @@ -21,7 +21,7 @@ public struct TMap: Colle public typealias Storage = Dictionary 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,11 @@ public struct TMap: Colle } public mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { - return updateValue(value, forKey: key) + return storage.updateValue(value, forKey: key) } public mutating func removeAtIndex(_ index: DictionaryIndex) -> (Key, Value) { - return removeAtIndex(index) + return storage.remove(at: index) } public mutating func removeValueForKey(_ key: Key) -> Value? { diff --git a/Sources/TSSLSocketTransport.swift b/Sources/TSSLSocketTransport.swift index c21b5b3..0d0cb5c 100644 --- a/Sources/TSSLSocketTransport.swift +++ b/Sources/TSSLSocketTransport.swift @@ -98,26 +98,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() - #if swift(>=4.0) inputStream?.schedule(in: .current, forMode: RunLoop.Mode.default) - #else - inputStream?.schedule(in: .current, forMode: .defaultRunLoopMode) - #endif inputStream?.open() outputStream = writeStream!.takeRetainedValue() - #if swift(>=4.0) outputStream?.schedule(in: .current, forMode: RunLoop.Mode.default) - #else - outputStream?.schedule(in: .current, forMode: .defaultRunLoopMode) - #endif outputStream?.open() readStream?.release() diff --git a/Sources/TSet.swift b/Sources/TSet.swift index 1ecd170..6891c11 100644 --- a/Sources/TSet.swift +++ b/Sources/TSet.swift @@ -32,7 +32,7 @@ public struct TSet : 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/Sources/TSocketTransport.swift b/Sources/TSocketTransport.swift index e6a64ad..e98f480 100644 --- a/Sources/TSocketTransport.swift +++ b/Sources/TSocketTransport.swift @@ -72,7 +72,7 @@ public class TCFSocketTransport: TStreamTransport { var readStream: Unmanaged? var writeStream: Unmanaged? CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, - hostname as CFString!, + hostname as CFString, UInt32(port), &readStream, &writeStream) @@ -88,19 +88,11 @@ public class TCFSocketTransport: TStreamTransport { } inputStream = readStream as InputStream - #if swift(>=4.0) inputStream.schedule(in: .current, forMode: RunLoop.Mode.default) - #else - inputStream.schedule(in: .current, forMode: .defaultRunLoopMode) - #endif inputStream.open() outputStream = writeStream as OutputStream - #if swift(>=4.0) outputStream.schedule(in: .current, forMode: RunLoop.Mode.default) - #else - outputStream.schedule(in: .current, forMode: .defaultRunLoopMode) - #endif outputStream.open() } else { diff --git a/Sources/TStreamTransport.swift b/Sources/TStreamTransport.swift index da46137..d0a024d 100644 --- a/Sources/TStreamTransport.swift +++ b/Sources/TStreamTransport.swift @@ -124,11 +124,7 @@ import CoreFoundation input?.delegate = nil input?.close() - #if swift(>=4.0) input?.remove(from: .current, forMode: RunLoop.Mode.default) - #else - input?.remove(from: .current, forMode: .defaultRunLoopMode) - #endif input = nil } @@ -139,11 +135,7 @@ import CoreFoundation } output?.delegate = nil output?.close() - #if swift(>=4.0) output?.remove(from: .current, forMode: RunLoop.Mode.default) - #else - output?.remove(from: .current, forMode: .defaultRunLoopMode) - #endif output = nil } } From 2e7644d2500f6eb3ad0e5350fb4d84c7b267ded0 Mon Sep 17 00:00:00 2001 From: Felix Nensa Date: Mon, 9 Jan 2023 12:17:51 +0100 Subject: [PATCH 3/4] Updated to Swift 5.1 --- Package.swift | 2 +- Sources/TSet.swift | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Package.swift b/Package.swift index b80de1e..a0eaf34 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.1 /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/Sources/TSet.swift b/Sources/TSet.swift index 6891c11..c106a4a 100644 --- a/Sources/TSet.swift +++ b/Sources/TSet.swift @@ -19,11 +19,11 @@ import Foundation -public struct TSet : SetAlgebra, Hashable, Collection, ExpressibleByArrayLiteral, TSerializable { +public struct TSet : Collection, Hashable, SetAlgebra, ExpressibleByArrayLiteral, TSerializable { + /// Typealias for Storage type public typealias Storage = Set - /// Internal Storage used for TSet (Set\) internal var storage : Storage @@ -40,7 +40,7 @@ public struct TSet : SetAlgebra, Hashable, C // Must implement isEmpty even though both SetAlgebra and Collection provide it due to their conflciting default implementations public var isEmpty: Bool { return storage.isEmpty } - + public func distance(from start: Index, to end: Index) -> IndexDistance { return storage.distance(from: start, to: end) } @@ -67,7 +67,7 @@ public struct TSet : SetAlgebra, Hashable, C internal init(storage: Set) { self.storage = storage } - + public func contains(_ member: Element) -> Bool { return storage.contains(member) } @@ -80,28 +80,28 @@ public struct TSet : SetAlgebra, Hashable, C return storage.remove(member) } - public func union(_ other: TSet) -> TSet { - return TSet(storage: storage.union(other.storage)) + public func union(_ other: __owned TSet) -> TSet { + return TSet(storage: storage.union(other.storage)) } public mutating func formIntersection(_ other: TSet) { return storage.formIntersection(other.storage) } - public mutating func formSymmetricDifference(_ other: TSet) { + public mutating func formSymmetricDifference(_ other: __owned TSet) { return storage.formSymmetricDifference(other.storage) } - public mutating func formUnion(_ other: TSet) { + public mutating func formUnion(_ other: __owned TSet) { return storage.formUnion(other.storage) } - public func intersection(_ other: TSet) -> TSet { - return TSet(storage: storage.intersection(other.storage)) + public func intersection(_ other: TSet) -> TSet { + return TSet(storage: storage.intersection(other.storage)) } - public func symmetricDifference(_ other: TSet) -> TSet { - return TSet(storage: storage.symmetricDifference(other.storage)) + public func symmetricDifference(_ other: __owned TSet) -> TSet { + return TSet(storage: storage.symmetricDifference(other.storage)) } public mutating func update(with newMember: Element) -> Element? { @@ -135,6 +135,10 @@ public struct TSet : SetAlgebra, Hashable, C return result } + public func hash(into hasher: inout Hasher) { + hasher.combine(hashValue) + } + /// Mark: TSerializable public static var thriftType : TType { return .set } @@ -150,13 +154,13 @@ public struct TSet : SetAlgebra, Hashable, C storage = Storage(sequence) } - public static func read(from proto: TProtocol) throws -> TSet { + public static func read(from proto: TProtocol) throws -> TSet { let (elementType, size) = try proto.readSetBegin() if elementType != Element.thriftType { throw TProtocolError(error: .invalidData, extendedError: .unexpectedType(type: elementType)) } - var set = TSet() + var set = TSet() for _ in 0.. Date: Mon, 9 Jan 2023 12:22:48 +0100 Subject: [PATCH 4/4] Updated to Swift 5.7 --- Package.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Package.swift b/Package.swift index a0eaf34..b313674 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,5 @@ -// swift-tools-version:5.1 +// swift-tools-version: 5.7 +// The swift-tools-version declares the minimum version of Swift required to build this package. /* * Licensed to the Apache Software Foundation (ASF) under one @@ -23,7 +24,12 @@ import PackageDescription let package = Package( name: "Thrift", - targets: [ - .target(name: "Thrift", path: "Sources") - ] + products: [ + .library( + name: "Thrift", + targets: ["Thrift"]), + ], + targets: [ + .target(name: "Thrift", path: "Sources") + ] )