mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SwiftPrivateThreadExtras: correct misuse of API
Copy out the result rather than form a dangling pointer. This fixes the incorrect usage that the compiler flags.
This commit is contained in:
@@ -117,17 +117,18 @@ public func _stdlib_thread_join<Result>(
|
||||
) -> (CInt, Result?) {
|
||||
#if os(Windows)
|
||||
let result = WaitForSingleObject(thread, INFINITE)
|
||||
if result == WAIT_OBJECT_0 {
|
||||
var threadResult: DWORD = 0
|
||||
GetExitCodeThread(thread, &threadResult)
|
||||
CloseHandle(thread)
|
||||
guard result == WAIT_OBJECT_0 else { return (CInt(result), nil) }
|
||||
|
||||
return (CInt(result),
|
||||
UnsafeMutablePointer<DWORD>(&threadResult)
|
||||
.withMemoryRebound(to: Result.self, capacity: 1){ $0.pointee })
|
||||
} else {
|
||||
return (CInt(result), nil)
|
||||
var dwResult: DWORD = 0
|
||||
GetExitCodeThread(thread, &dwResult)
|
||||
CloseHandle(thread)
|
||||
|
||||
let value: Result = withUnsafePointer(to: &dwResult) {
|
||||
$0.withMemoryRebound(to: Result.self, capacity: 1) {
|
||||
$0.pointee
|
||||
}
|
||||
}
|
||||
return (CInt(result), value)
|
||||
#else
|
||||
var threadResultRawPtr: UnsafeMutableRawPointer?
|
||||
let result = pthread_join(thread, &threadResultRawPtr)
|
||||
|
||||
Reference in New Issue
Block a user