Skip to content

Refine the Foundation error backtracing guard #813

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

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions Sources/Testing/SourceAttribution/Backtrace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,15 @@ extension Backtrace {
/// first time the value of this property is read.
static let isFoundationCaptureEnabled = {
#if SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING
let _CFErrorSetCallStackCaptureEnabled = symbol(named: "_CFErrorSetCallStackCaptureEnabled").map {
unsafeBitCast($0, to: (@convention(c) (DarwinBoolean) -> DarwinBoolean).self)
if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") == true {
let _CFErrorSetCallStackCaptureEnabled = symbol(named: "_CFErrorSetCallStackCaptureEnabled").map {
unsafeBitCast($0, to: (@convention(c) (DarwinBoolean) -> DarwinBoolean).self)
}
_ = _CFErrorSetCallStackCaptureEnabled?(true)
return _CFErrorSetCallStackCaptureEnabled != nil
}
_ = _CFErrorSetCallStackCaptureEnabled?(true)
return _CFErrorSetCallStackCaptureEnabled != nil
#else
false
#endif
return false
}()

/// The implementation of ``Backtrace/startCachingForThrownErrors()``, run
Expand All @@ -353,11 +354,7 @@ extension Backtrace {
/// This value is named oddly so that it shows up clearly in symbolicated
/// backtraces.
private static let __SWIFT_TESTING_IS_CAPTURING_A_BACKTRACE_FOR_A_THROWN_ERROR__: Void = {
#if SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING
if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") != false {
_ = isFoundationCaptureEnabled
}
#endif
_ = isFoundationCaptureEnabled

if Environment.flag(named: "SWT_SWIFT_ERROR_BACKTRACING_ENABLED") != false {
_oldWillThrowHandler.withLock { oldWillThrowHandler in
Expand Down