summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-28 18:36:37 +0100
committerTyge Løvset <[email protected]>2021-12-28 18:36:37 +0100
commit390e99e911c46ad59ecb966bffb275c9cba92fe1 (patch)
tree6a44f3911fcfe8757409a01613162504d0fb04a3
parentdbeb998018ce3a739500f9a29e9b62639de2c49f (diff)
downloadSTC-modified-390e99e911c46ad59ecb966bffb275c9cba92fe1.tar.gz
STC-modified-390e99e911c46ad59ecb966bffb275c9cba92fe1.zip
Some renaming of new features in previous commit.
-rw-r--r--build_autocheck.sh5
-rw-r--r--buildcheck.sh5
-rw-r--r--checkauto.ll (renamed from autocheck.ll)12
-rw-r--r--docs/ccommon_api.md16
-rw-r--r--include/stc/ccommon.h1
5 files changed, 20 insertions, 19 deletions
diff --git a/build_autocheck.sh b/build_autocheck.sh
deleted file mode 100644
index 96ec7d4d..00000000
--- a/build_autocheck.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-if [ "$OS" = "Windows_NT" ]; then EXE=.exe; fi
-flex autocheck.ll
-gcc -O2 lex.yy.c -o autocheck$EXE
-rm lex.yy.c
-strip autocheck$EXE
diff --git a/buildcheck.sh b/buildcheck.sh
new file mode 100644
index 00000000..5a1b2e93
--- /dev/null
+++ b/buildcheck.sh
@@ -0,0 +1,5 @@
+if [ "$OS" = "Windows_NT" ]; then EXE=.exe; fi
+flex checkauto.ll
+gcc -O2 lex.yy.c -o checkauto$EXE
+rm lex.yy.c
+strip checkauto$EXE
diff --git a/autocheck.ll b/checkauto.ll
index 9b090b1c..a2822d9b 100644
--- a/autocheck.ll
+++ b/checkauto.ll
@@ -56,23 +56,23 @@ c_auto { block_type = AUTO; state = BRACES; }
\} { if (state != BRACES) block_type = block[--block_lev]; }
return { if (block_type == AUTO) {
printf("%s:%d: error: 'return' used inside a c_auto* scope.\n"
- " Use 'c_exitauto' to exit the current c_auto* scope.\n", fname, yylineno);
+ " Use 'c_breakauto' to exit the current c_auto* scope.\n", fname, yylineno);
} else if (block_type & AUTO) {
printf("%s:%d: error: 'return' used in a loop inside a c_auto* scope.\n"
- " Use 'break' to exit loops, then 'c_exitauto' to exit c_auto*.\n", fname, yylineno);
+ " Use 'break' to exit loops, then 'c_breakauto' to exit c_auto*.\n", fname, yylineno);
}
}
break { if (block_type == AUTO)
printf("%s:%d: error: 'break' used inside a c_auto* scope.\n"
- " Use 'c_exitauto' to exit the current c_auto* scope.\n", fname, yylineno);
+ " Use 'c_breakauto' to exit the current c_auto* scope.\n", fname, yylineno);
}
continue { if (block_type == AUTO)
printf("%s:%d: warning: 'continue' used inside a c_auto* scope.\n"
" It will only break out of the current c_auto* scope.\n"
- " Use 'c_exitauto' instead to make it explicit.\n", fname, yylineno);
+ " Use 'c_breakauto' instead to make it explicit.\n", fname, yylineno);
}
-c_exitauto { if (block_type != AUTO)
- printf("%s:%d: warning: 'c_exitauto' used outside a c_auto* scope.\n"
+c_breakauto { if (block_type != AUTO)
+ printf("%s:%d: warning: 'c_breakauto' used outside a c_auto* scope.\n"
" Did you mean 'continue' instead?", fname, yylineno);
}
{ID} ;
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 9c872519..bd7029c4 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -6,18 +6,18 @@ The following handy macros are safe to use, i.e. have no side-effects.
General ***defer*** mechanics for resource acquisition. These macros allows to specify the release of the
resource where the resource acquisition takes place. Makes it easier to verify that resources are released.
-**NB**: These macros are one-time executed **for-loops**. Use ***only*** `c_exitauto` in order to break out
+**NB**: These macros are one-time executed **for-loops**. Use ***only*** `c_breakauto` in order to break out
of these `c_auto*`-blocks! ***Do not*** use `return` or `goto` (or `break`) inside them, as they will
prevent the `end`-statement to be executed when leaving scope. This is not particular to the `c_auto*()`
macros, as one must always make sure to unwind temporary allocated resources before a `return` in C.
-| Usage | Description |
-|:---------------------------------------|:---------------------------------------------------|
-| `c_auto (Type, var...)` | `c_autovar (Type var=Type_init(), Type_drop(&var))` |
-| `c_autovar (Type var=init, end...)` | Declare `var`. Defer `end...` to end of block |
-| `c_autoscope (init, end...)` | Execute `init`. Defer `end...` to end of block |
-| `c_autodefer (end...)` | Defer `end...` to end of block |
-| `c_exitauto;` | Break safely out of a `c_auto*`-block/scope |
+| Usage | Description |
+|:---------------------------------------|:-----------------------------------------------------|
+| `c_auto (Type, var...)` | `c_autovar (Type var=Type_init(), Type_drop(&var))` |
+| `c_autovar (Type var=init, end...)` | Declare `var`. Defer `end...` to end of block |
+| `c_autoscope (init, end...)` | Execute `init`. Defer `end...` to end of block |
+| `c_autodefer (end...)` | Defer `end...` to end of block |
+| `c_breakauto;` | Break out of a `c_auto*`-block/scope without memleak |
For multiple variables, use either multiple **c_autovar** in sequence, or declare variable outside
scope and use **c_autoscope**. Also, **c_auto** support up to 3 variables.
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 8ae0dfae..b2ae7b97 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -169,6 +169,7 @@ STC_INLINE uint64_t c_default_hash(const void* key, size_t len) {
#define c_autovar(declvar, ...) for (declvar, *_c_ii = NULL; !_c_ii; ++_c_ii, __VA_ARGS__)
#define c_autoscope(init, ...) for (int _c_ii = (init, 0); !_c_ii; ++_c_ii, __VA_ARGS__)
#define c_autodefer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__)
+#define c_breakauto continue
#define c_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__)
#define c_auto_2(C, a) \