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:
Saleem Abdulrasool
2020-06-21 18:06:51 -07:00
parent bbbe67e3a9
commit 364981f52c

View File

@@ -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)