|
45 | 45 | #define _CXX_INTEROP_CONCAT(...) \
|
46 | 46 | _CXX_INTEROP_CONCAT_(__VA_ARGS__,,,,,,,,,,,,,,,,,)
|
47 | 47 |
|
48 |
| -/// Specifies that a C++ `class` or `struct` is reference-counted using |
| 48 | +/// Specifies that a C `class` or `struct` is reference-counted using |
49 | 49 | /// the given `retain` and `release` functions. This annotation lets Swift import
|
50 | 50 | /// such a type as reference counted type in Swift, taking advantage of Swift's
|
51 | 51 | /// automatic reference counting.
|
|
76 | 76 | __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:_retain)))) \
|
77 | 77 | __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:_release))))
|
78 | 78 |
|
79 |
| -/// Specifies that a C++ `class` or `struct` is a reference type whose lifetime |
| 79 | +/// Specifies that a `class` or `struct` is a reference type whose lifetime |
80 | 80 | /// is presumed to be immortal, i.e. the reference to such object is presumed to
|
81 | 81 | /// always be valid. This annotation lets Swift import such a type as a reference
|
82 | 82 | /// type in Swift.
|
|
160 | 160 | #define SWIFT_UNCHECKED_SENDABLE \
|
161 | 161 | __attribute__((swift_attr("@Sendable")))
|
162 | 162 |
|
163 |
| -/// Specifies that a specific c++ type such class or struct should be imported |
164 |
| -/// as a non-copyable Swift value type. |
| 163 | +/// Specifies that a class or struct should be imported as a non-copyable |
| 164 | +/// Swift value type. |
165 | 165 | #define SWIFT_NONCOPYABLE \
|
166 | 166 | __attribute__((swift_attr("~Copyable")))
|
167 | 167 |
|
| 168 | +/// Specifies that a class or struct should be imported as a non-copyable |
| 169 | +/// Swift value type that calls the given _destroy function when a value is no |
| 170 | +/// longer used. |
| 171 | +/// |
| 172 | +/// This example shows how to use this macro to let Swift know that |
| 173 | +/// a given C struct should have its members freed when it goes out of scope: |
| 174 | +/// ```c |
| 175 | +/// typedef struct SWIFT_NONCOPYABLE_WITH_DESTROY(mytypeFreeMembers) MyType { |
| 176 | +/// void *storage |
| 177 | +/// } MyType; |
| 178 | +/// |
| 179 | +/// void mytypeFreeMembers(MyType toBeDestroyed); |
| 180 | +/// MyType mytypeCreate(void); |
| 181 | +/// ``` |
| 182 | +/// |
| 183 | +/// Usage in Swift: |
| 184 | +/// ```swift |
| 185 | +/// let mt = mytypeCreate() |
| 186 | +/// let mt2 = mt // consumes mt |
| 187 | +/// // once mt2 is unused, Swift will call mytypeFreeMembers(mt2) |
| 188 | +#define SWIFT_NONCOPYABLE_WITH_DESTROY(_destroy) \ |
| 189 | + __attribute__((swift_attr("~Copyable"))) \ |
| 190 | + __attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(destroy:_destroy)))) |
| 191 | + |
168 | 192 | /// Specifies that a specific c++ type such class or struct should be imported
|
169 | 193 | /// as a non-escapable Swift value type when the non-escapable language feature
|
170 | 194 | /// is enabled.
|
|
258 | 282 | #define SWIFT_MUTATING
|
259 | 283 | #define SWIFT_UNCHECKED_SENDABLE
|
260 | 284 | #define SWIFT_NONCOPYABLE
|
| 285 | +#define SWIDT_NONCOPYABLE_WITH_DESTROY(_destroy) |
261 | 286 | #define SWIFT_NONESCAPABLE
|
262 | 287 | #define SWIFT_ESCAPABLE
|
263 | 288 | #define SWIFT_ESCAPABLE_IF(...)
|
|
0 commit comments