41
41
42
42
#if SWIFT_HAS_VOUCHER_HEADER
43
43
44
- static inline bool swift_voucher_needs_adopt (voucher_t _Nullable voucher) {
45
- if (__builtin_available (macOS 12.0 , iOS 15.0 , tvOS 15.0 , watchOS 8.0 , *)) {
46
- return voucher_needs_adopt (voucher);
47
- }
48
- return true ;
49
- }
50
-
51
44
#else
52
45
53
46
// If the header isn't available, declare the necessary calls here.
@@ -64,10 +57,6 @@ extern "C" voucher_t _Nullable voucher_copy(void);
64
57
// Consumes argument, returns retained value.
65
58
extern " C" voucher_t _Nullable voucher_adopt (voucher_t _Nullable voucher);
66
59
67
- static inline bool swift_voucher_needs_adopt (voucher_t _Nullable voucher) {
68
- return true ;
69
- }
70
-
71
60
#endif // __has_include(<os/voucher_private.h>)
72
61
73
62
static inline void swift_voucher_release (voucher_t _Nullable voucher) {
@@ -88,10 +77,26 @@ static inline voucher_t _Nullable voucher_copy(void) { return nullptr; }
88
77
static inline voucher_t _Nullable voucher_adopt (voucher_t _Nullable voucher) {
89
78
return nullptr ;
90
79
}
91
- static inline bool swift_voucher_needs_adopt (voucher_t _Nullable voucher) {
92
- return true ;
93
- }
94
80
static inline void swift_voucher_release (voucher_t _Nullable voucher) {}
95
81
#endif // __APPLE__
96
82
83
+ // Declare our own voucher_needs_adopt for when we don't get it from the SDK.
84
+ // This declaration deliberately takes `void *` instead of `voucher_t`. When the
85
+ // SDK provides one that takes `voucher_t`, then C++ overload resolution will
86
+ // favor that one. When the SDK does not provide a declaration, then the call
87
+ // site will invoke this stub instead.
88
+ static inline bool voucher_needs_adopt (void * _Nullable voucher) {
89
+ return true ;
90
+ }
91
+
92
+ static inline bool swift_voucher_needs_adopt (voucher_t _Nullable voucher) {
93
+ #if __APPLE__
94
+ if (__builtin_available (macOS 12.0 , iOS 15.0 , tvOS 15.0 , watchOS 8.0 , *))
95
+ return voucher_needs_adopt (voucher);
96
+ return true ;
97
+ #else
98
+ return voucher_needs_adopt (voucher);
97
99
#endif
100
+ }
101
+
102
+ #endif // SWIFT_CONCURRENCY_VOUCHERSHIMS_H
0 commit comments