You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't use a class to store the current exit test. (#1065)
This PR replaces the private `_CurrentContainer` class used to store the
current exit test with a bare pointer. The class is prone to duplicate
definitions, but we really just use it as a glorified box type for the
move-only `ExitTest`, so an immortal pointer will work just as well.
Works around rdar://148837303.
### 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.
/// The exit test that is running in the current process, if any.
137
140
///
@@ -144,11 +147,13 @@ extension ExitTest {
144
147
/// process.
145
148
publicstaticvarcurrent:ExitTest?{
146
149
_read{
147
-
iflet current = _current.rawValue {
148
-
yield current.exitTest
149
-
}else{
150
-
yield nil
150
+
// NOTE: Even though this accessor is `_read` and has borrowing semantics,
151
+
// we must make a copy so that we don't yield lock-guarded memory to the
152
+
// caller (which is not concurrency-safe.)
153
+
letcurrentCopy= _current.withLock{ current in
154
+
return current.pointee?.unsafeCopy()
151
155
}
156
+
yield currentCopy
152
157
}
153
158
}
154
159
}
@@ -235,7 +240,8 @@ extension ExitTest {
235
240
236
241
// Set ExitTest.current before the test body runs.
237
242
Self._current.withLock{ current in
238
-
current =_CurrentContainer(exitTest:self)
243
+
precondition(current.pointee ==nil,"Set the current exit test twice in the same process. Please file a bug report at https://github.com/swiftlang/swift-testing/issues/new")
0 commit comments