Skip to content

Commit 141634a

Browse files
committed
Fix withCancellationHandler on arm64e
1 parent 6e2338c commit 141634a

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,9 @@ swift_task_addCancellationHandlerImpl(
838838
void *context) {
839839
void *allocation =
840840
swift_task_alloc(sizeof(CancellationNotificationStatusRecord));
841-
auto *record =
842-
new (allocation) CancellationNotificationStatusRecord(
843-
handler, context);
841+
auto unsigned_handler = swift_auth_code(handler, 3848);
842+
auto *record = new (allocation)
843+
CancellationNotificationStatusRecord(unsigned_handler, context);
844844

845845
swift_task_addStatusRecord(record);
846846
return record;

test/Concurrency/Runtime/cancellation_handler.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
// rdar://76038845
66
// UNSUPPORTED: use_os_stdlib
77

8+
// for sleep
9+
#if canImport(Darwin)
10+
import Darwin
11+
#elseif canImport(Glibc)
12+
import Glibc
13+
#endif
14+
815
class Canary {
916
deinit {
1017
print("canary died")
@@ -21,10 +28,22 @@ if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
2128
}
2229
}
2330
task.cancel()
31+
sleep(1)
32+
detach {
33+
await Task.withCancellationHandler {
34+
print("Task was cancelled!")
35+
}
36+
operation: {
37+
print("Running the operation...")
38+
}
39+
}
40+
sleep(10)
2441
} else {
2542
// Fake prints to satisfy FileCheck.
2643
print("Canary")
2744
print("canary died")
45+
print("Running the operation...")
2846
}
2947
// CHECK: Canary
3048
// CHECK-NEXT: canary died
49+
// CHECK-NEXT: Running the operation...

0 commit comments

Comments
 (0)