From bdf9efcc32d46d6e4b692392d435506e69328db7 Mon Sep 17 00:00:00 2001 From: Kenneth Bongort Date: Wed, 29 Apr 2020 15:58:16 -0700 Subject: [PATCH 1/4] Upgrade to swift 5 --- Package.swift | 17 ++++++++++++----- Package@swift-3.swift | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 Package@swift-3.swift diff --git a/Package.swift b/Package.swift index 425fbca..0b88647 100644 --- a/Package.swift +++ b/Package.swift @@ -1,16 +1,23 @@ -// swift-tools-version:3.1 +// swift-tools-version:4.0 import PackageDescription let package = Package( name: "PostgreSQL", + products: [ + .library(name: "PostgreSQL", targets: ["PostgreSQL"]), + ], dependencies: [ // Module map for `libpq` - .Package(url: "https://github.com/vapor-community/cpostgresql.git", majorVersion: 2), - + .package(url: "https://github.com/vapor-community/cpostgresql.git", .upToNextMajor(from: "2.1.0")), + // Data structure for converting between multiple representations - .Package(url: "https://github.com/vapor/node.git", majorVersion: 2), + .package(url: "https://github.com/vapor/node.git", .upToNextMajor(from: "2.1.0")), // Core extensions, type-aliases, and functions that facilitate common tasks - .Package(url: "https://github.com/vapor/core.git", majorVersion: 2) + .package(url: "https://github.com/vapor/core.git", .upToNextMajor(from: "2.1.2")) + ], + targets: [ + .target(name: "PostgreSQL", dependencies: ["CPostgreSQL", "Node", "Core"]), + .testTarget(name: "PostgreSQLTests", dependencies: ["PostgreSQL"]), ] ) diff --git a/Package@swift-3.swift b/Package@swift-3.swift new file mode 100644 index 0000000..425fbca --- /dev/null +++ b/Package@swift-3.swift @@ -0,0 +1,16 @@ +// swift-tools-version:3.1 +import PackageDescription + +let package = Package( + name: "PostgreSQL", + dependencies: [ + // Module map for `libpq` + .Package(url: "https://github.com/vapor-community/cpostgresql.git", majorVersion: 2), + + // Data structure for converting between multiple representations + .Package(url: "https://github.com/vapor/node.git", majorVersion: 2), + + // Core extensions, type-aliases, and functions that facilitate common tasks + .Package(url: "https://github.com/vapor/core.git", majorVersion: 2) + ] +) From 42c3d8b955b30aa73b1ce5ed113da7fc37b6eac2 Mon Sep 17 00:00:00 2001 From: Kenneth Bongort Date: Wed, 29 Apr 2020 16:26:21 -0700 Subject: [PATCH 2/4] Fix build. --- Package.swift | 8 ++++---- Sources/PostgreSQL/Bind/BinaryUtils.swift | 6 +++--- Sources/PostgreSQL/Bind/Bind.swift | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index 0b88647..59f7fb9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:4.0 +// swift-tools-version:5.2 import PackageDescription let package = Package( @@ -8,13 +8,13 @@ let package = Package( ], dependencies: [ // Module map for `libpq` - .package(url: "https://github.com/vapor-community/cpostgresql.git", .upToNextMajor(from: "2.1.0")), + .package(name: "CPostgreSQL", url: "https://github.com/vapor-community/cpostgresql.git", from: "2.1.0"), // Data structure for converting between multiple representations - .package(url: "https://github.com/vapor/node.git", .upToNextMajor(from: "2.1.0")), + .package(name: "Node", url: "https://github.com/vapor/node.git", from: "2.1.0"), // Core extensions, type-aliases, and functions that facilitate common tasks - .package(url: "https://github.com/vapor/core.git", .upToNextMajor(from: "2.1.2")) + .package(name: "Core", url: "https://github.com/vapor/core.git", from: "2.1.2"), ], targets: [ .target(name: "PostgreSQL", dependencies: ["CPostgreSQL", "Node", "Core"]), diff --git a/Sources/PostgreSQL/Bind/BinaryUtils.swift b/Sources/PostgreSQL/Bind/BinaryUtils.swift index 40b9c7d..3038848 100644 --- a/Sources/PostgreSQL/Bind/BinaryUtils.swift +++ b/Sources/PostgreSQL/Bind/BinaryUtils.swift @@ -4,12 +4,12 @@ import Core extension UInt8 { var lowercaseHexPair: String { let hexString = String(self, radix: 16, uppercase: false) - return String(repeating: "0", count: 2 - hexString.characters.count) + hexString + return String(repeating: "0", count: 2 - hexString.count) + hexString } var lowercaseBinaryString: String { let bitString = String(self, radix: 2, uppercase: false) - return String(repeating: "0", count: 8 - bitString.characters.count) + bitString + return String(repeating: "0", count: 8 - bitString.count) + bitString } } @@ -190,7 +190,7 @@ struct BinaryUtils { // The number of digits should be 4 (DEC_DIGITS), // so pad if necessary. - return String(repeating: "0", count: Numeric.decDigits - stringDigits.characters.count) + stringDigits + return String(repeating: "0", count: Numeric.decDigits - stringDigits.count) + stringDigits } /// Function for rounding numeric values. diff --git a/Sources/PostgreSQL/Bind/Bind.swift b/Sources/PostgreSQL/Bind/Bind.swift index 623ee1d..fdc49aa 100644 --- a/Sources/PostgreSQL/Bind/Bind.swift +++ b/Sources/PostgreSQL/Bind/Bind.swift @@ -14,7 +14,7 @@ public final class Bind { deinit { if ownsMemory { - bytes.deallocate(capacity: length) + bytes.deallocate() } } } From 9376b0c100908d2b46092a59975f1a79b73d56b2 Mon Sep 17 00:00:00 2001 From: Kenneth Bongort Date: Tue, 5 May 2020 09:34:15 -0700 Subject: [PATCH 3/4] Move Swift 3 package to just Package.swift, and Swift 5.2 package to Package@swift-5.2.swift. --- Package.swift | 17 +++++------------ Package@swift-3.swift | 16 ---------------- Package@swift-5.2.swift | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) delete mode 100644 Package@swift-3.swift create mode 100644 Package@swift-5.2.swift diff --git a/Package.swift b/Package.swift index 59f7fb9..425fbca 100644 --- a/Package.swift +++ b/Package.swift @@ -1,23 +1,16 @@ -// swift-tools-version:5.2 +// swift-tools-version:3.1 import PackageDescription let package = Package( name: "PostgreSQL", - products: [ - .library(name: "PostgreSQL", targets: ["PostgreSQL"]), - ], dependencies: [ // Module map for `libpq` - .package(name: "CPostgreSQL", url: "https://github.com/vapor-community/cpostgresql.git", from: "2.1.0"), - + .Package(url: "https://github.com/vapor-community/cpostgresql.git", majorVersion: 2), + // Data structure for converting between multiple representations - .package(name: "Node", url: "https://github.com/vapor/node.git", from: "2.1.0"), + .Package(url: "https://github.com/vapor/node.git", majorVersion: 2), // Core extensions, type-aliases, and functions that facilitate common tasks - .package(name: "Core", url: "https://github.com/vapor/core.git", from: "2.1.2"), - ], - targets: [ - .target(name: "PostgreSQL", dependencies: ["CPostgreSQL", "Node", "Core"]), - .testTarget(name: "PostgreSQLTests", dependencies: ["PostgreSQL"]), + .Package(url: "https://github.com/vapor/core.git", majorVersion: 2) ] ) diff --git a/Package@swift-3.swift b/Package@swift-3.swift deleted file mode 100644 index 425fbca..0000000 --- a/Package@swift-3.swift +++ /dev/null @@ -1,16 +0,0 @@ -// swift-tools-version:3.1 -import PackageDescription - -let package = Package( - name: "PostgreSQL", - dependencies: [ - // Module map for `libpq` - .Package(url: "https://github.com/vapor-community/cpostgresql.git", majorVersion: 2), - - // Data structure for converting between multiple representations - .Package(url: "https://github.com/vapor/node.git", majorVersion: 2), - - // Core extensions, type-aliases, and functions that facilitate common tasks - .Package(url: "https://github.com/vapor/core.git", majorVersion: 2) - ] -) diff --git a/Package@swift-5.2.swift b/Package@swift-5.2.swift new file mode 100644 index 0000000..59f7fb9 --- /dev/null +++ b/Package@swift-5.2.swift @@ -0,0 +1,23 @@ +// swift-tools-version:5.2 +import PackageDescription + +let package = Package( + name: "PostgreSQL", + products: [ + .library(name: "PostgreSQL", targets: ["PostgreSQL"]), + ], + dependencies: [ + // Module map for `libpq` + .package(name: "CPostgreSQL", url: "https://github.com/vapor-community/cpostgresql.git", from: "2.1.0"), + + // Data structure for converting between multiple representations + .package(name: "Node", url: "https://github.com/vapor/node.git", from: "2.1.0"), + + // Core extensions, type-aliases, and functions that facilitate common tasks + .package(name: "Core", url: "https://github.com/vapor/core.git", from: "2.1.2"), + ], + targets: [ + .target(name: "PostgreSQL", dependencies: ["CPostgreSQL", "Node", "Core"]), + .testTarget(name: "PostgreSQLTests", dependencies: ["PostgreSQL"]), + ] +) From 18755af8de5e22773a07a1524195bb3fe0dffba2 Mon Sep 17 00:00:00 2001 From: Kenneth Bongort Date: Fri, 8 May 2020 14:35:22 -0700 Subject: [PATCH 4/4] Keep old verison of code for Swift <5, to maintain compatibility. --- Sources/PostgreSQL/Bind/BinaryUtils.swift | 12 ++++++++++++ Sources/PostgreSQL/Bind/Bind.swift | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/Sources/PostgreSQL/Bind/BinaryUtils.swift b/Sources/PostgreSQL/Bind/BinaryUtils.swift index 3038848..e513b66 100644 --- a/Sources/PostgreSQL/Bind/BinaryUtils.swift +++ b/Sources/PostgreSQL/Bind/BinaryUtils.swift @@ -4,12 +4,20 @@ import Core extension UInt8 { var lowercaseHexPair: String { let hexString = String(self, radix: 16, uppercase: false) + #if swift(>=5.0) return String(repeating: "0", count: 2 - hexString.count) + hexString + #else + return String(repeating: "0", count: 2 - hexString.characters.count) + hexString + #endif } var lowercaseBinaryString: String { let bitString = String(self, radix: 2, uppercase: false) + #if swift(>=5.0) return String(repeating: "0", count: 8 - bitString.count) + bitString + #else + return String(repeating: "0", count: 8 - bitString.characters.count) + bitString + #endif } } @@ -190,7 +198,11 @@ struct BinaryUtils { // The number of digits should be 4 (DEC_DIGITS), // so pad if necessary. + #if swift(>=5.0) return String(repeating: "0", count: Numeric.decDigits - stringDigits.count) + stringDigits + #else + return String(repeating: "0", count: Numeric.decDigits - stringDigits.characters.count) + stringDigits + #endif } /// Function for rounding numeric values. diff --git a/Sources/PostgreSQL/Bind/Bind.swift b/Sources/PostgreSQL/Bind/Bind.swift index fdc49aa..9051da1 100644 --- a/Sources/PostgreSQL/Bind/Bind.swift +++ b/Sources/PostgreSQL/Bind/Bind.swift @@ -14,7 +14,11 @@ public final class Bind { deinit { if ownsMemory { + #if swift(>=5.0) bytes.deallocate() + #else + bytes.deallocate(capacity: length) + #endif } } }