Skip to content

Commit faaabba

Browse files
authored
Use swift_getErrorValue() unless Objective-C is available. (#922)
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. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 8836b38 commit faaabba

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Sources/Testing/SourceAttribution/Backtrace.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ extension Backtrace {
133133
/// - errorAddress: The address of the error existential box.
134134
init(_ errorAddress: UnsafeMutableRawPointer) {
135135
_rawValue = errorAddress
136-
#if SWT_TARGET_OS_APPLE
136+
#if _runtime(_ObjC)
137137
let error = Unmanaged<AnyObject>.fromOpaque(errorAddress).takeUnretainedValue() as! any Error
138138
if type(of: error) is AnyObject.Type {
139139
_rawValue = Unmanaged.passUnretained(error as AnyObject).toOpaque()
@@ -336,7 +336,7 @@ extension Backtrace {
336336
/// - Note: The underlying Foundation function is called (if present) the
337337
/// first time the value of this property is read.
338338
static let isFoundationCaptureEnabled = {
339-
#if SWT_TARGET_OS_APPLE && !SWT_NO_DYNAMIC_LINKING
339+
#if _runtime(_ObjC) && !SWT_NO_DYNAMIC_LINKING
340340
if Environment.flag(named: "SWT_FOUNDATION_ERROR_BACKTRACING_ENABLED") == true {
341341
let _CFErrorSetCallStackCaptureEnabled = symbol(named: "_CFErrorSetCallStackCaptureEnabled").map {
342342
unsafeBitCast($0, to: (@convention(c) (DarwinBoolean) -> DarwinBoolean).self)

Sources/_TestingInternals/include/WillThrow.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ typedef void (* SWT_SENDABLE SWTWillThrowTypedHandler)(void *error, const void *
7171
/// ``SWTWillThrowTypedHandler``
7272
SWT_EXTERN SWTWillThrowTypedHandler SWT_SENDABLE _Nullable swt_setWillThrowTypedHandler(SWTWillThrowTypedHandler SWT_SENDABLE _Nullable handler);
7373

74-
#if !defined(__APPLE__)
75-
/// The result of `swift__getErrorValue()`.
74+
#if defined(__swift__) && !defined(__OBJC__)
75+
/// The result of `swift_getErrorValue()`.
7676
///
7777
/// For more information, see this type's declaration
7878
/// [in the Swift repository](https://github.com/swiftlang/swift/blob/main/include/swift/Runtime/Error.h).

0 commit comments

Comments
 (0)