Skip to content

Commit

Permalink
one more thing
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Jun 13, 2024
1 parent b2cc29c commit e8dfd3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions Sources/Perception/Internal/RuntimeWarning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func runtimeWarn(
#if canImport(os)
os_log(
.fault,
dso: dso.value,
dso: dso,
log: OSLog(subsystem: "com.apple.runtime-issues", category: category),
"%@",
message
Expand All @@ -28,7 +28,8 @@ func runtimeWarn(
#endif
}

#if DEBUG
#if !DEBUG
#else
import XCTestDynamicOverlay

#if canImport(os)
Expand All @@ -39,8 +40,15 @@ func runtimeWarn(
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
//
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
@usableFromInline
let dso = UncheckedSendable<UnsafeMutableRawPointer>({
#if swift(>=5.10)
@usableFromInline
nonisolated(unsafe) let dso = getSwiftUIDSO()
#else
@usableFromInline
let dso = getSwiftUIDSO()
#endif

private func getSwiftUIDSO() -> UnsafeMutableRawPointer {
let count = _dyld_image_count()
for i in 0..<count {
if let name = _dyld_get_image_name(i) {
Expand All @@ -53,7 +61,7 @@ func runtimeWarn(
}
}
return UnsafeMutableRawPointer(mutating: #dsohandle)
}())
}
#else
import Foundation

Expand Down
6 changes: 3 additions & 3 deletions Sources/Perception/Internal/UncheckedSendable.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@usableFromInline struct UncheckedSendable<Value>: @unchecked Sendable {
@usableFromInline let value: Value
@usableFromInline init(_ value: Value) {
struct UncheckedSendable<Value>: @unchecked Sendable {
let value: Value
init(_ value: Value) {
self.value = value
}
}

0 comments on commit e8dfd3e

Please sign in to comment.