File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Sources/Testing/SourceAttribution Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,16 @@ 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+
4353 /// Get the current backtrace.
4454 ///
4555 /// - Parameters:
@@ -66,9 +76,9 @@ public struct Backtrace: Sendable {
6676 initializedCount = . init( clamping: backtrace ( addresses. baseAddress!, . init( clamping: addresses. count) ) )
6777 }
6878#elseif os(Android)
69- initializedCount = addresses . withMemoryRebound ( to : UnsafeMutableRawPointer . self ) { addresses in
70- . init( clamping: backtrace ( addresses. baseAddress!, . init( clamping: addresses. count) ) )
71- }
79+ #if !SWT_NO_DYNAMIC_LINKING
80+ initializedCount = . init( clamping: _backtrace ? ( addresses. baseAddress!, . init( clamping: addresses. count) ) )
81+ #endif
7282#elseif os(Linux) || os(FreeBSD) || os(OpenBSD)
7383 initializedCount = . init( clamping: backtrace ( addresses. baseAddress!, . init( clamping: addresses. count) ) )
7484#elseif os(Windows)
You can’t perform that action at this time.
0 commit comments