Skip to content

Commit 5f25c18

Browse files
committed
runtime: add comments/docs explaining the semantics of IA2_{CON,DE}STRUCTOR
1 parent 46d47bd commit 5f25c18

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

runtime/libia2/include/ia2.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,23 @@
4747
#define IA2_POST_CONDITION_FOR(target_func) __attribute__((annotate("ia2_post_condition:" #target_func)))
4848

4949
/// Mark the annotated function as a constructor for the type `T`,
50-
/// where the function has the signature `R f(T*, ...)`.
50+
/// where the function has the signature `R f(T* this, ...)`.
5151
/// The `...` aren't varargs here; it just means that
5252
/// there can be any number of extra args after the `T*`.
5353
///
54+
/// This function should initialize the `T*`
55+
/// and marks the start of its lifetime as a
56+
/// registered and valid ptr of type `T`.
57+
///
5458
/// Note that this is not the same as `__attribute__((constructor))`.
5559
#define IA2_CONSTRUCTOR __attribute__((annotate("ia2_constructor")))
5660

5761
/// Mark the annotated function as a destructor for the type `T`,
58-
/// where the function has the signature `void f(T*)`.
62+
/// where the function has the signature `void f(T* this)`.
63+
///
64+
/// This function should unitialize the `T*`
65+
/// and marks the end of its lifetime as a
66+
/// registered and valid ptr of type `T`.
5967
///
6068
/// Note that this is not the same as `__attribute__((destructor))`.
6169
#define IA2_DESTRUCTOR __attribute__((annotate("ia2_destructor")))

tests/type_confusion/dav1d.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ RUN: cat dav1d_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s
88
#define IA2_COMPARTMENT 2
99
#include <ia2_compartment_init.inc>
1010

11-
IA2_CONSTRUCTOR
11+
IA2_CONSTRUCTOR // Registers that ptr `this` has type `Dav1dContext` now.
1212
int dav1d_open(Dav1dContext *const this, const Dav1dSettings *const s) {
1313
// Initialize `this`; implementation omitted.
1414
return 0;
1515
}
1616

17-
IA2_DESTRUCTOR
17+
IA2_DESTRUCTOR // Registers that ptr `this` no longer has type `Dav1dContext`.
1818
void dav1d_close(Dav1dContext *const this) {
1919
// Uninitialize `this`; implementation omitted.
2020
}

0 commit comments

Comments
 (0)