From 6a2b13e37035116fdd7450863e0c50843a63e175 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 20 Jul 2020 12:44:21 +0100 Subject: [PATCH] Fix the build on Linux Motivation: A number of the changes in the code for running on Linux were not validated ahead of time, and broke the build. Modifications: - Correct the spelling of Glibc - Modified string initialization on non-Darwin platforms Results: Builds and passes tests on Linux --- Sources/StructuredHeaders/FieldParser.swift | 25 +++++++++++++------ Sources/StructuredHeaders/PseudoDecimal.swift | 4 +-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Sources/StructuredHeaders/FieldParser.swift b/Sources/StructuredHeaders/FieldParser.swift index 02f188a..59fd342 100644 --- a/Sources/StructuredHeaders/FieldParser.swift +++ b/Sources/StructuredHeaders/FieldParser.swift @@ -522,14 +522,25 @@ extension String { // We assume the string is previously validated, so the escapes are easily removed. See the doc comment for // `StrippingStringEscapesCollection` for more details on what we're doing here. let unescapedBytes = StrippingStringEscapesCollection(bytes, escapes: escapes) - if #available(macOS 10.16, macCatalyst 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { - return String(unsafeUninitializedCapacity: unescapedBytes.count) { innerPtr in - let (_, endIndex) = innerPtr.initialize(from: unescapedBytes) - return endIndex + #if canImport(Darwin) + if #available(macOS 10.16, macCatalyst 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *) { + return String(unsafeUninitializedCapacity: unescapedBytes.count) { innerPtr in + let (_, endIndex) = innerPtr.initialize(from: unescapedBytes) + return endIndex + } + } else { + return String(decoding: unescapedBytes, as: UTF8.self) } - } else { - return String(decoding: unescapedBytes, as: UTF8.self) - } + #else + #if compiler(>=5.3) + return String(unsafeUninitializedCapacity: unescapedBytes.count) { innerPtr in + let (_, endIndex) = innerPtr.initialize(from: unescapedBytes) + return endIndex + } + #else + return String(decoding: unescapedBytes, as: UTF8.self) + #endif + #endif } } diff --git a/Sources/StructuredHeaders/PseudoDecimal.swift b/Sources/StructuredHeaders/PseudoDecimal.swift index 93b6246..87e7bd5 100644 --- a/Sources/StructuredHeaders/PseudoDecimal.swift +++ b/Sources/StructuredHeaders/PseudoDecimal.swift @@ -13,8 +13,8 @@ //===----------------------------------------------------------------------===// #if canImport(Darwin) import Darwin -#elseif canImport(GLibc) -import GLibc +#elseif canImport(Glibc) +import Glibc #else #error("Unsupported OS") #endif