Skip to content

Commit 8ae66ec

Browse files
authored
Merge pull request swiftlang#76888 from ktoso/wip-improve-execute-buffer-init-tracking
2 parents 7664582 + d41c9c2 commit 8ae66ec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,20 @@ extension DistributedActorSystem {
555555
errorCode: .typeDeserializationFailure)
556556
}
557557

558-
var executeDistributedTargetHasThrown = false
558+
// we start out assuming we may have thrown,
559+
// and set this to false when we return without having thrown
560+
var executeDistributedTargetHasThrown = true
561+
559562
func doDestroyReturnTypeBuffer<R>(_: R.Type) {
560563
let buf = resultBuffer.assumingMemoryBound(to: R.self)
564+
561565
if !executeDistributedTargetHasThrown {
566+
// since the _execute function has NOT thrown,
567+
// there must be a value in the result buffer that we must deinitialize
562568
buf.deinitialize(count: 1)
563-
}
569+
} // otherwise, the _execute has thrown and not populated the result buffer
570+
571+
// finally, deallocate the buffer
564572
buf.deallocate()
565573
}
566574

@@ -584,6 +592,9 @@ extension DistributedActorSystem {
584592
witnessTables: witnessTablesBuffer,
585593
numWitnessTables: UInt(numWitnessTables)
586594
)
595+
// execute has not thrown, so the result buffer has been filled with some value,
596+
// we must properly deinitialize it.
597+
executeDistributedTargetHasThrown = false
587598

588599
if returnType == Void.self {
589600
try await handler.onReturnVoid()
@@ -595,7 +606,6 @@ extension DistributedActorSystem {
595606
)
596607
}
597608
} catch {
598-
executeDistributedTargetHasThrown = true
599609
try await handler.onThrow(error: error)
600610
}
601611
}

0 commit comments

Comments
 (0)