Skip to content

Commit 6a2b13e

Browse files
committed
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
1 parent 97fd7b6 commit 6a2b13e

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Sources/StructuredHeaders/FieldParser.swift

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,25 @@ extension String {
522522
// We assume the string is previously validated, so the escapes are easily removed. See the doc comment for
523523
// `StrippingStringEscapesCollection` for more details on what we're doing here.
524524
let unescapedBytes = StrippingStringEscapesCollection(bytes, escapes: escapes)
525-
if #available(macOS 10.16, macCatalyst 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
526-
return String(unsafeUninitializedCapacity: unescapedBytes.count) { innerPtr in
527-
let (_, endIndex) = innerPtr.initialize(from: unescapedBytes)
528-
return endIndex
525+
#if canImport(Darwin)
526+
if #available(macOS 10.16, macCatalyst 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *) {
527+
return String(unsafeUninitializedCapacity: unescapedBytes.count) { innerPtr in
528+
let (_, endIndex) = innerPtr.initialize(from: unescapedBytes)
529+
return endIndex
530+
}
531+
} else {
532+
return String(decoding: unescapedBytes, as: UTF8.self)
529533
}
530-
} else {
531-
return String(decoding: unescapedBytes, as: UTF8.self)
532-
}
534+
#else
535+
#if compiler(>=5.3)
536+
return String(unsafeUninitializedCapacity: unescapedBytes.count) { innerPtr in
537+
let (_, endIndex) = innerPtr.initialize(from: unescapedBytes)
538+
return endIndex
539+
}
540+
#else
541+
return String(decoding: unescapedBytes, as: UTF8.self)
542+
#endif
543+
#endif
533544
}
534545
}
535546

Sources/StructuredHeaders/PseudoDecimal.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
//===----------------------------------------------------------------------===//
1414
#if canImport(Darwin)
1515
import Darwin
16-
#elseif canImport(GLibc)
17-
import GLibc
16+
#elseif canImport(Glibc)
17+
import Glibc
1818
#else
1919
#error("Unsupported OS")
2020
#endif

0 commit comments

Comments
 (0)