summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2023-01-04 22:55:08 +0100
committerTyge Lovset <[email protected]>2023-01-04 22:55:08 +0100
commitf89ba241b30a9335a8354c435c377cfcf9841de2 (patch)
tree233b72f88793dbd4fcb93ff3965b83986ea01eef
parent3812789b283f59d2cc4ca0bd32c4edbd7742ef99 (diff)
downloadSTC-modified-f89ba241b30a9335a8354c435c377cfcf9841de2.tar.gz
STC-modified-f89ba241b30a9335a8354c435c377cfcf9841de2.zip
Removed the experimental c_AUTODROP macro.
-rw-r--r--README.md2
-rw-r--r--docs/carray_api.md2
-rw-r--r--docs/ccommon_api.md5
-rw-r--r--include/stc/ccommon.h6
-rw-r--r--include/stc/priv/lowcase.h3
-rw-r--r--misc/examples/astar.c4
-rw-r--r--misc/examples/forfilter.c3
-rw-r--r--src/checkauto.l2
8 files changed, 12 insertions, 15 deletions
diff --git a/README.md b/README.md
index 475db445..1e9bfbea 100644
--- a/README.md
+++ b/README.md
@@ -394,7 +394,7 @@ and non-emplace methods:
#include <stc/cvec.h> // vector of string (cstr)
...
c_AUTO (cvec_str, vec) // declare and call cvec_str_init() and defer cvec_str_drop(&vec)
-c_AUTODROP (cstr, s, cstr_lit("a string literal")) // like c_AUTO without auto default init.
+c_WITH (cstr s = cstr_lit("a string literal"), cstr_drop(&s))
{
const char* hello = "Hello";
cvec_str_push_back(&vec, cstr_from(hello); // construct and add string from const char*
diff --git a/docs/carray_api.md b/docs/carray_api.md
index cd4e0e45..803a1610 100644
--- a/docs/carray_api.md
+++ b/docs/carray_api.md
@@ -90,7 +90,7 @@ int main()
// Ex1
int xd = 30, yd = 20, zd = 10;
// define arr3[30][20][10], initialized with zeros.
- c_AUTODROP (carr3_f, arr3, carr3_f_with_size(xd, yd, zd, 0.0f)) {
+ c_WITH (carr3_f arr3 = carr3_f_with_size(xd, yd, zd, 0.0f), carr3_f_drop(&arr3)) {
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 d5ecc430..bb9efac4 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -3,7 +3,7 @@
The following macros are recommended to use, and they safe/have no side-effects.
## Scope macros (RAII)
-### c_AUTO, c_AUTODROP, c_WITH, c_SCOPE, c_DEFER
+### c_AUTO, 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.
@@ -13,7 +13,6 @@ The **checkauto** utility described below, ensures that the `c_AUTO*` macros are
| `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_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 block above without memory leaks |
@@ -50,7 +49,7 @@ c_AUTO (cstr, s1, s2)
printf("%s %s\n", cstr_str(&s1), cstr_str(&s2));
}
-c_AUTODROP (cstr, str, cstr_lit("Hello"))
+c_WITH (cstr str = cstr_lit("Hello"), cstr_drop(&str))
{
cstr_append(&str, " world");
printf("%s\n", cstr_str(&str));
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 191709fb..90abb186 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -122,8 +122,6 @@ typedef const char* crawstr;
#define c_SV2(str, n) (c_INIT(csview){str, n})
#define c_ARGSV(sv) (int)(sv).size, (sv).str /* use with "%.*s" */
#define c_PAIR(ref) (ref)->first, (ref)->second
-#define c_sv c_SV /* [deprecated] */
-#define c_ARGsv(sv) c_ARGSV(sv) /* [deprecated] */
#define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k)))
@@ -203,7 +201,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
#define c_WITH3(declvar, pred, drop) for (declvar, **_c_i = NULL; !_c_i && (pred); ++_c_i, drop)
#define c_SCOPE(init, drop) for (int _c_i = (init, 0); !_c_i; ++_c_i, drop)
#define c_DEFER(...) for (int _c_i = 0; !_c_i; ++_c_i, __VA_ARGS__)
-#define c_AUTODROP(C, a, ...) for (C a = __VA_ARGS__, **_c_i = NULL; !_c_i; ++_c_i, C##_drop(&a))
+#define c_DROP(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)
#define c_AUTO(...) c_MACRO_OVERLOAD(c_AUTO, __VA_ARGS__)
#define c_AUTO2(C, a) \
@@ -218,8 +216,6 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle,
c_WITH2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \
(C##_drop(&d), C##_drop(&c), C##_drop(&b), C##_drop(&a)))
-#define c_DROP(C, ...) do { c_FORLIST (_i, C*, {__VA_ARGS__}) C##_drop(*_i.ref); } while(0)
-
#define c_FIND_IF(...) c_MACRO_OVERLOAD(c_FIND_IF, __VA_ARGS__)
#define c_FIND_IF4(it, C, cnt, pred) do { \
size_t index = 0; \
diff --git a/include/stc/priv/lowcase.h b/include/stc/priv/lowcase.h
index 94de4578..8b37fa23 100644
--- a/include/stc/priv/lowcase.h
+++ b/include/stc/priv/lowcase.h
@@ -42,11 +42,12 @@
#define c_fortoken c_FORTOKEN
#define c_fortoken_sv c_FORTOKEN_SV
#define c_auto c_AUTO
-#define c_autodrop c_AUTODROP
#define c_with c_WITH
#define c_scope c_SCOPE
#define c_defer c_DEFER
#define c_drop c_DROP
+#define c_sv c_SV
+#define c_ARGsv c_ARGSV
#define c_find_if c_FIND_IF
#define c_erase_if c_ERASE_IF
#define c_flt_take c_FLT_TAKE
diff --git a/misc/examples/astar.c b/misc/examples/astar.c
index e308eb78..828de8ce 100644
--- a/misc/examples/astar.c
+++ b/misc/examples/astar.c
@@ -159,7 +159,9 @@ main(void)
int width = cstr_find(&maze, "\n") + 1;
c_WITH (cdeq_point path = astar(&maze, width), cdeq_point_drop(&path))
{
- c_FOREACH (it, cdeq_point, path) cstr_data(&maze)[point_index(it.ref)] = 'x';
+ c_FOREACH (it, cdeq_point, path)
+ cstr_data(&maze)[point_index(it.ref)] = 'x';
+
printf("%s", cstr_str(&maze));
}
}
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index c0a4ccad..280fdc9c 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -22,7 +22,8 @@
void demo1(void)
{
c_AUTO (IVec, vec) {
- c_FORLIST (i, int, {0, 1, 2, 3, 4, 5, 80, 6, 7, 80, 8, 9, 80, 10, 11, 12, 13, 14, 15, 80, 16, 17})
+ c_FORLIST (i, int, {0, 1, 2, 3, 4, 5, 80, 6, 7, 80, 8, 9, 80,
+ 10, 11, 12, 13, 14, 15, 80, 16, 17})
IVec_push(&vec, *i.ref);
puts("demo1:");
diff --git a/src/checkauto.l b/src/checkauto.l
index e4c796d0..4af35c49 100644
--- a/src/checkauto.l
+++ b/src/checkauto.l
@@ -52,12 +52,10 @@ do { block_type |= LOOP; state = BRACESDONE; }
c_with |
c_scope |
c_defer |
-c_autodrop |
c_auto |
c_WITH |
c_SCOPE |
c_DEFER |
-c_AUTODROP |
c_AUTO { block_type = AUTO; state = BRACES; }
\( { if (state == BRACES) ++braces_lev; }
\) { if (state == BRACES && --braces_lev == 0) {