diff options
| author | Tyge Løvset <[email protected]> | 2022-12-31 09:41:24 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-12-31 09:41:24 +0100 |
| commit | 91e79fc60713c1f09e940a7ee83ff2f8aa4f9d69 (patch) | |
| tree | b2f1eb8fef010ec490efcf0fb420b218ad23a4dd /include/stc | |
| parent | 89de800ff2e0a8389359a8a7a2684edaae8ce742 (diff) | |
| download | STC-modified-91e79fc60713c1f09e940a7ee83ff2f8aa4f9d69.tar.gz STC-modified-91e79fc60713c1f09e940a7ee83ff2f8aa4f9d69.zip | |
Internally renamed ccommon.h macros to uppercase. Lowercase macros are still supported via include/stc/priv/lowcase.h.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/algo/filter.h | 24 | ||||
| -rw-r--r-- | include/stc/carc.h | 10 | ||||
| -rw-r--r-- | include/stc/cbits.h | 16 | ||||
| -rw-r--r-- | include/stc/cbox.h | 10 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 104 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 8 | ||||
| -rw-r--r-- | include/stc/clist.h | 16 | ||||
| -rw-r--r-- | include/stc/cmap.h | 26 | ||||
| -rw-r--r-- | include/stc/cpque.h | 4 | ||||
| -rw-r--r-- | include/stc/cqueue.h | 2 | ||||
| -rw-r--r-- | include/stc/cregex.h | 2 | ||||
| -rw-r--r-- | include/stc/cset.h | 2 | ||||
| -rw-r--r-- | include/stc/csmap.h | 10 | ||||
| -rw-r--r-- | include/stc/csset.h | 2 | ||||
| -rw-r--r-- | include/stc/cstack.h | 10 | ||||
| -rw-r--r-- | include/stc/cstr.h | 12 | ||||
| -rw-r--r-- | include/stc/csview.h | 6 | ||||
| -rw-r--r-- | include/stc/cvec.h | 6 | ||||
| -rw-r--r-- | include/stc/priv/lowcase.h (renamed from include/stc/priv/allcaps.h) | 67 |
19 files changed, 168 insertions, 169 deletions
diff --git a/include/stc/algo/filter.h b/include/stc/algo/filter.h index 10aeb7e7..74db5e04 100644 --- a/include/stc/algo/filter.h +++ b/include/stc/algo/filter.h @@ -37,9 +37,9 @@ int main() puts(""); c_FORFILTER (i, cstack_int, stk - , c_flt_skipwhile(i, *i.ref < 3) + , c_FLT_SKIPWHILE(i, *i.ref < 3) && (*i.ref & 1) == 0 // even only - , c_flt_take(i, 2)) // break after 2 + , c_FLT_TAKE(i, 2)) // break after 2 printf(" %d", *i.ref); puts(""); } @@ -54,20 +54,20 @@ int main() #define c_NFILTERS 14 /* 22, 30, .. */ #endif -#define c_flt_take(i, n) (++(i).s1[(i).s1top++] <= (n)) -#define c_flt_skip(i, n) (++(i).s1[(i).s1top++] > (n)) -#define c_flt_skipwhile(i, pred) ((i).s2[(i).s2top++] |= !(pred)) -#define c_flt_takewhile(i, pred) !c_flt_skipwhile(i, pred) +#define c_FLT_TAKE(i, n) (++(i).s1[(i).s1top++] <= (n)) +#define c_FLT_SKIP(i, n) (++(i).s1[(i).s1top++] > (n)) +#define c_FLT_SKIPWHILE(i, pred) ((i).s2[(i).s2top++] |= !(pred)) +#define c_FLT_TAKEWHILE(i, pred) !c_FLT_SKIPWHILE(i, pred) -#define c_forfilter(...) c_MACRO_OVERLOAD(c_forfilter, __VA_ARGS__) +#define c_FORFILTER(...) c_MACRO_OVERLOAD(c_FORFILTER, __VA_ARGS__) -#define c_forfilter4(i, C, cnt, filter) \ - c_forfilter_b(i, C, C##_begin(&cnt), filter) +#define c_FORFILTER4(i, C, cnt, filter) \ + c_FORFILTER_B(i, C, C##_begin(&cnt), filter) -#define c_forfilter5(i, C, cnt, filter, cond) \ - c_forfilter_b(i, C, C##_begin(&cnt), filter) if (!(cond)) break; else +#define c_FORFILTER5(i, C, cnt, filter, cond) \ + c_FORFILTER_B(i, C, C##_begin(&cnt), filter) if (!(cond)) break; else -#define c_forfilter_b(i, C, start, filter) \ +#define c_FORFILTER_B(i, C, start, filter) \ for (struct {C##_iter it; C##_value *ref; \ uint32_t s1[c_NFILTERS], index, count; \ bool s2[c_NFILTERS]; uint8_t s1top, s2top;} \ diff --git a/include/stc/carc.h b/include/stc/carc.h index f14fdd65..130b90ef 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -45,7 +45,7 @@ int main() { ArcPers q = ArcPers_clone(p); // share the pointer printf("%s %s. uses: %ld\n", cstr_str(&q.get->name), cstr_str(&q.get->last), *q.use_count); - c_drop(ArcPers, &p, &q); + c_DROP(ArcPers, &p, &q); } */ #include "ccommon.h" @@ -101,14 +101,14 @@ STC_INLINE long _cx_memb(_use_count)(const _cx_self* self) STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) { _cx_self ptr = {p}; if (p) - *(ptr.use_count = c_alloc(catomic_long)) = 1; + *(ptr.use_count = c_ALLOC(catomic_long)) = 1; return ptr; } // c++: std::make_shared<_cx_value>(val) STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { _cx_self ptr; - struct _cx_memb(_rep_)* rep = c_alloc(struct _cx_memb(_rep_)); + struct _cx_memb(_rep_)* rep = c_ALLOC(struct _cx_memb(_rep_)); *(ptr.use_count = &rep->counter) = 1; *(ptr.get = &rep->value) = val; return ptr; @@ -127,8 +127,8 @@ STC_INLINE void _cx_memb(_drop)(_cx_self* self) { if (self->use_count && _i_atomic_dec_and_test(self->use_count)) { i_keydrop(self->get); if ((char *)self->get != (char *)self->use_count + offsetof(struct _cx_memb(_rep_), value)) - c_free(self->get); - c_free((long*)self->use_count); + c_FREE(self->get); + c_FREE((long*)self->use_count); } } diff --git a/include/stc/cbits.h b/include/stc/cbits.h index 3c187e78..fde1d05f 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -27,13 +27,13 @@ Similar to boost::dynamic_bitset / std::bitset #include "cbits.h" int main() { - c_with (cbits bset = cbits_with_size(23, true), cbits_drop(&bset)) + c_WITH (cbits bset = cbits_with_size(23, true), cbits_drop(&bset)) { cbits_reset(&bset, 9); cbits_resize(&bset, 43, false); printf("%4zu: ", cbits_size(&bset)); - c_forrange (i, cbits_size(&bset)) + c_FORRANGE (i, cbits_size(&bset)) printf("%d", cbits_at(&bset, i)); puts(""); cbits_set(&bset, 28); @@ -43,7 +43,7 @@ int main() { cbits_set_value(&bset, 99, false); printf("%4zu: ", cbits_size(&bset)); - c_forrange (i, cbits_size(&bset)) + c_FORRANGE (i, cbits_size(&bset)) printf("%d", cbits_at(&bset, i)); puts(""); } @@ -125,7 +125,7 @@ struct { uint64_t *data64; size_t _size; } typedef i_type; STC_INLINE cbits cbits_init(void) { return c_INIT(cbits){NULL}; } STC_INLINE void cbits_create(cbits* self) { self->data64 = NULL; self->_size = 0; } -STC_INLINE void cbits_drop(cbits* self) { c_free(self->data64); } +STC_INLINE void cbits_drop(cbits* self) { c_FREE(self->data64); } STC_INLINE size_t cbits_size(const cbits* self) { return self->_size; } STC_INLINE cbits* cbits_take(cbits* self, cbits other) { @@ -138,7 +138,7 @@ STC_INLINE cbits* cbits_take(cbits* self, cbits other) { STC_INLINE cbits cbits_clone(cbits other) { const size_t bytes = _cbits_bytes(other._size); - cbits set = {(uint64_t *)memcpy(c_malloc(bytes), other.data64, bytes), other._size}; + cbits set = {(uint64_t *)memcpy(c_MALLOC(bytes), other.data64, bytes), other._size}; return set; } @@ -153,7 +153,7 @@ STC_INLINE cbits* cbits_copy(cbits* self, const cbits* other) { STC_INLINE void cbits_resize(cbits* self, const size_t size, const bool value) { const size_t new_n = _cbits_words(size), osize = self->_size, old_n = _cbits_words(osize); - self->data64 = (uint64_t *)c_realloc(self->data64, new_n*8); + self->data64 = (uint64_t *)c_REALLOC(self->data64, new_n*8); self->_size = size; if (new_n >= old_n) { memset(self->data64 + old_n, -(int)value, (new_n - old_n)*8); @@ -175,13 +175,13 @@ STC_INLINE cbits cbits_move(cbits* self) { } STC_INLINE cbits cbits_with_size(const size_t size, const bool value) { - cbits set = {(uint64_t *)c_malloc(_cbits_bytes(size)), size}; + cbits set = {(uint64_t *)c_MALLOC(_cbits_bytes(size)), size}; cbits_set_all(&set, value); return set; } STC_INLINE cbits cbits_with_pattern(const size_t size, const uint64_t pattern) { - cbits set = {(uint64_t *)c_malloc(_cbits_bytes(size)), size}; + cbits set = {(uint64_t *)c_MALLOC(_cbits_bytes(size)), size}; cbits_set_pattern(&set, pattern); return set; } diff --git a/include/stc/cbox.h b/include/stc/cbox.h index b8a61375..7be3dc36 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -37,7 +37,7 @@ Person Person_clone(Person p) { } void Person_drop(Person* p) { printf("drop: %s %s\n", cstr_str(&p->name), cstr_str(&p->email)); - c_drop(cstr, &p->name, &p->email); + c_DROP(cstr, &p->name, &p->email); } #define i_keyclass Person // bind Person clone+drop fn's @@ -45,7 +45,7 @@ void Person_drop(Person* p) { #include <stc/cbox.h> int main() { - c_auto (PBox, p, q) + c_AUTO (PBox, p, q) { p = PBox_from(Person_from("John Smiths", "[email protected]")); q = PBox_clone(p); @@ -89,7 +89,7 @@ STC_INLINE _cx_self _cx_memb(_from_ptr)(_cx_value* p) // c++: std::make_unique<i_key>(val) STC_INLINE _cx_self _cx_memb(_make)(_cx_value val) { - _cx_self ptr = {c_alloc(_cx_value)}; + _cx_self ptr = {c_ALLOC(_cx_value)}; *ptr.get = val; return ptr; } @@ -100,7 +100,7 @@ STC_INLINE _cx_raw _cx_memb(_toraw)(const _cx_self* self) STC_INLINE void _cx_memb(_drop)(_cx_self* self) { if (self->get) { i_keydrop(self->get); - c_free(self->get); + c_FREE(self->get); } } @@ -136,7 +136,7 @@ STC_INLINE _cx_self _cx_memb(_from)(_cx_value val) STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) { if (!other.get) return other; - _cx_self out = {c_alloc(i_key)}; + _cx_self out = {c_ALLOC(i_key)}; *out.get = i_keyclone(*other.get); return out; } diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 95c35915..ce6bba84 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -29,7 +29,7 @@ #include <stdbool.h> #include <string.h> #include <assert.h> -#include "priv/allcaps.h" +#include "priv/lowcase.h" #if SIZE_MAX == UINT32_MAX #define c_ZU PRIu32 @@ -62,33 +62,33 @@ #define _c_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, \ _14, _15, _16, N, ...) N -#define c_static_assert(cond) \ +#define c_STATIC_ASSERT(cond) \ typedef char c_PASTE(_static_assert_line_, __LINE__)[(cond) ? 1 : -1] -#define c_container_of(p, T, m) \ +#define c_CONTAINER_OF(p, T, m) \ ((T*)((char*)(p) + 0*sizeof((p) == &((T*)0)->m) - offsetof(T, m))) #ifndef __cplusplus - #define c_alloc(T) c_malloc(sizeof(T)) - #define c_alloc_n(T, n) c_malloc(sizeof(T)*(n)) - #define c_new(T, ...) ((T*)memcpy(c_alloc(T), (T[]){__VA_ARGS__}, sizeof(T))) + #define c_ALLOC(T) c_MALLOC(sizeof(T)) + #define c_ALLOC_N(T, n) c_MALLOC(sizeof(T)*(n)) + #define c_NEW(T, ...) ((T*)memcpy(c_ALLOC(T), (T[]){__VA_ARGS__}, sizeof(T))) #define c_INIT(T) (T) #else #include <new> - #define c_alloc(T) static_cast<T*>(c_malloc(sizeof(T))) - #define c_alloc_n(T, n) static_cast<T*>(c_malloc(sizeof(T)*(n))) - #define c_new(T, ...) new (c_alloc(T)) T(__VA_ARGS__) + #define c_ALLOC(T) static_cast<T*>(c_MALLOC(sizeof(T))) + #define c_ALLOC_N(T, n) static_cast<T*>(c_MALLOC(sizeof(T)*(n))) + #define c_NEW(T, ...) new (c_ALLOC(T)) T(__VA_ARGS__) #define c_INIT(T) T #endif -#ifndef c_malloc - #define c_malloc(sz) malloc(sz) - #define c_calloc(n, sz) calloc(n, sz) - #define c_realloc(p, sz) realloc(p, sz) - #define c_free(p) free(p) +#ifndef c_MALLOC + #define c_MALLOC(sz) malloc(sz) + #define c_CALLOC(n, sz) calloc(n, sz) + #define c_REALLOC(p, sz) realloc(p, sz) + #define c_FREE(p) free(p) #endif -#define c_delete(T, ptr) do { T *_c_p = ptr; T##_drop(_c_p); c_free(_c_p); } while (0) -#define c_swap(T, x, y) do { T _c_t = x; x = y; y = _c_t; } while (0) -#define c_arraylen(a) (sizeof (a)/sizeof *(a)) +#define c_DELETE(T, ptr) do { T *_c_p = ptr; T##_drop(_c_p); c_FREE(_c_p); } while (0) +#define c_SWAP(T, x, y) do { T _c_t = x; x = y; y = _c_t; } while (0) +#define c_ARRAYLEN(a) (sizeof (a)/sizeof *(a)) // x and y are i_keyraw* type, defaults to i_key*: #define c_default_cmp(x, y) (c_default_less(y, x) - c_default_less(x, y)) @@ -162,72 +162,72 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, return NULL; } -#define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__) -#define c_foreach3(it, C, cnt) \ +#define c_FOREACH(...) c_MACRO_OVERLOAD(c_FOREACH, __VA_ARGS__) +#define c_FOREACH3(it, C, cnt) \ for (C##_iter it = C##_begin(&cnt); it.ref; C##_next(&it)) -#define c_foreach4(it, C, start, finish) \ +#define c_FOREACH4(it, C, start, finish) \ for (C##_iter it = start, *_endref = (C##_iter*)(finish).ref \ ; it.ref != (C##_value*)_endref; C##_next(&it)) -#define c_forwhile(i, C, start, cond) \ +#define c_FORWHILE(i, C, start, cond) \ for (struct {C##_iter it; C##_value *ref; size_t index;} \ i = {.it=start, .ref=i.it.ref}; i.it.ref && (cond) \ ; C##_next(&i.it), i.ref = i.it.ref, ++i.index) -#define c_forpair(key, val, C, cnt) /* structured binding */ \ +#define c_FORPAIR(key, val, C, cnt) /* structured binding */ \ for (struct {C##_iter it; const C##_key* key; C##_mapped* val;} _ = {.it=C##_begin(&cnt)} \ ; _.it.ref && (_.key = &_.it.ref->first, _.val = &_.it.ref->second) \ ; C##_next(&_.it)) -#define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__) -#define c_forrange1(stop) c_forrange3(_c_i, 0, stop) -#define c_forrange2(i, stop) c_forrange3(i, 0, stop) -#define c_forrange3(i, start, stop) \ +#define c_FORRANGE(...) c_MACRO_OVERLOAD(c_FORRANGE, __VA_ARGS__) +#define c_FORRANGE1(stop) c_FORRANGE3(_c_i, 0, stop) +#define c_FORRANGE2(i, stop) c_FORRANGE3(i, 0, stop) +#define c_FORRANGE3(i, start, stop) \ for (long long i=start, _end=(long long)(stop); i < _end; ++i) -#define c_forrange4(i, start, stop, step) \ +#define c_FORRANGE4(i, start, stop, step) \ for (long long i=start, _inc=step, _end=(long long)(stop) - (_inc > 0) \ ; (_inc > 0) ^ (i > _end); i += _inc) #ifndef __cplusplus - #define c_forlist(it, T, ...) \ + #define c_FORLIST(it, T, ...) \ for (struct {T* data; T* ref; int size, index;} \ it = {.data=(T[])__VA_ARGS__, .ref=it.data, .size=sizeof((T[])__VA_ARGS__)/sizeof(T)} \ ; it.index < it.size; ++it.ref, ++it.index) #else #include <initializer_list> - #define c_forlist(it, T, ...) \ + #define c_FORLIST(it, T, ...) \ for (struct {std::initializer_list<T> _il; std::initializer_list<T>::iterator data, ref; size_t size, index;} \ it = {._il=__VA_ARGS__, .data=it._il.begin(), .ref=it.data, .size=it._il.size()} \ ; it.index < it.size; ++it.ref, ++it.index) #endif -#define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__) -#define c_with2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop) -#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_WITH(...) c_MACRO_OVERLOAD(c_WITH, __VA_ARGS__) +#define c_WITH2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop) +#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_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__) -#define c_auto2(C, a) \ - c_with2(C a = C##_init(), C##_drop(&a)) -#define c_auto3(C, a, b) \ - c_with2(c_EXPAND(C a = C##_init(), b = C##_init()), \ - (C##_drop(&b), C##_drop(&a))) -#define c_auto4(C, a, b, c) \ - c_with2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init()), \ - (C##_drop(&c), C##_drop(&b), C##_drop(&a))) -#define c_auto5(C, a, b, c, d) \ - 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_AUTO(...) c_MACRO_OVERLOAD(c_AUTO, __VA_ARGS__) +#define c_AUTO2(C, a) \ + c_WITH2(C a = C##_init(), C##_drop(&a)) +#define c_AUTO3(C, a, b) \ + c_WITH2(c_EXPAND(C a = C##_init(), b = C##_init()), \ + (C##_drop(&b), C##_drop(&a))) +#define c_AUTO4(C, a, b, c) \ + c_WITH2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init()), \ + (C##_drop(&c), C##_drop(&b), C##_drop(&a))) +#define c_AUTO5(C, a, b, c, d) \ + 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_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 { \ +#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; \ for (it = C##_begin(&cnt); it.ref && !(pred); C##_next(&it)) \ ++index; \ } while (0) -#define c_find_if5(it, C, start, end, pred) do { \ +#define c_FIND_IF5(it, C, start, end, pred) do { \ size_t index = 0; \ const C##_value* _endref = (end).ref; \ for (it = start; it.ref != _endref && !(pred); C##_next(&it)) \ @@ -235,7 +235,7 @@ STC_INLINE char* cstrnstrn(const char *str, const char *needle, if (it.ref == _endref) it.ref = NULL; \ } while (0) -#define c_erase_if(it, C, cnt, pred) do { \ +#define c_ERASE_IF(it, C, cnt, pred) do { \ C##_iter it = C##_begin(&cnt); \ for (size_t index = 0; it.ref; ++index) { \ if (pred) it = C##_erase_at(&cnt, it); \ diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 9416d5b2..d9205e61 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -90,7 +90,7 @@ STC_INLINE size_t _cx_memb(_size)(const _cx_self* self) { return self->_le STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) { return self->_cap; } STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return !self->_len; } STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* pval) { return i_keyto(pval); } -STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_self, *a, *b); } +STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_SWAP(_cx_self, *a, *b); } STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; } STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + self->_len - 1; } @@ -227,7 +227,7 @@ STC_DEF void _cx_memb(_shrink_to_fit)(_cx_self *self) { if (self->_len != self->_cap) { memmove(self->_base, self->data, self->_len*sizeof(i_key)); - _cx_value* d = (_cx_value*)c_realloc(self->_base, self->_len*sizeof(i_key)); + _cx_value* d = (_cx_value*)c_REALLOC(self->_base, self->_len*sizeof(i_key)); if (d) { self->_base = d; self->_cap = self->_len; @@ -240,7 +240,7 @@ STC_DEF void _cx_memb(_drop)(_cx_self* self) { if (self->_base) { _cx_memb(_clear)(self); - c_free(self->_base); + c_FREE(self->_base); } } @@ -248,7 +248,7 @@ static size_t _cx_memb(_realloc_)(_cx_self* self, const size_t n) { const size_t cap = (size_t)((float)self->_len*1.7f) + n + 7U; const size_t nfront = _cdeq_nfront(self); - _cx_value* d = (_cx_value*)c_realloc(self->_base, cap*sizeof(i_key)); + _cx_value* d = (_cx_value*)c_REALLOC(self->_base, cap*sizeof(i_key)); if (!d) return 0; self->_cap = cap; diff --git a/include/stc/clist.h b/include/stc/clist.h index 1ace1dac..89f3533e 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -34,19 +34,19 @@ int main() { - c_auto (clist_ix, list) + c_AUTO (clist_ix, list) { int n; for (int i = 0; i < 1000000; ++i) // one million clist_ix_push_back(&list, crandom() >> 32); n = 0; - c_foreach (i, clist_ix, list) + c_FOREACH (i, clist_ix, list) if (++n % 10000 == 0) printf("%8d: %10zu\n", n, *i.ref); // Sort them... clist_ix_sort(&list); // mergesort O(n*log n) n = 0; puts("sorted"); - c_foreach (i, clist_ix, list) + c_FOREACH (i, clist_ix, list) if (++n % 10000 == 0) printf("%8d: %10zu\n", n, *i.ref); } } @@ -64,13 +64,13 @@ SELF##_value value; \ } -#define _clist_tonode(vp) c_container_of(vp, _cx_node, value) +#define _clist_tonode(vp) c_CONTAINER_OF(vp, _cx_node, value) _c_clist_types(clist_VOID, int); _c_clist_complete_types(clist_VOID, dummy); #define _c_clist_insert_entry_after(ref, val) \ - _cx_node *entry = c_alloc(_cx_node); entry->value = val; \ + _cx_node *entry = c_ALLOC(_cx_node); entry->value = val; \ _c_clist_insert_node_after(ref, entry) #define _c_clist_insert_node_after(ref, entry) \ @@ -269,7 +269,7 @@ _clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const STC_DEF _cx_self _cx_memb(_clone)(_cx_self cx) { _cx_self out = _cx_memb(_init)(); - c_foreach (it, _cx_self, cx) + c_FOREACH (it, _cx_self, cx) _cx_memb(_push_back)(&out, i_keyclone((*it.ref))); return out; } @@ -344,7 +344,7 @@ STC_DEF void _cx_memb(_erase_node_after)(_cx_self* self, _cx_node* ref) { _cx_node* node = _cx_memb(_unlink_node_after)(self, ref); i_keydrop((&node->value)); - c_free(node); + c_FREE(node); } STC_DEF _cx_node* @@ -402,7 +402,7 @@ _cx_memb(_split_off)(_cx_self* self, _cx_iter it1, _cx_iter it2) { STC_DEF _cx_iter _cx_memb(_find_in)(_cx_iter it1, _cx_iter it2, _cx_raw val) { - c_foreach (it, _cx_self, it1, it2) { + c_FOREACH (it, _cx_self, it1, it2) { _cx_raw r = i_keyto(it.ref); if (i_eq((&r), (&val))) return it; diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 11edf127..1d0583f4 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -31,7 +31,7 @@ #include <stc/cmap.h> int main(void) { - c_with (cmap_ichar m = cmap_ichar_init(), cmap_ichar_drop(&m)) + c_WITH (cmap_ichar m = cmap_ichar_init(), cmap_ichar_drop(&m)) { cmap_ichar_emplace(&m, 5, 'a'); cmap_ichar_emplace(&m, 8, 'b'); @@ -42,7 +42,7 @@ int main(void) { cmap_ichar_emplace_or_assign(&m, 5, 'd'); // update cmap_ichar_erase(&m, 8); - c_foreach (i, cmap_ichar, m) + c_FOREACH (i, cmap_ichar, m) printf("map %d: %c\n", i.ref->first, i.ref->second); } } @@ -115,7 +115,7 @@ STC_INLINE size_t _cx_memb(_size)(const _cx_self* map) { return map->size; STC_INLINE size_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; } STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* map) { return (size_t)((float)map->bucket_count * (i_max_load_factor)); } -STC_INLINE void _cx_memb(_swap)(_cx_self *map1, _cx_self *map2) {c_swap(_cx_self, *map1, *map2); } +STC_INLINE void _cx_memb(_swap)(_cx_self *map1, _cx_self *map2) {c_SWAP(_cx_self, *map1, *map2); } STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } @@ -298,8 +298,8 @@ STC_INLINE void _cx_memb(_wipe_)(_cx_self* self) { STC_DEF void _cx_memb(_drop)(_cx_self* self) { _cx_memb(_wipe_)(self); - c_free(self->_hashx); - c_free((void *) self->table); + c_FREE(self->_hashx); + c_FREE((void *) self->table); } STC_DEF void _cx_memb(_clear)(_cx_self* self) { @@ -370,10 +370,10 @@ _cx_memb(_insert_entry_)(_cx_self* self, _cx_rawkey rkey) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self m) { if (m.table) { - _cx_value *t = c_alloc_n(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count; - uint8_t *h = (uint8_t *)memcpy(c_malloc(m.bucket_count + 1), m._hashx, m.bucket_count + 1); + _cx_value *t = c_ALLOC_N(_cx_value, m.bucket_count), *dst = t, *m_end = m.table + m.bucket_count; + uint8_t *h = (uint8_t *)memcpy(c_MALLOC(m.bucket_count + 1), m._hashx, m.bucket_count + 1); if (!(t && h)) - { c_free(t), c_free(h), t = 0, h = 0, m.bucket_count = 0; } + { c_FREE(t), c_FREE(h), t = 0, h = 0, m.bucket_count = 0; } else for (; m.table != m_end; ++m.table, ++m._hashx, ++dst) if (*m._hashx) @@ -396,8 +396,8 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { _nbuckets |= 1; #endif _cx_self m = { - c_alloc_n(_cx_value, _nbuckets), - (uint8_t *) c_calloc(_nbuckets + 1, 1), + c_ALLOC_N(_cx_value, _nbuckets), + (uint8_t *) c_CALLOC(_nbuckets + 1, 1), self->size, (i_size)_nbuckets, }; bool ok = m.table && m._hashx; @@ -411,10 +411,10 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) { m.table[b.idx] = *e; m._hashx[b.idx] = (uint8_t)b.hx; } - c_swap(_cx_self, *self, m); + c_SWAP(_cx_self, *self, m); } - c_free(m._hashx); - c_free(m.table); + c_FREE(m._hashx); + c_FREE(m.table); return ok; } diff --git a/include/stc/cpque.h b/include/stc/cpque.h index c1e7c13b..7f4bb588 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -49,7 +49,7 @@ STC_INLINE _cx_self _cx_memb(_init)(void) STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap != self->_len && cap <= self->_cap) return true; - _cx_value *d = (_cx_value *)c_realloc(self->data, cap*sizeof *d); + _cx_value *d = (_cx_value *)c_REALLOC(self->data, cap*sizeof *d); return d ? (self->data = d, self->_cap = cap, true) : false; } @@ -73,7 +73,7 @@ STC_INLINE void _cx_memb(_clear)(_cx_self* self) { } STC_INLINE void _cx_memb(_drop)(_cx_self* self) - { _cx_memb(_clear)(self); c_free(self->data); } + { _cx_memb(_clear)(self); c_FREE(self->data); } STC_INLINE size_t _cx_memb(_size)(const _cx_self* q) { return q->_len; } diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h index 0c0df063..319b5b47 100644 --- a/include/stc/cqueue.h +++ b/include/stc/cqueue.h @@ -33,7 +33,7 @@ int main() { stc64_t rng = stc64_new(1234); stc64_uniform_t dist = stc64_uniform_new(0, n); - c_auto (cqueue_int, Q) + c_AUTO (cqueue_int, Q) { // Push ten million random numbers onto the queue. for (int i=0; i<n; ++i) diff --git a/include/stc/cregex.h b/include/stc/cregex.h index 975bd675..4bb17938 100644 --- a/include/stc/cregex.h +++ b/include/stc/cregex.h @@ -79,7 +79,7 @@ typedef struct { csview match[CREG_MAX_CAPTURES]; } cregex_iter; -#define c_formatch(it, Re, Input) \ +#define c_FORMATCH(it, Re, Input) \ for (cregex_iter it = {Re, Input}; \ cregex_find(it.re, it.input, it.match, CREG_M_NEXT) == CREG_OK; ) diff --git a/include/stc/cset.h b/include/stc/cset.h index 0dddc02f..cc3aa1e4 100644 --- a/include/stc/cset.h +++ b/include/stc/cset.h @@ -33,7 +33,7 @@ int main(void) { cset_sx_insert(&s, 5); cset_sx_insert(&s, 8); - c_foreach (i, cset_sx, s) + c_FOREACH (i, cset_sx, s) printf("set %d\n", *i.ref); cset_sx_drop(&s); } diff --git a/include/stc/csmap.h b/include/stc/csmap.h index f651db00..e3b82fea 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -32,7 +32,7 @@ #include <stc/csmap.h> int main(void) { - c_with (csmap_sx m = csmap_sx_init(), csmap_sx_drop(&m)) + c_WITH (csmap_sx m = csmap_sx_init(), csmap_sx_drop(&m)) { csmap_sx_emplace(&m, "Testing one", 1.234); csmap_sx_emplace(&m, "Testing two", 12.34); @@ -43,7 +43,7 @@ int main(void) { csmap_sx_emplace_or_assign(&m, "Testing three", 1000.0); // update csmap_sx_erase(&m, "Testing two"); - c_foreach (i, csmap_sx, m) + c_FOREACH (i, csmap_sx, m) printf("map %s: %g\n", cstr_str(&i.ref->first), i.ref->second); } } @@ -120,7 +120,7 @@ STC_API void _cx_memb(_next)(_cx_iter* it); STC_INLINE bool _cx_memb(_empty)(const _cx_self* cx) { return cx->size == 0; } STC_INLINE size_t _cx_memb(_size)(const _cx_self* cx) { return cx->size; } STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* cx) { return cx->cap; } -STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_self, *a, *b); } +STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_SWAP(_cx_self, *a, *b); } STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey) { _cx_iter it; _cx_memb(_find_it)(self, rkey, &it); return it; } STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey) @@ -229,7 +229,7 @@ STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap <= self->cap) return false; - _cx_node* nodes = (_cx_node*)c_realloc(self->nodes, (cap + 1)*sizeof(_cx_node)); + _cx_node* nodes = (_cx_node*)c_REALLOC(self->nodes, (cap + 1)*sizeof(_cx_node)); if (!nodes) return false; nodes[0] = c_INIT(_cx_node){{0, 0}, 0}; @@ -563,7 +563,7 @@ STC_DEF void _cx_memb(_drop)(_cx_self* self) { if (self->cap) { _cx_memb(_drop_r_)(self->nodes, self->root); - c_free(self->nodes); + c_FREE(self->nodes); } } diff --git a/include/stc/csset.h b/include/stc/csset.h index 753ed063..1ae8c3f2 100644 --- a/include/stc/csset.h +++ b/include/stc/csset.h @@ -36,7 +36,7 @@ int main(void) { csset_i_insert(&s, 3); csset_i_insert(&s, 5); - c_foreach (k, csset_i, s) + c_FOREACH (k, csset_i, s) printf("set %d\n", *k.ref); csset_i_drop(&s); } diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 5e87cf9f..9fb96e3c 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -59,12 +59,12 @@ STC_INLINE void _cx_memb(_create)(_cx_self* self) { self->_len = 0; self->_cap = 0; self->data = NULL; } STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) { - _cx_self out = {(_cx_value *) c_malloc(cap*sizeof(i_key)), 0, cap}; + _cx_self out = {(_cx_value *) c_MALLOC(cap*sizeof(i_key)), 0, cap}; return out; } STC_INLINE _cx_self _cx_memb(_with_size)(size_t size, i_key null) { - _cx_self out = {(_cx_value *) c_malloc(size*sizeof null), size, size}; + _cx_self out = {(_cx_value *) c_MALLOC(size*sizeof null), size, size}; while (size) out.data[--size] = null; return out; } @@ -79,7 +79,7 @@ STC_INLINE void _cx_memb(_clear)(_cx_self* self) { STC_INLINE void _cx_memb(_drop)(_cx_self* self) { _cx_memb(_clear)(self); #ifndef i_capacity - c_free(self->data); + c_FREE(self->data); #endif } @@ -100,7 +100,7 @@ STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) { STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { if (n < self->_len) return true; #ifndef i_capacity - _cx_value *t = (_cx_value *)c_realloc(self->data, n*sizeof *t); + _cx_value *t = (_cx_value *)c_REALLOC(self->data, n*sizeof *t); if (t) { self->_cap = n, self->data = t; return true; } #endif return false; @@ -149,7 +149,7 @@ STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) #if !defined i_no_clone STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) { - _cx_self out = {(_cx_value *)c_malloc(v._len*sizeof(_cx_value)), v._len, v._len}; + _cx_self out = {(_cx_value *)c_MALLOC(v._len*sizeof(_cx_value)), v._len, v._len}; if (!out.data) out._cap = 0; else for (size_t i = 0; i < v._len; ++v.data) out.data[i++] = i_keyclone((*v.data)); diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 9748b72c..d1a1e765 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -62,7 +62,7 @@ enum { cstr_s_cap = sizeof(cstr_buf) - 2 }; #define cstr_l_size(s) ((s)->lon.size) #define cstr_l_set_size(s, len) ((s)->lon.data[(s)->lon.size = (len)] = 0) #define cstr_l_data(s) (s)->lon.data -#define cstr_l_drop(s) c_free((s)->lon.data) +#define cstr_l_drop(s) c_FREE((s)->lon.data) #define cstr_is_long(s) ((s)->sml.size > 127) STC_API char* _cstr_init(cstr* self, size_t len, size_t cap); @@ -473,7 +473,7 @@ STC_DEF char* _cstr_internal_move(cstr* self, const size_t pos1, const size_t po STC_DEF char* _cstr_init(cstr* self, const size_t len, const size_t cap) { if (cap > cstr_s_cap) { - self->lon.data = (char *)c_malloc(cap + 1); + self->lon.data = (char *)c_MALLOC(cap + 1); cstr_l_set_size(self, len); cstr_l_set_cap(self, cap); return self->lon.data; @@ -487,26 +487,26 @@ STC_DEF void cstr_shrink_to_fit(cstr* self) { if (r.size == r.cap) return; if (r.size > cstr_s_cap) { - self->lon.data = (char *)c_realloc(self->lon.data, r.size + 1); + self->lon.data = (char *)c_REALLOC(self->lon.data, r.size + 1); cstr_l_set_cap(self, r.size); } else if (r.cap > cstr_s_cap) { memcpy(self->sml.data, r.data, r.size + 1); cstr_s_set_size(self, r.size); - c_free(r.data); + c_FREE(r.data); } } STC_DEF char* cstr_reserve(cstr* self, const size_t cap) { if (cstr_is_long(self)) { if (cap > cstr_l_cap(self)) { - self->lon.data = (char *)c_realloc(self->lon.data, cap + 1); + self->lon.data = (char *)c_REALLOC(self->lon.data, cap + 1); cstr_l_set_cap(self, cap); } return self->lon.data; } /* from short to long: */ if (cap > cstr_s_cap) { - char* data = (char *)c_malloc(cap + 1); + char* data = (char *)c_MALLOC(cap + 1); const size_t len = cstr_s_size(self); memcpy(data, self->sml.data, cstr_s_cap + 1); self->lon.data = data; diff --git a/include/stc/csview.h b/include/stc/csview.h index 972bc788..638d9920 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -115,13 +115,13 @@ STC_API csview csview_substr_ex(csview sv, intptr_t pos, size_t n); STC_API csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2); STC_API csview csview_token(csview sv, const char* sep, size_t* start); -#define c_fortoken_sv(it, inputsv, sep) \ +#define c_FORTOKEN_SV(it, inputsv, sep) \ for (struct { csview _inp, token, *ref; const char *_sep; size_t pos; } \ it = {._inp=inputsv, .token=it._inp, .ref=&it.token, ._sep=sep} \ ; it.pos <= it._inp.size && (it.token = csview_token(it._inp, it._sep, &it.pos)).str ; ) -#define c_fortoken(it, input, sep) \ - c_fortoken_sv(it, csview_from(input), sep) +#define c_FORTOKEN(it, input, sep) \ + c_FORTOKEN_SV(it, csview_from(input), sep) /* csview interaction with cstr: */ #ifdef CSTR_H_INCLUDED diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 5eaefa04..40e9ad4f 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -128,7 +128,7 @@ STC_INLINE size_t _cx_memb(_size)(const _cx_self* self) { return self->_le STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) { return self->_cap; } STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return !self->_len; } STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* val) { return i_keyto(val); } -STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_swap(_cx_self, *a, *b); } +STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_SWAP(_cx_self, *a, *b); } STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; } STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return self->data + self->_len - 1; } @@ -274,13 +274,13 @@ _cx_memb(_drop)(_cx_self* self) { if (self->_cap == 0) return; _cx_memb(_clear)(self); - c_free(self->data); + c_FREE(self->data); } STC_DEF bool _cx_memb(_reserve)(_cx_self* self, const size_t cap) { if (cap > self->_cap || (cap && cap == self->_len)) { - _cx_value* d = (_cx_value*)c_realloc(self->data, cap*sizeof(i_key)); + _cx_value* d = (_cx_value*)c_REALLOC(self->data, cap*sizeof(i_key)); if (!d) return false; self->data = d; diff --git a/include/stc/priv/allcaps.h b/include/stc/priv/lowcase.h index 1e2460b5..d9ad0f93 100644 --- a/include/stc/priv/allcaps.h +++ b/include/stc/priv/lowcase.h @@ -20,37 +20,36 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#define c_ALLOC c_alloc -#define c_ALLOC_N c_alloc_n -#define c_NEW c_new -#define c_MALLOC c_malloc -#define c_CALLOC c_calloc -#define c_REALLOC c_realloc -#define c_FREE c_free -#define c_DELETE c_delete -#define c_SWAP c_swap -#define c_CONTAINER_OF c_container_of -#define c_STATIC_ASSERT c_static_assert -#define c_ARRAYLEN c_arraylen -#define c_OPTION c_option -#define c_FORLIST c_forlist -#define c_FORRANGE c_forrange -#define c_FOREACH c_foreach -#define c_FORWHILE c_forwhile -#define c_FORPAIR c_forpair -#define c_FORFILTER c_forfilter -#define c_FORMATCH c_formatch -#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_FIND_IF c_find_if -#define c_ERASE_IF c_erase_if -#define c_FLT_TAKE c_flt_take -#define c_FLT_SKIP c_flt_skip -#define c_FLT_SKIPWHILE c_flt_skipwhile -#define c_FLT_TAKEWHILE c_flt_takewhile +#define c_alloc c_ALLOC +#define c_alloc_n c_ALLOC_N +#define c_new c_NEW +#define c_malloc c_MALLOC +#define c_calloc c_CALLOC +#define c_realloc c_REALLOC +#define c_free c_FREE +#define c_delete c_DELETE +#define c_swap c_SWAP +#define c_container_of c_CONTAINER_OF +#define c_static_assert c_STATIC_ASSERT +#define c_arraylen c_ARRAYLEN +#define c_forlist c_FORLIST +#define c_forrange c_FORRANGE +#define c_foreach c_FOREACH +#define c_forwhile c_FORWHILE +#define c_forpair c_FORPAIR +#define c_forfilter c_FORFILTER +#define c_formatch c_FORMATCH +#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_find_if c_FIND_IF +#define c_erase_if c_ERASE_IF +#define c_flt_take c_FLT_TAKE +#define c_flt_skip c_FLT_SKIP +#define c_flt_skipwhile c_FLT_SKIPWHILE +#define c_flt_takewhile c_FLT_TAKEWHILE |
