Skip to content

Commit 67d148b

Browse files
committed
runtime: add comments/docs explaining the semantics of IA2_{CON,DE}STRUCTOR
1 parent fc8fb4b commit 67d148b

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
@@ -43,15 +43,23 @@
4343
#define IA2_POST_CONDITION_FOR(target_func) __attribute__((annotate("ia2_post_condition:" #target_func)))
4444

4545
/// Mark the annotated function as a constructor for the type `T`,
46-
/// where the function has the signature `R f(T*, ...)`.
46+
/// where the function has the signature `R f(T* this, ...)`.
4747
/// The `...` aren't varargs here; it just means that
4848
/// there can be any number of extra args after the `T*`.
4949
///
50+
/// This function should initialize the `T*`
51+
/// and marks the start of its lifetime as a
52+
/// registered and valid ptr of type `T`.
53+
///
5054
/// Note that this is not the same as `__attribute__((constructor))`.
5155
#define IA2_CONSTRUCTOR __attribute__((annotate("ia2_constructor")))
5256

5357
/// Mark the annotated function as a destructor for the type `T`,
54-
/// where the function has the signature `void f(T*)`.
58+
/// where the function has the signature `void f(T* this)`.
59+
///
60+
/// This function should unitialize the `T*`
61+
/// and marks the end of its lifetime as a
62+
/// registered and valid ptr of type `T`.
5563
///
5664
/// Note that this is not the same as `__attribute__((destructor))`.
5765
#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)