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
This commit is contained in:
Cory Benfield committed 2020-07-20 12:44:21 +01:00
1 parent 97fd7b6bbc
commit 6a2b13e370
2 files changed
+20 -9

No files matched your search

+18 -7
View File
@@ -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
}
}
@@ -13,8 +13,8 @@
//===----------------------------------------------------------------------===//
#if canImport(Darwin)
import Darwin
#elseif canImport(GLibc)
import GLibc
#elseif canImport(Glibc)
import Glibc
#else
#error("Unsupported OS")
#endif