summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-23 08:35:44 +0100
committerTyge Løvset <[email protected]>2023-02-23 08:35:44 +0100
commit4ff4c8d352f76b658214029988eab7ce1d69efe8 (patch)
treeb4344007993fdb6460b7d4ecd3536a7f1e2b91b6
parent95f0b246cedc2d3669575ed2bfb398e6fbcb2b2f (diff)
downloadSTC-modified-4ff4c8d352f76b658214029988eab7ce1d69efe8.tar.gz
STC-modified-4ff4c8d352f76b658214029988eab7ce1d69efe8.zip
Internal updates.
-rw-r--r--include/stc/algo/cco.h34
-rw-r--r--include/stc/cbits.h11
-rw-r--r--misc/examples/bits.c2
-rwxr-xr-xmisc/examples/make.sh5
-rw-r--r--misc/examples/printspan.c10
5 files changed, 33 insertions, 29 deletions
diff --git a/include/stc/algo/cco.h b/include/stc/algo/cco.h
index fdb8ece3..c94382b1 100644
--- a/include/stc/algo/cco.h
+++ b/include/stc/algo/cco.h
@@ -99,38 +99,36 @@
* `c_' macros for re-entrant coroutines.
*/
typedef struct {
- int _ccoline;
+ int cco_line;
} *cco_handle;
-#define cco_context(cref, ...) \
+#define cco_context(handle, ...) \
struct ccoContext { \
- int _ccoline; \
+ int cco_line; \
__VA_ARGS__ \
- } **_ccoparam = (struct ccoContext **)cref
+ } **_ccoparam = (struct ccoContext **)handle + 0*sizeof((*(handle))->cco_line)
#define cco_routine(ctx, ...) \
- do { \
- if (!*_ccoparam) { \
- *_ccoparam = malloc(sizeof **_ccoparam); \
- (*_ccoparam)->_ccoline = 0; \
- } \
- struct ccoContext *ctx = *_ccoparam; \
- switch (ctx->_ccoline) { \
- case 0: __VA_ARGS__ break; \
- default: assert(!"cco_finish: missing"); \
- } \
- free(ctx), *_ccoparam = 0; \
- } while (0)
+ if (!*_ccoparam) { \
+ *_ccoparam = (struct ccoContext *)malloc(sizeof **_ccoparam); \
+ (*_ccoparam)->cco_line = 0; \
+ } \
+ struct ccoContext *ctx = *_ccoparam; \
+ switch (ctx->cco_line) { \
+ case 0: __VA_ARGS__ break; \
+ default: assert(!"cco_finish: missing"); \
+ } \
+ free(ctx), *_ccoparam = NULL
#define cco_yield(ret) \
do { \
- (*_ccoparam)->_ccoline = __LINE__; return ret; \
+ (*_ccoparam)->cco_line = __LINE__; return ret; \
case __LINE__:; \
} while (0)
#define cco_finish case -1
#define cco_stop(ctx) \
- ((*(ctx))->_ccoline = -1, (ctx))
+ ((*(ctx))->cco_line = -1, (ctx))
#endif /* COROUTINE_H */
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index e2d97f8c..fa0da665 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -61,8 +61,13 @@ int main() {
#define _cbits_words(n) (i_ssize)(((n) + 63)>>6)
#define _cbits_bytes(n) (_cbits_words(n) * c_sizeof(uint64_t))
-#if defined(__GNUC__) || defined(__clang__)
+#if defined(__GNUC__)
STC_INLINE int cpopcount64(uint64_t x) {return __builtin_popcountll(x);}
+ #ifndef __clang__
+ #pragma GCC diagnostic push
+ #pragma GCC diagnostic ignored "-Wstringop-overflow="
+ #pragma GCC diagnostic ignored "-Walloc-size-larger-than="
+ #endif
#elif defined(_MSC_VER) && defined(_WIN64)
#include <intrin.h>
STC_INLINE int cpopcount64(uint64_t x) {return (int)__popcnt64(x);}
@@ -303,7 +308,9 @@ STC_INLINE bool _i_memb(_disjoint)(const i_type* self, const i_type* other) {
_i_assert(self->_size == other->_size);
return _cbits_disjoint(self->data64, other->data64, _i_memb(_size)(self));
}
-
+#if defined __GNUC__ && !defined __clang__
+#pragma GCC diagnostic pop
+#endif
#define CBITS_H_INCLUDED
#undef _i_size
#undef _i_memb
diff --git a/misc/examples/bits.c b/misc/examples/bits.c
index 730dd953..6f28c52d 100644
--- a/misc/examples/bits.c
+++ b/misc/examples/bits.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <stc/cbits.h>
-int main()
+int main(void)
{
c_with (cbits set = cbits_with_size(23, true), cbits_drop(&set)) {
printf("count %" c_ZI ", %" c_ZI "\n", cbits_count(&set), cbits_size(&set));
diff --git a/misc/examples/make.sh b/misc/examples/make.sh
index 19a53880..5ac0b653 100755
--- a/misc/examples/make.sh
+++ b/misc/examples/make.sh
@@ -7,10 +7,9 @@ if [ "$(uname)" = 'Linux' ]; then
fi
cc=gcc; cflags="-s -O2 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings"
-#cc=gcc; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize"
+#cc=gcc; cflags="-g -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize"
#cc=tcc; cflags="-Wall -std=c99"
-#cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wsign-compare -Wwrite-strings"
-#cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -DSTC_CSTR_V1 -DSTC_CSMAP_V1"
+#cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wno-unused-function -Wsign-compare -Wwrite-strings"
#cc=gcc; cflags="-x c++ -s -O2 -Wall -std=c++20"
#cc=g++; cflags="-x c++ -s -O2 -Wall"
#cc=cl; cflags="-O2 -nologo -W3 -MD"
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index c7b0c609..81f6fa14 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -9,7 +9,7 @@
#define i_val int
#include <stc/cdeq.h>
#define i_val_str
-#include <stc/cset.h>
+#include <stc/csset.h>
#include <stc/cspan.h>
using_cspan(intspan, int, 1);
@@ -25,7 +25,7 @@ int main()
c_auto (cvec_int, vec)
c_auto (cstack_int, stk)
c_auto (cdeq_int, deq)
- c_auto (cset_str, set)
+ c_auto (csset_str, set)
{
intspan sp1 = cspan_make(intspan, {1, 2});
printMe( sp1 );
@@ -48,9 +48,9 @@ int main()
deq = c_make(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8});
printMe( (intspan)cspan_from(&deq) );
- set = c_make(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"});
- printf("%d:", (int)cset_str_size(&set));
- c_foreach (e, cset_str, set)
+ set = c_make(csset_str, {"5", "7", "4", "3", "8", "2", "1", "9", "6"});
+ printf("%d:", (int)csset_str_size(&set));
+ c_foreach (e, csset_str, set)
printf(" %s", cstr_str(e.ref));
puts("");
}