summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/carray_api.md3
-rw-r--r--docs/ccommon_api.md15
2 files changed, 12 insertions, 6 deletions
diff --git a/docs/carray_api.md b/docs/carray_api.md
index e12cbc4f..fb2c6a89 100644
--- a/docs/carray_api.md
+++ b/docs/carray_api.md
@@ -90,8 +90,7 @@ int main()
// Ex1
int xd = 30, yd = 20, zd = 10;
// define arr3[30][20][10], initialized with zeros.
- c_with (carr3_f arr3 = carr3_f_with_size(xd, yd, zd, 0.0f),
- carr3_f_drop(&arr3)) {
+ c_autodrop (carr3_f, arr3, carr3_f_with_size(xd, yd, zd, 0.0f)) {
arr3.data[5][4][3] = 3.14f;
float *arr1 = arr3.data[5][4];
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 7721a38d..8a11042b 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -3,19 +3,20 @@
The following macros are recommended to use, and they safe/have no side-effects.
## Scope macros (RAII)
-### c_auto, c_with, c_scope, c_defer
+### c_auto, c_autodrop, c_with, c_scope, c_defer
General ***defer*** mechanics for resource acquisition. These macros allows you to specify the
freeing of the resources at the point where the acquisition takes place.
The **checkauto** utility described below, ensures that the `c_auto*` macros are used correctly.
| Usage | Description |
|:---------------------------------------|:----------------------------------------------------------|
-| `c_auto (Type, var...)` | Same as `c_with (Type var=Type_init(), Type_drop(&var))` |
| `c_with (Type var=init, drop)` | Declare `var`. Defer `drop...` to end of scope |
| `c_with (Type var=init, pred, drop)` | Adds a predicate in order to exit early if init failed |
-| `c_scope (init, drop...)` | Execute `init` and defer `drop...` to end of scope |
+| `c_auto (Type, var1,...,var4)` | `c_with (Type var1=Type_init(), Type_drop(&var1))` ... |
+| `c_autodrop (Type, var, init...)` | Like `c_with (Type var=init..., Type_drop(&var))` |
+| `c_scope (init, drop)` | Execute `init` and defer `drop` to end of scope |
| `c_defer (drop...)` | Defer `drop...` to end of scope |
-| `continue` | Exit a `c_auto/c_with/c_scope...` without memory leaks |
+| `continue` | Exit a block above without memory leaks |
For multiple variables, use either multiple **c_with** in sequence, or declare variable outside
scope and use **c_scope**. For convenience, **c_auto** support up to 4 variables.
@@ -49,6 +50,12 @@ c_auto (cstr, s1, s2)
printf("%s %s\n", cstr_str(&s1), cstr_str(&s2));
}
+c_autodrop (cstr, str, cstr_new("Hello"))
+{
+ cstr_append(&str, " world");
+ printf("%s\n", cstr_str(&str));
+}
+
// `c_scope` is like `c_with` but works with an already declared variable.
static pthread_mutex_t mut;
c_scope (pthread_mutex_lock(&mut), pthread_mutex_unlock(&mut))