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
- replace [[clang::noescape]] syntax with __noescape (etc)
- specify YAML syntax highlighting for YAML code blocks
- consistently use "annotation" in favour of "attribute"
- insert HTML table to enable code block in cells
@@ -313,7 +316,7 @@ Notably, the default constructor of a type is always assumed to create an indepe
313
316
314
317
We can also attach `lifetimebound` annotations to C and C++ APIs using [API Notes](https://clang.llvm.org/docs/APINotes.html). The `-1` index represents the `this` position.
315
318
316
-
```
319
+
```yaml
317
320
Tags:
318
321
- Name: MyClass
319
322
Methods:
@@ -335,7 +338,7 @@ annotation to describe the lifetime of other output values, like output/inout ar
|`void take_ptr_lifetime(const int * __counted_by(len) x __noescape, int len);`|`func take_ptr_lifetime(_ x: Span<Int32>)`|
502
-
|`const int * __counted_by(len) change_ptr_lifetime(const int * __counted_by(len) x __lifetimebound, int len);`|`@lifetime(x) func change_ptr_lifetime(_ x: Span<Int32>) -> Span<Int32>`|
503
-
|`void take_ptr(const int * __counted_by(len) x, int len);`|`func take_ptr(_ x: UnsafeBufferPointer<Int32>)`|
504
-
|`const int * __counted_by(len) change_ptr(const int * __counted_by(len) x, int len);`|`@lifetime(x) func change_ptr(_ x: UnsafeBufferPointer<Int32>) -> UnsafeBufferPointer<Int32>`|
515
+
<tr>
516
+
<td markdown=1>
517
+
```c
518
+
const int * __counted_by(len)
519
+
change_ptr_lifetime(
520
+
const int * __counted_by(len) x __lifetimebound,
521
+
int len);
522
+
```
523
+
</td>
524
+
<td markdown=1>
525
+
```swift
526
+
@lifetime(x)
527
+
func change_ptr_lifetime(_ x: Span<Int32>)
528
+
-> Span<Int32>
529
+
```
530
+
</td>
531
+
</tr>
532
+
533
+
<tr>
534
+
<td markdown=1>
535
+
```c
536
+
void
537
+
take_ptr(
538
+
const int * __counted_by(len) x,
539
+
int len);
540
+
```
541
+
</td>
542
+
<td markdown=1>
543
+
```swift
544
+
func take_ptr(_ x: UnsafeBufferPointer<Int32>)
545
+
```
546
+
</td>
547
+
</tr>
548
+
549
+
<tr>
550
+
<td markdown=1>
551
+
```c
552
+
const int * __counted_by(len)
553
+
change_ptr(
554
+
const int * __counted_by(len) x,
555
+
int len);
556
+
```
557
+
</td>
558
+
<td markdown=1>
559
+
```swift
560
+
@lifetime(x)
561
+
func change_ptr(_ x: UnsafeBufferPointer<Int32>)
562
+
-> UnsafeBufferPointer<Int32>
563
+
```
564
+
</td>
565
+
</tr>
566
+
567
+
</table>
505
568
506
569
The `UnsafeBufferPointer` overloads provide the same bounds safety as their `Span` equvalents
507
570
(NB: `UnsafeBufferPointer`is not bounds checked on memory access in release builds, but the generated
@@ -516,14 +579,14 @@ adding any bounds or lifetime annotations.
516
579
517
580
#### Bounds Annotations using API Notes
518
581
519
-
In cases where you don't want to modify the imported headers, bounds attributes can be applied using API Notes.
582
+
In cases where you don't want to modify the imported headers, bounds annotations can be applied using API Notes.
520
583
Given the following header:
521
584
```c
522
585
void foo(int *p, int len);
523
586
void *bar(int size);
524
587
```
525
588
We can provide bounds annotations in our API note file like this:
526
-
```
589
+
```yaml
527
590
Functions:
528
591
- Name: foo
529
592
Parameters:
@@ -538,12 +601,13 @@ Functions:
538
601
```
539
602
540
603
#### Limitations
541
-
Bounds attributes are not supported for nested pointers: only the outermost pointer can be transformed.
604
+
Bounds annotations are not supported for nested pointers: only the outermost pointer can be transformed.
542
605
543
-
`lifetime_capture_by` is currently not taken into account when generating safe overloads.
0 commit comments