Skip to content

Commit e668585

Browse files
committed
Use the new #available(Android <API>, *) instead from Swift 6.3 to look for backtrace()
Mads just added this compiler feature for Android in swiftlang/swift#84574
1 parent 0cbe3ec commit e668585

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/Testing/SourceAttribution/Backtrace.swift

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

43-
#if os(Android) && !SWT_NO_DYNAMIC_LINKING
43+
#if compiler(<6.3) && os(Android)
4444
/// The `backtrace()` function.
4545
///
4646
/// This function was added to Android with API level 33, which is higher than
@@ -76,7 +76,13 @@ public struct Backtrace: Sendable {
7676
initializedCount = .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
7777
}
7878
#elseif os(Android)
79-
#if !SWT_NO_DYNAMIC_LINKING
79+
#if compiler(>=6.3)
80+
if #available(Android 33, *) {
81+
initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in
82+
.init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
83+
}
84+
}
85+
#else
8086
if let _backtrace {
8187
initializedCount = .init(clamping: _backtrace(addresses.baseAddress!, .init(clamping: addresses.count)))
8288
}

0 commit comments

Comments
 (0)