-
Notifications
You must be signed in to change notification settings - Fork 131
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 |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ jobs: | |
| ios_host_exclude_xcode_versions: '[{"xcode_version": "16.2"}, {"xcode_version": "16.3"}, {"xcode_version": "16.4"}]' | ||
| enable_wasm_sdk_build: true | ||
| enable_android_sdk_build: true | ||
| android_ndk_versions: '["r28c"]' | ||
| android_sdk_triples: '["aarch64-unknown-linux-android33", "x86_64-unknown-linux-android28"]' | ||
| soundness: | ||
| name: Soundness | ||
| uses: swiftlang/github-workflows/.github/workflows/[email protected] | ||
|
|
||
| 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) | ||
| /// 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.
why have you changed the order of conditionals here?
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.
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 comment
The 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?
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.
No idea what you mean by complexity in this context, I just figured that the compiler check is more generally known by Swift devs.
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.
Actually,
compiler()has special powers in the compiler (heh). If it evaluates tofalse, subsequent conditions are not even parsed. This means that you can write something like#if compiler(>=6.3) && objectFormat(ELF)and an older compiler won't complain that it doesn't know whatobjectFormat()is.It's good to get into the habit of putting
compiler()first for this reason.