From c583ea37290b628cced44c12ae09f226179c0450 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Tue, 21 Jan 2025 15:16:08 -0500 Subject: [PATCH] Use `swift_getErrorValue()` unless Objective-C is available. Tweak the logic for when we use the runtime-internal `swift_getErrorValue()` function in our `_swift_willThrow` handler so that we use it if the runtime does not support Objective-C interop. Currently, we toggle based on whether we're on an Apple platform, but this isn't quite right. Resolves rdar://143328537. --- Sources/Testing/SourceAttribution/Backtrace.swift | 4 ++-- Sources/_TestingInternals/include/WillThrow.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Testing/SourceAttribution/Backtrace.swift b/Sources/Testing/SourceAttribution/Backtrace.swift index a6019860c..78227e3da 100644 --- a/Sources/Testing/SourceAttribution/Backtrace.swift +++ b/Sources/Testing/SourceAttribution/Backtrace.swift @@ -133,7 +133,7 @@ extension Backtrace { /// - errorAddress: The address of the error existential box. init(_ errorAddress: UnsafeMutableRawPointer) { _rawValue = errorAddress -#if SWT_TARGET_OS_APPLE +#if _runtime(_ObjC) let error = Unmanaged.fromOpaque(errorAddress).takeUnretainedValue() as! any Error if type(of: error) is AnyObject.Type { _rawValue = Unmanaged.passUnretained(error as AnyObject).toOpaque() @@ -336,7 +336,7 @@ extension Backtrace { /// - Note: The underlying Foundation function is called (if present) the /// first time the value of this property is read. static let isFoundationCaptureEnabled = { -#if SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING +#if _runtime(_ObjC) && !SWT_NO_DYNAMIC_LINKING if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") == true { let _CFErrorSetCallStackCaptureEnabled = symbol(named: "_CFErrorSetCallStackCaptureEnabled").map { unsafeBitCast($0, to: (@convention(c) (DarwinBoolean) -> DarwinBoolean).self) diff --git a/Sources/_TestingInternals/include/WillThrow.h b/Sources/_TestingInternals/include/WillThrow.h index 3d5a7c319..13331773f 100644 --- a/Sources/_TestingInternals/include/WillThrow.h +++ b/Sources/_TestingInternals/include/WillThrow.h @@ -71,8 +71,8 @@ typedef void (* SWT_SENDABLE SWTWillThrowTypedHandler)(void *error, const void * /// ``SWTWillThrowTypedHandler`` SWT_EXTERN SWTWillThrowTypedHandler SWT_SENDABLE _Nullable swt_setWillThrowTypedHandler(SWTWillThrowTypedHandler SWT_SENDABLE _Nullable handler); -#if !defined(__APPLE__) -/// The result of `swift__getErrorValue()`. +#if defined(__swift__) && !defined(__OBJC__) +/// The result of `swift_getErrorValue()`. /// /// For more information, see this type's declaration /// [in the Swift repository](https://github.com/swiftlang/swift/blob/main/include/swift/Runtime/Error.h).