Pull request #68 prevents Backtrace from being built on Swift 5.9 and above, but Demangle is still built and fails when the importing project uses musl.
64 lines
1.8 KiB
Swift
64 lines
1.8 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftLinuxBacktrace open source project
|
|
//
|
|
// Copyright (c) 2019-2020 Apple Inc. and the SwiftLinuxBacktrace project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftLinuxBacktrace project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Swift 5.9 has its own built-in backtracing support in the runtime;
|
|
// we don't want to activate this library if we're using 5.9 or above.
|
|
#if !(swift(>=5.9) && !os(Windows))
|
|
|
|
#if os(Linux)
|
|
import Glibc
|
|
#elseif os(Windows)
|
|
#if swift(<5.4)
|
|
#error("unsupported Swift version")
|
|
#else
|
|
@_implementationOnly
|
|
import ucrt
|
|
#endif
|
|
#endif
|
|
|
|
#if os(Linux) || os(Windows)
|
|
@_silgen_name("swift_demangle")
|
|
public
|
|
func _stdlib_demangleImpl(
|
|
mangledName: UnsafePointer<CChar>?,
|
|
mangledNameLength: UInt,
|
|
outputBuffer: UnsafeMutablePointer<CChar>?,
|
|
outputBufferSize: UnsafeMutablePointer<UInt>?,
|
|
flags: UInt32
|
|
) -> UnsafeMutablePointer<CChar>?
|
|
|
|
internal func _stdlib_demangleName(_ mangledName: String) -> String {
|
|
return mangledName.utf8CString.withUnsafeBufferPointer {
|
|
mangledNameUTF8CStr in
|
|
|
|
let demangledNamePtr = _stdlib_demangleImpl(
|
|
mangledName: mangledNameUTF8CStr.baseAddress,
|
|
mangledNameLength: UInt(mangledNameUTF8CStr.count - 1),
|
|
outputBuffer: nil,
|
|
outputBufferSize: nil,
|
|
flags: 0
|
|
)
|
|
|
|
if let demangledNamePtr = demangledNamePtr {
|
|
let demangledName = String(cString: demangledNamePtr)
|
|
free(demangledNamePtr)
|
|
return demangledName
|
|
}
|
|
return mangledName
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#endif
|