Skip to content

Commit 82e3221

Browse files
committed
Use the new #available(Android API, *) instead to look for backtrace()
Mads just added this compiler feature for Android in swiftlang/swift#84574
1 parent 38067d6 commit 82e3221

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

Sources/Testing/SourceAttribution/Backtrace.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ public struct Backtrace: Sendable {
4040
self.addresses = addresses.map { Address(UInt(bitPattern: $0)) }
4141
}
4242

43-
#if os(Android) && !SWT_NO_DYNAMIC_LINKING
44-
/// The `backtrace()` function.
45-
///
46-
/// This function was added to Android with API level 33, which is higher than
47-
/// our minimum deployment target, so we look it up dynamically at runtime.
48-
private static let _backtrace = symbol(named: "backtrace").map {
49-
castCFunction(at: $0, to: (@convention(c) (UnsafeMutablePointer<UnsafeMutableRawPointer?>, CInt) -> CInt).self)
50-
}
51-
#endif
52-
5343
/// Get the current backtrace.
5444
///
5545
/// - Parameters:
@@ -77,8 +67,10 @@ public struct Backtrace: Sendable {
7767
}
7868
#elseif os(Android)
7969
#if !SWT_NO_DYNAMIC_LINKING
80-
if let _backtrace {
81-
initializedCount = .init(clamping: _backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
70+
if #available(Android 33, *) {
71+
initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in
72+
.init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
73+
}
8274
}
8375
#endif
8476
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD)

0 commit comments

Comments
 (0)