Skip to content

Commit 63f1bdf

Browse files
committed
wip
1 parent 3735b1c commit 63f1bdf

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

Sources/IssueReporting/Internal/TestSupport.swift

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ func _recordIssue(
1919
#if os(WASI)
2020
let _recordIssue = _recordIssue()
2121
#else
22-
guard let pointer = pointer(for: "IssueReportingTestSupport_RecordIssue")
22+
guard let _recordIssue = function(for: "IssueReportingTestSupport_RecordIssue")
2323
else { return }
24-
let _recordIssue = withUnsafePointer(to: pointer) {
25-
UnsafeRawPointer($0).assumingMemoryBound(to: DynamicFunction.self).pointee()
26-
}
2724
#endif
2825
let recordIssue = _recordIssue as! (String?, String, String, Int, Int) -> Void
2926
recordIssue(message, fileID, filePath, line, column)
@@ -38,11 +35,8 @@ func _withKnownIssue(
3835
#if os(WASI)
3936
let _withKnownIssue = _withKnownIssue()
4037
#else
41-
guard let pointer = pointer(for: "IssueReportingTestSupport_WithKnownIssue")
38+
guard let _withKnownIssue = function(for: "IssueReportingTestSupport_WithKnownIssue")
4239
else { return }
43-
let _withKnownIssue = withUnsafePointer(to: pointer) {
44-
UnsafeRawPointer($0).assumingMemoryBound(to: DynamicFunction.self).pointee()
45-
}
4640
#endif
4741
let withKnownIssue = _withKnownIssue as! (String?, Bool, () throws -> Void) -> Void
4842
withKnownIssue(message, isIntermittent, body)
@@ -54,11 +48,8 @@ func _currentTestIsNotNil() -> Bool {
5448
#if os(WASI)
5549
let _currentTestIsNotNil = _currentTestIsNotNil()
5650
#else
57-
guard let pointer = pointer(for: "IssueReportingTestSupport_CurrentTestIsNotNil")
51+
guard let _currentTestIsNotNil = function(for: "IssueReportingTestSupport_CurrentTestIsNotNil")
5852
else { return false }
59-
let _currentTestIsNotNil = withUnsafePointer(to: pointer) {
60-
UnsafeRawPointer($0).assumingMemoryBound(to: DynamicFunction.self).pointee()
61-
}
6253
#endif
6354
let currentTestIsNotNil = _currentTestIsNotNil as! () -> Bool
6455
return currentTestIsNotNil()
@@ -69,11 +60,8 @@ func _XCTFail(_ message: String, file: StaticString, line: UInt) {
6960
#if os(WASI)
7061
let _XCTFail = _XCTFail()
7162
#else
72-
guard let pointer = pointer(for: "IssueReportingTestSupport_XCTFail")
63+
guard let _XCTFail = function(for: "IssueReportingTestSupport_XCTFail")
7364
else { return }
74-
let _XCTFail = withUnsafePointer(to: pointer) {
75-
UnsafeRawPointer($0).assumingMemoryBound(to: DynamicFunction.self).pointee()
76-
}
7765
#endif
7866
let XCTFail = _XCTFail as! (String, StaticString, UInt) -> Void
7967
XCTFail(message, file, line)
@@ -88,11 +76,8 @@ func _XCTExpectFailure(
8876
#if os(WASI)
8977
let _XCTExpectFailure = _XCTExpectFailure()
9078
#else
91-
guard let pointer = pointer(for: "IssueReportingTestSupport_XCTExpectFailure")
79+
guard let _XCTExpectFailure = function(for: "IssueReportingTestSupport_XCTExpectFailure")
9280
else { return }
93-
let _XCTExpectFailure = withUnsafePointer(to: pointer) {
94-
UnsafeRawPointer($0).assumingMemoryBound(to: DynamicFunction.self).pointee()
95-
}
9681
#endif
9782
let XCTExpectFailure = _XCTExpectFailure as! (String?, Bool?, () throws -> Void) throws -> Void
9883
try Result { try XCTExpectFailure(failureReason, strict, failingBlock) }._rethrowGet()
@@ -105,21 +90,21 @@ func _XCTExpectFailure(
10590
private typealias DynamicFunction = @convention(c) () -> Any
10691
#endif
10792

108-
private func pointer(for symbol: String) -> UnsafeMutableRawPointer? {
93+
private func function(for symbol: String) -> Any? {
10994
#if os(Linux)
11095
let symbol = symbolMap[symbol] ?? symbol
11196
guard
11297
let handle = dlopen("libIssueReportingTestSupport.so", RTLD_LAZY),
11398
let pointer = dlsym(handle, symbol)
11499
else { return nil }
115-
return pointer
100+
return unsafeBitCast(pointer, to: DynamicFunction.self)()
116101
#elseif os(Windows)
117102
let symbol = symbolMap[symbol]
118103
guard
119104
let handle = LoadLibraryA("IssueReportingTestSupport.dll"),
120105
let pointer = GetProcAddress(handle, symbol)
121106
else { return nil }
122-
return pointer
107+
return unsafeBitCast(pointer, to: DynamicFunction.self)()
123108
#else
124109
guard
125110
let prefix,
@@ -128,7 +113,7 @@ func _XCTExpectFailure(
128113
let handle = dlopen(path, RTLD_LAZY),
129114
let pointer = dlsym(handle, symbol)
130115
else { return nil }
131-
return pointer
116+
return unsafeBitCast(pointer, to: DynamicFunction.self)()
132117
#endif
133118
}
134119

0 commit comments

Comments
 (0)