You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `voidtake_ptr(const int * __counted_by(len) x __noescape, int len);` | `func take_ptr(_ x: Span<Int32>)` |
498
+
|`const int * __counted_by(len) change_ptr(const int * __counted_by(len) x __lifetimebound, int len);`|`@lifetime(x) func change_ptr(_ x: Span<Int32>) -> Span<Int32>`|
499
+
500
+
These overloads provide the same bounds safety as their `UnsafeBufferPointer` equvalents, but with
501
+
added lifetime safety. If lifetime information is available the generated safe overload will always
502
+
choose to use `Span` - no `UnsafeBufferPointer` overload will be generated in this case. This means
503
+
that existing callers are not affected by annotating an API with `__counted_by`, but callers using the
504
+
safe overload after adding `__counted_by`*will* be affected if `__noescape` is also added later on, or
505
+
if another parameter is then also annotated with `__counted_by`.
506
+
To prevent source breaking changes, make sure to fully annotate the bounds and lifetimes of an API when
507
+
adding any bounds or lifetime annotations.
508
+
509
+
#### Bounds Annotations using API Notes
510
+
511
+
In cases where you don't want to modify the imported headers, bounds attributes can be applied using API Notes.
512
+
Given the following header:
513
+
```c
514
+
voidfoo(int *p, int len);
515
+
void *bar(int size);
516
+
```
517
+
We can provide bounds annotations in our API note file like this:
518
+
```
519
+
Functions:
520
+
- Name: foo
521
+
Parameters:
522
+
- Position: 0
523
+
BoundsSafety:
524
+
Kind: counted_by
525
+
BoundedBy: "len"
526
+
- Name: bar
527
+
BoundsSafety:
528
+
Kind: sized_by
529
+
BoundedBy: "size"
530
+
```
531
+
532
+
#### Limitations
533
+
Bounds attributes are not supported for nested pointers: only the outermost pointer can be transformed.
534
+
535
+
`lifetime_capture_by` is currently not taken into account when generating safe overloads.
536
+
537
+
Bounds attributes on global variables or struct fields are ignored: only parameters and return values
538
+
are considered.
539
+
540
+
Bounds attributes, while supported in Objective-C code bases, are not currently supported in Objective-C
0 commit comments