-
Notifications
You must be signed in to change notification settings - Fork 129
Use the new #available(Android API, *) instead to look for backtrace()
#1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ public struct Backtrace: Sendable { | |
| self.addresses = addresses.map { Address(UInt(bitPattern: $0)) } | ||
| } | ||
|
|
||
| #if os(Android) && !SWT_NO_DYNAMIC_LINKING | ||
| #if compiler(<6.3) && os(Android) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why have you changed the order of conditionals here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No particular reason, just the perception that such compiler versioning is more important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which conditional has more complexity, the compiler version check or the os check?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea what you mean by complexity in this context, I just figured that the compiler check is more generally known by Swift devs.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, It's good to get into the habit of putting |
||
| /// The `backtrace()` function. | ||
| /// | ||
| /// This function was added to Android with API level 33, which is higher than | ||
|
|
@@ -76,7 +76,13 @@ public struct Backtrace: Sendable { | |
| initializedCount = .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) | ||
| } | ||
| #elseif os(Android) | ||
| #if !SWT_NO_DYNAMIC_LINKING | ||
| #if compiler(>=6.3) | ||
| if #available(Android 33, *) { | ||
| initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in | ||
| .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe an if let for baseAddress here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this almost always succeeds- unless the allocation up top fails?- so the unwrapping is a mere formality, but I'm just bringing back Jonathan's earlier code here: I didn't write this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, for some reason (correct me I'm wrong) the closure gives you a buggy object with nil property references (such as a de-reference issue) maybe you will lead this into a SIGTRAP I think
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my experience, this always works and is a common idiom in the Swift corelibs.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unwrap cannot fail. Hence the forced unwrap. There is no point in an
|
||
| } | ||
| } | ||
| #else | ||
| if let _backtrace { | ||
| initializedCount = .init(clamping: _backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be
android_ndk_versions(plural) now; I changed it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, r27d is the LTS NDK release, so maybe we should keep that and include r28?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't, as this new
#available(Androidfeature in trunk and 6.3 only compiles with NDK 28 or later- the Bionic libc changed how it versioned its APIs by API level starting with NDK 28 and this feature requires that change- hence the drive to get all trunk/6.3 CI on NDK 28 or 29 now, in preparation for the likely next LTS NDK 30.