summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-10-17 11:12:45 +0200
committerTyge Løvset <[email protected]>2020-10-17 11:12:45 +0200
commiteaafb4cdc64215f054ee87ddd307b81264ed8b7a (patch)
tree3f98674af81d6ce75b346d05a8cb3a5c7cc45350
parent490e03ae9f2007ef1da38a141479770e1c4a61c0 (diff)
downloadSTC-modified-eaafb4cdc64215f054ee87ddd307b81264ed8b7a.tar.gz
STC-modified-eaafb4cdc64215f054ee87ddd307b81264ed8b7a.zip
Internal renaming of STC_IMP to STC_DEF. Removed cstr_INIT. Use cstr_init().
-rw-r--r--README.md2
-rw-r--r--examples/ex_gaussian.c6
-rw-r--r--examples/random.c2
-rw-r--r--stc/cbitset.h18
-rw-r--r--stc/ccommon.h12
-rw-r--r--stc/clist.h30
-rw-r--r--stc/cmap.h24
-rw-r--r--stc/cpqueue.h2
-rw-r--r--stc/cqueue.h2
-rw-r--r--stc/crandom.h12
-rw-r--r--stc/cstack.h2
-rw-r--r--stc/cstr.h54
-rw-r--r--stc/cvec.h22
13 files changed, 94 insertions, 94 deletions
diff --git a/README.md b/README.md
index 047b5a68..3d9f2274 100644
--- a/README.md
+++ b/README.md
@@ -441,7 +441,7 @@ using_carray(f, float);
int main()
{
- carray3f a3 = carray3f_make(30, 20, 10, 0.0f); // define a3[30][20][10], init with 0.0f.
+ carray3f a3 = carray3f_init(30, 20, 10, 0.0f); // define a3[30][20][10], init with 0.0f.
*carray3f_at(&a3, 5, 4, 3) = 3.14f; // a3[5][4][3] = 3.14
carray1f a1 = carray3f_at2(&a3, 5, 4); // sub-array a3[5][4] (no data copy).
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c
index 1ff494f5..dc04215c 100644
--- a/examples/ex_gaussian.c
+++ b/examples/ex_gaussian.c
@@ -29,20 +29,20 @@ int main()
crand_normal_f64_t dist = crand_normal_f64_init(Mean, StdDev);
// Create histogram map
- cmap_i mhist = cmap_INIT;
+ cmap_i mhist = cmap_i_init();
for (size_t i = 0; i < N; ++i) {
int index = (int) round( crand_normal_f64(&rng, &dist) );
cmap_i_emplace(&mhist, index, 0).first->second += 1;
}
// Transfer map to vec and sort it by map keys.
- cvec_e vhist = cvec_INIT;
+ cvec_e vhist = cvec_e_init();
c_foreach (i, cmap_i, mhist)
cvec_e_push_back(&vhist, *i.val);
cvec_e_sort(&vhist);
// Print the gaussian bar chart
- cstr_t bar = cstr_INIT;
+ cstr_t bar = cstr_init();
c_foreach (i, cvec_e, vhist) {
size_t n = (size_t) (i.val->second * Mag / N);
if (n > 0) {
diff --git a/examples/random.c b/examples/random.c
index fa63d2af..7f1be3f5 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -58,7 +58,7 @@ int main()
if (n >= 0 && n < R) ++hist[n];
}
- cstr_t bar = cstr_INIT;
+ cstr_t bar = cstr_init();
c_forrange (i, int, R) {
cstr_take(&bar, cstr_with_size(hist[i] * 25ull * R / N2, '*'));
printf("%2d %s\n", i, bar.str);
diff --git a/stc/cbitset.h b/stc/cbitset.h
index 4eb0c7f5..cc437ce1 100644
--- a/stc/cbitset.h
+++ b/stc/cbitset.h
@@ -168,7 +168,7 @@ STC_INLINE bool cbitset_itval(cbitset_iter_t it) {
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-STC_IMP void cbitset_resize(cbitset_t* self, size_t size, bool value) {
+STC_DEF void cbitset_resize(cbitset_t* self, size_t size, bool value) {
size_t new_n = (size + 63) >> 6, osize = self->size, old_n = (osize + 63) >> 6;
self->_arr = (uint64_t *) c_realloc(self->_arr, new_n * 8);
self->size = size;
@@ -181,28 +181,28 @@ STC_IMP void cbitset_resize(cbitset_t* self, size_t size, bool value) {
}
}
-STC_IMP cbitset_t cbitset_with_size(size_t size, bool value) {
+STC_DEF cbitset_t cbitset_with_size(size_t size, bool value) {
cbitset_t set = {(uint64_t *) c_malloc(((size + 63) >> 6) * 8), size};
cbitset_set_all(&set, value);
return set;
}
-STC_IMP cbitset_t cbitset_from_str(const char* str) {
+STC_DEF cbitset_t cbitset_from_str(const char* str) {
const char* p = str; while (*p) ++p;
cbitset_t set = cbitset_with_size(p - str, false);
for (size_t i=0; i<set.size; ++i) if (str[i] == '1') cbitset_set(&set, i);
return set;
}
-STC_IMP cstr_t cbitset_to_str(cbitset_t set) {
+STC_DEF cstr_t cbitset_to_str(cbitset_t set) {
cstr_t out = cstr_with_size(set.size, '0');
for (size_t i=0; i<set.size; ++i) if (cbitset_test(set, i)) out.str[i] = '1';
return out;
}
-STC_IMP cbitset_t cbitset_clone(cbitset_t other) {
+STC_DEF cbitset_t cbitset_clone(cbitset_t other) {
size_t bytes = ((other.size + 63) >> 6) * 8;
cbitset_t set = {(uint64_t *) memcpy(c_malloc(bytes), other._arr, bytes), other.size};
return set;
}
-STC_IMP size_t cbitset_count(cbitset_t s) {
+STC_DEF size_t cbitset_count(cbitset_t s) {
size_t count = 0, n = ((s.size + 63) >> 6) - 1;
if (s.size > 0) {
for (size_t i=0; i<n; ++i) count += cpopcount64(s._arr[i]);
@@ -221,9 +221,9 @@ STC_IMP size_t cbitset_count(cbitset_t s) {
uint64_t m = (1ull << (s.size & 63)) - 1, last = s._arr[n] & m; \
return (last OPR (other._arr[n] & m)) == last
-STC_IMP bool cbitset_is_disjoint(cbitset_t s, cbitset_t other) { _cbitset_SETOP(^); }
-STC_IMP bool cbitset_is_subset(cbitset_t s, cbitset_t other) { _cbitset_SETOP(|); }
-STC_IMP bool cbitset_is_superset(cbitset_t s, cbitset_t other) { _cbitset_SETOP(&); }
+STC_DEF bool cbitset_is_disjoint(cbitset_t s, cbitset_t other) { _cbitset_SETOP(^); }
+STC_DEF bool cbitset_is_subset(cbitset_t s, cbitset_t other) { _cbitset_SETOP(|); }
+STC_DEF bool cbitset_is_superset(cbitset_t s, cbitset_t other) { _cbitset_SETOP(&); }
#endif
#endif
diff --git a/stc/ccommon.h b/stc/ccommon.h
index 1eb50432..65c4b41a 100644
--- a/stc/ccommon.h
+++ b/stc/ccommon.h
@@ -39,14 +39,14 @@
#if defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
# define STC_API extern
-# define STC_IMP
-# define STC_APIV extern
-# define STC_IMPV
+# define STC_DEF
+# define STC_API_V extern
+# define STC_DEF_V
#else
# define STC_API static inline
-# define STC_IMP static inline
-# define STC_APIV static
-# define STC_IMPV static
+# define STC_DEF static inline
+# define STC_API_V static
+# define STC_DEF_V static
#endif
/* Macro overloading feature support: https://rextester.com/ONP80107 */
diff --git a/stc/clist.h b/stc/clist.h
index 9375405b..3b4a3642 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -213,39 +213,39 @@ STC_API size_t _clist_size(const clist_void* self);
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
#define _c_implement_clist_7(X, Value, valueDestroy, valueCompareRaw, RawValue, valueToRaw, valueFromRaw) \
\
- STC_IMP void \
+ STC_DEF void \
clist_##X##_del(clist_##X* self) { \
while (self->last) _clist_##X##_erase_after(self, self->last); \
} \
\
- STC_IMP void \
+ STC_DEF void \
clist_##X##_push_back(clist_##X* self, Value value) { \
_c_clist_insert_after(self, X, self->last, value); \
self->last = entry; \
} \
- STC_IMP void \
+ STC_DEF void \
clist_##X##_push_front(clist_##X* self, Value value) { \
_c_clist_insert_after(self, X, self->last, value); \
if (!self->last) self->last = entry; \
} \
- STC_IMP void \
+ STC_DEF void \
clist_##X##_push_n(clist_##X *self, const clist_##X##_input_t in[], size_t size) { \
for (size_t i=0; i<size; ++i) clist_##X##_push_back(self, valueFromRaw(in[i])); \
} \
\
- STC_IMP clist_##X##_iter_t \
+ STC_DEF clist_##X##_iter_t \
clist_##X##_insert_after(clist_##X* self, clist_##X##_iter_t pos, Value value) { \
clist_##X##_node_t* node = pos.val ? _clist_node(X, pos.val) : NULL; \
_c_clist_insert_after(self, X, node, value); \
if (!node || node == self->last && pos._state == 0) self->last = entry; \
pos.val = &entry->value, pos._state = 0; return pos; \
} \
- STC_IMP clist_##X##_iter_t \
+ STC_DEF clist_##X##_iter_t \
clist_##X##_erase_after(clist_##X* self, clist_##X##_iter_t pos) { \
_clist_##X##_erase_after(self, _clist_node(X, pos.val)); \
clist_##X##_next(&pos); return pos; \
} \
- STC_IMP clist_##X##_iter_t \
+ STC_DEF clist_##X##_iter_t \
clist_##X##_erase_range_after(clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish) { \
clist_##X##_node_t* node = _clist_node(X, first.val), *done = finish.val ? _clist_node(X, finish.val) : NULL; \
while (node && node->next != done) \
@@ -253,7 +253,7 @@ STC_API size_t _clist_size(const clist_void* self);
clist_##X##_next(&first); return first; \
} \
\
- STC_IMP clist_##X##_iter_t \
+ STC_DEF clist_##X##_iter_t \
clist_##X##_find_before(const clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish, RawValue val) { \
clist_##X##_iter_t i = first; \
for (clist_##X##_next(&i); i.val != finish.val; clist_##X##_next(&i)) { \
@@ -264,13 +264,13 @@ STC_API size_t _clist_size(const clist_void* self);
return clist_##X##_end(self); \
} \
\
- STC_IMP clist_##X##_iter_t \
+ STC_DEF clist_##X##_iter_t \
clist_##X##_find(const clist_##X* self, RawValue val) { \
clist_##X##_iter_t it = clist_##X##_find_before(self, clist_##X##_before_begin(self), clist_##X##_end(self), val); \
if (it.val != clist_##X##_end(self).val) clist_##X##_next(&it); \
return it; \
} \
- STC_IMP clist_##X##_node_t* \
+ STC_DEF clist_##X##_node_t* \
_clist_##X##_erase_after(clist_##X* self, clist_##X##_node_t* node) { \
clist_##X##_node_t* del = node->next, *next = del->next; \
node->next = next; \
@@ -280,7 +280,7 @@ STC_API size_t _clist_size(const clist_void* self);
return node; \
} \
\
- STC_IMP size_t \
+ STC_DEF size_t \
clist_##X##_remove(clist_##X* self, RawValue val) { \
size_t n = 0; \
clist_##X##_node_t* prev = self->last, *node; \
@@ -295,7 +295,7 @@ STC_API size_t _clist_size(const clist_void* self);
return n; \
} \
\
- STC_IMP void \
+ STC_DEF void \
clist_##X##_splice_after(clist_##X* self, clist_##X##_iter_t pos, clist_##X* other) { \
if (!pos.val) \
self->last = other->last; \
@@ -314,7 +314,7 @@ STC_API size_t _clist_size(const clist_void* self);
RawValue b = valueToRaw(&((clist_##X##_node_t *) y)->value); \
return valueCompareRaw(&a, &b); \
} \
- STC_IMP void \
+ STC_DEF void \
clist_##X##_sort(clist_##X* self) { \
clist_void_node_t* last = _clist_mergesort((clist_void_node_t *) self->last->next, clist_##X##_sort_compare); \
self->last = (clist_##X##_node_t *) last; \
@@ -329,7 +329,7 @@ STC_API size_t _clist_size(const clist_void* self);
if (node) node->next = entry
/* +: set self->last based on node */
-STC_IMP size_t
+STC_DEF size_t
_clist_size(const clist_void* self) {
const clist_void_node_t *i = self->last;
if (!i) return 0;
@@ -341,7 +341,7 @@ _clist_size(const clist_void* self) {
/* Singly linked list Mergesort implementation by Simon Tatham. O(n*log n).
* https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
*/
-STC_IMP clist_void_node_t *
+STC_DEF clist_void_node_t *
_clist_mergesort(clist_void_node_t *list, int (*cmp)(const void*, const void*)) {
clist_void_node_t *p, *q, *e, *tail, *oldhead;
int insize = 1, nmerges, psize, qsize, i;
diff --git a/stc/cmap.h b/stc/cmap.h
index 1a8782c1..ed1511f7 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -319,13 +319,13 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
#define _c_implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
- STC_IMP ctype##_##X \
+ STC_DEF ctype##_##X \
ctype##_##X##_with_capacity(size_t cap) { \
ctype##_##X h = ctype##_INIT; \
ctype##_##X##_reserve(&h, cap); \
return h; \
} \
- STC_IMP void \
+ STC_DEF void \
ctype##_##X##_push_n(ctype##_##X* self, const ctype##_##X##_input_t in[], size_t n) { \
for (size_t i=0; i<n; ++i) CMAP_ONLY_##ctype(ctype##_##X##_put(self, in[i].first, in[i].second)) \
CSET_ONLY_##ctype(ctype##_##X##_insert(self, in[i])) ; \
@@ -338,19 +338,19 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
for (; e != end; ++e) if (*hx++) ctype##_##X##_entry_del(e); \
} \
\
- STC_IMP void ctype##_##X##_del(ctype##_##X* self) { \
+ STC_DEF void ctype##_##X##_del(ctype##_##X* self) { \
ctype##_##X##_wipe_(self); \
c_free(self->_hashx); \
c_free(self->table); \
} \
\
- STC_IMP void ctype##_##X##_clear(ctype##_##X* self) { \
+ STC_DEF void ctype##_##X##_clear(ctype##_##X* self) { \
ctype##_##X##_wipe_(self); \
self->size = 0; \
memset(self->_hashx, 0, self->bucket_count); \
} \
\
- STC_IMP ctype##_bucket_t \
+ STC_DEF ctype##_bucket_t \
ctype##_##X##_bucket(const ctype##_##X* self, const ctype##_##X##_rawkey_t* rawKeyPtr) { \
uint32_t sx, hash = keyHashRaw(rawKeyPtr, sizeof(ctype##_##X##_rawkey_t)); \
size_t cap = self->bucket_count; \
@@ -366,7 +366,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
return b; \
} \
\
- STC_IMP ctype##_##X##_value_t* \
+ STC_DEF ctype##_##X##_value_t* \
ctype##_##X##_find(const ctype##_##X* self, RawKey rawKey) { \
if (self->size == 0) return NULL; \
ctype##_bucket_t b = ctype##_##X##_bucket(self, &rawKey); \
@@ -377,12 +377,12 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
if (self->size + 1 >= self->bucket_count * self->max_load_factor) \
ctype##_##X##_reserve(self, 5 + self->size * 3 / 2); \
} \
- STC_IMP bool \
+ STC_DEF bool \
ctype##_##X##_contains(const ctype##_##X* self, RawKey rawKey) { \
return self->size && self->_hashx[ctype##_##X##_bucket(self, &rawKey).idx]; \
} \
\
- STC_IMP ctype##_##X##_result_t \
+ STC_DEF ctype##_##X##_result_t \
ctype##_##X##_insert_key_(ctype##_##X* self, RawKey rawKey) { \
ctype##_##X##_reserve_expand(self); \
ctype##_bucket_t b = ctype##_##X##_bucket(self, &rawKey); \
@@ -395,7 +395,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
return res; \
} \
\
- STC_IMP void \
+ STC_DEF void \
ctype##_##X##_reserve(ctype##_##X* self, size_t newcap) { \
size_t oldcap = self->bucket_count; \
if (self->size > newcap) return; \
@@ -421,7 +421,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
c_free(tmp.table); \
} \
\
- STC_IMP void \
+ STC_DEF void \
ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* val) { \
size_t i = chash_entry_index(*self, val), j = i, k, cap = self->bucket_count; \
ctype##_##X##_value_t* slot = self->table; \
@@ -442,13 +442,13 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
/* https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/ */
-STC_IMP uint32_t c_default_hash16(const void *data, size_t len) {
+STC_DEF uint32_t c_default_hash16(const void *data, size_t len) {
const volatile uint16_t *key = (const uint16_t *) data;
uint64_t x = *key++ * 0xc613fc15u;
while (len -= 2) x = (*key++ + x) * 2654435769ull;
return (uint32_t) x;
}
-STC_IMP uint32_t c_default_hash32(const void* data, size_t len) {
+STC_DEF uint32_t c_default_hash32(const void* data, size_t len) {
const volatile uint32_t *key = (const uint32_t *) data;
uint64_t x = *key++ * 2654435769ull;
while (len -= 4) x = (*key++ + x) * 2654435769ull;
diff --git a/stc/cpqueue.h b/stc/cpqueue.h
index 685c4fc8..0c01c017 100644
--- a/stc/cpqueue.h
+++ b/stc/cpqueue.h
@@ -57,7 +57,7 @@
typedef ctype##_rawvalue_t cpqueue_##X##_rawvalue_t; \
typedef ctype##_input_t cpqueue_##X##_input_t; \
STC_INLINE cpqueue_##X \
- cpqueue_##X##_init() {return ctype##_init();} \
+ cpqueue_##X##_init(void) {return ctype##_init();} \
STC_INLINE size_t \
cpqueue_##X##_size(cpqueue_##X pq) {return ctype##_size(pq);} \
STC_INLINE bool \
diff --git a/stc/cqueue.h b/stc/cqueue.h
index 42c0e99e..c81b8092 100644
--- a/stc/cqueue.h
+++ b/stc/cqueue.h
@@ -65,7 +65,7 @@
typedef ctype##_rawvalue_t cqueue_##X##_rawvalue_t; \
typedef ctype##_input_t cqueue_##X##_input_t; \
STC_INLINE cqueue_##X \
- cqueue_##X##_init() {return ctype##_init();} \
+ cqueue_##X##_init(void) {return ctype##_init();} \
STC_INLINE void \
cqueue_##X##_del(cqueue_##X* self) {ctype##_del(self);} \
STC_INLINE size_t \
diff --git a/stc/crandom.h b/stc/crandom.h
index a52bbc79..326a9a20 100644
--- a/stc/crandom.h
+++ b/stc/crandom.h
@@ -138,14 +138,14 @@ STC_API double crand_normal_f64(crand_rng64_t* rng, crand_normal_f64_t* dist);
#endif
/* PRNG PCG32 https://www.pcg-random.org/download.html */
-STC_IMP crand_rng32_t crand_rng32_with_seq(uint64_t seed, uint64_t seq) {
+STC_DEF crand_rng32_t crand_rng32_with_seq(uint64_t seed, uint64_t seq) {
crand_rng32_t rng = {{0u, (seq << 1u) | 1u}}; /* inc must be odd */
crand_i32(&rng);
rng.state[0] += seed;
crand_i32(&rng);
return rng;
}
-STC_IMP uint32_t crand_i32(crand_rng32_t* rng) {
+STC_DEF uint32_t crand_i32(crand_rng32_t* rng) {
uint64_t old = rng->state[0];
rng->state[0] = old * 6364136223846793005ull + rng->state[1];
uint32_t xors = (uint32_t) (((old >> 18u) ^ old) >> 27u);
@@ -158,12 +158,12 @@ STC_IMP uint32_t crand_i32(crand_rng32_t* rng) {
/* Even faster than sfc64: updates only 192bit state. Better for parallel processing: */
/* Guarantees 2^63 unique threads with minimum 2^64 period length ~ 2^160 average period. */
/* Tested with PractRand to 8 TB output: no issues */
-STC_IMP crand_rng64_t crand_rng64_with_seq(uint64_t seed, uint64_t seq) {
+STC_DEF crand_rng64_t crand_rng64_with_seq(uint64_t seed, uint64_t seq) {
crand_rng64_t rng = {{seed, seed, seed, (seq << 1u) | 1u}}; /* increment must be odd */
for (int i = 0; i < 12; ++i) crand_i64(&rng);
return rng;
}
-STC_IMP uint64_t crand_i64(crand_rng64_t* rng) {
+STC_DEF uint64_t crand_i64(crand_rng64_t* rng) {
enum {LROT = 24, RSHIFT = 11, LSHIFT = 3};
uint64_t *s = rng->state;
const uint64_t b = s[1], result = s[0] ^ (s[2] += s[3]|1);
@@ -173,7 +173,7 @@ STC_IMP uint64_t crand_i64(crand_rng64_t* rng) {
}
/* Unbiased uniform https://github.com/lemire/fastrange */
-STC_IMP uint32_t crand_unbiased_i32(crand_rng32_t* rng, crand_uniform_i32_t* dist) {
+STC_DEF uint32_t crand_unbiased_i32(crand_rng32_t* rng, crand_uniform_i32_t* dist) {
uint32_t r = dist->range;
uint64_t m = (uint64_t) crand_i32(rng) * r;
uint32_t l = (uint32_t) m;
@@ -186,7 +186,7 @@ STC_IMP uint32_t crand_unbiased_i32(crand_rng32_t* rng, crand_uniform_i32_t* dis
}
/* Marsaglia polar method for gaussian distribution. */
-STC_IMP double crand_normal_f64(crand_rng64_t* rng, crand_normal_f64_t* dist) {
+STC_DEF double crand_normal_f64(crand_rng64_t* rng, crand_normal_f64_t* dist) {
double u1, u2, s, m;
if (dist->has_next) {
dist->has_next = false;
diff --git a/stc/cstack.h b/stc/cstack.h
index 336218f3..b23c11c3 100644
--- a/stc/cstack.h
+++ b/stc/cstack.h
@@ -54,7 +54,7 @@
typedef ctype##_rawvalue_t cstack_##X##_rawvalue_t; \
typedef ctype##_input_t cstack_##X##_input_t; \
STC_INLINE cstack_##X \
- cstack_##X##_init() {return ctype##_init();} \
+ cstack_##X##_init(void) {return ctype##_init();} \
STC_INLINE void \
cstack_##X##_del(cstack_##X* self) {ctype##_del(self);} \
STC_INLINE size_t \
diff --git a/stc/cstr.h b/stc/cstr.h
index fb824852..07164ebe 100644
--- a/stc/cstr.h
+++ b/stc/cstr.h
@@ -33,16 +33,15 @@ typedef struct cstr { char* str; } cstr_t;
typedef struct { char *val; } cstr_iter_t;
typedef char cstr_value_t;
-STC_APIV size_t _cstr_nullrep[];
-STC_APIV cstr_t cstr_INIT;
-
#define cstr_size(s) ((const size_t *) (s).str)[-2]
#define cstr_capacity(s) ((const size_t *) (s).str)[-1]
#define cstr_empty(s) (cstr_size(s) == 0)
#define cstr_NPOS ((size_t) (-1))
STC_API cstr_t
-cstr_n(const char* str, size_t len);
+cstr_init(void);
+STC_API cstr_t
+cstr_from_n(const char* str, size_t len);
STC_API cstr_t
cstr_from_fmt(const char* fmt, ...);
STC_API size_t
@@ -69,9 +68,6 @@ c_strnstr(const char* s, const char* needle, size_t n);
/* gives true string capacity: 7, 23, 39, ... */
#define _cstr_cap(size) ((((size) + 24) >> 4) * 16 - 9)
-STC_INLINE cstr_t
-cstr_init() {return cstr_INIT;}
-
STC_INLINE void
cstr_del(cstr_t* self) {
if (cstr_capacity(*self))
@@ -80,24 +76,24 @@ cstr_del(cstr_t* self) {
STC_INLINE cstr_t
cstr_with_capacity(size_t cap) {
- cstr_t s = cstr_INIT;
+ cstr_t s = cstr_init();
cstr_reserve(&s, cap);
return s;
}
STC_INLINE cstr_t
cstr_with_size(size_t len, char fill) {
- cstr_t s = cstr_INIT;
+ cstr_t s = cstr_init();
cstr_resize(&s, len, fill);
return s;
}
STC_INLINE cstr_t
cstr_from(const char* str) {
- return cstr_n(str, strlen(str));
+ return cstr_from_n(str, strlen(str));
}
STC_INLINE cstr_t
cstr_clone(cstr_t s) {
- return cstr_n(s.str, cstr_size(s));
+ return cstr_from_n(s.str, cstr_size(s));
}
STC_INLINE void
@@ -134,7 +130,7 @@ cstr_take(cstr_t* self, cstr_t s) {
STC_INLINE cstr_t
cstr_move(cstr_t* self) {
cstr_t tmp = *self;
- *self = cstr_INIT;
+ *self = cstr_init();
return tmp;
}
@@ -215,10 +211,14 @@ STC_INLINE uint32_t cstr_hash_raw(const char* const* spp, size_t ignored) {
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-STC_IMPV size_t _cstr_nullrep[] = {0, 0, 0};
-STC_IMPV cstr_t cstr_INIT = {(char* ) &_cstr_nullrep[2]};
+STC_DEF cstr_t
+cstr_init() {
+ static size_t nullrep[3] = {0, 0, 0};
+ static cstr_t init = {(char* ) &nullrep[2]};
+ return init;
+}
-STC_IMP size_t
+STC_DEF size_t
cstr_reserve(cstr_t* self, size_t cap) {
size_t len = cstr_size(*self), oldcap = cstr_capacity(*self);
if (cap > oldcap) {
@@ -230,7 +230,7 @@ cstr_reserve(cstr_t* self, size_t cap) {
return oldcap;
}
-STC_IMP void
+STC_DEF void
cstr_resize(cstr_t* self, size_t len, char fill) {
size_t n = cstr_size(*self);
cstr_reserve(self, len);
@@ -238,9 +238,9 @@ cstr_resize(cstr_t* self, size_t len, char fill) {
if (len | n) self->str[_cstr_size(*self) = len] = '\0';
}
-STC_IMP cstr_t
-cstr_n(const char* str, size_t len) {
- if (len == 0) return cstr_INIT;
+STC_DEF cstr_t
+cstr_from_n(const char* str, size_t len) {
+ if (len == 0) return cstr_init();
size_t *rep = (size_t *) c_malloc(_cstr_mem(len));
cstr_t s = {(char *) memcpy(rep + 2, str, len)};
s.str[rep[0] = len] = '\0';
@@ -248,7 +248,7 @@ cstr_n(const char* str, size_t len) {
return s;
}
-STC_IMP cstr_t
+STC_DEF cstr_t
cstr_from_fmt(const char* fmt, ...) {
#if defined(__clang__)
# pragma clang diagnostic push
@@ -257,7 +257,7 @@ cstr_from_fmt(const char* fmt, ...) {
# pragma warning(push)
# pragma warning(disable: 4996)
#endif
- cstr_t tmp = cstr_INIT;
+ cstr_t tmp = cstr_init();
va_list args, args2;
va_start(args, fmt);
va_copy(args2, args);
@@ -277,7 +277,7 @@ cstr_from_fmt(const char* fmt, ...) {
#endif
}
-STC_IMP cstr_t*
+STC_DEF cstr_t*
cstr_assign_n(cstr_t* self, const char* str, size_t len) {
if (len || cstr_capacity(*self)) {
cstr_reserve(self, len);
@@ -287,7 +287,7 @@ cstr_assign_n(cstr_t* self, const char* str, size_t len) {
return self;
}
-STC_IMP cstr_t*
+STC_DEF cstr_t*
cstr_append_n(cstr_t* self, const char* str, size_t len) {
if (len) {
size_t oldlen = cstr_size(*self), newlen = oldlen + len;
@@ -313,7 +313,7 @@ STC_INLINE void _cstr_internal_move(cstr_t* self, size_t pos1, size_t pos2) {
self->str[_cstr_size(*self) = newlen] = '\0';
}
-STC_IMP void
+STC_DEF void
cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n) {
c_withbuffer (char, xstr, n) {
memcpy(xstr, str, n);
@@ -322,7 +322,7 @@ cstr_replace_n(cstr_t* self, size_t pos, size_t len, const char* str, size_t n)
}
}
-STC_IMP void
+STC_DEF void
cstr_erase(cstr_t* self, size_t pos, size_t n) {
size_t len = cstr_size(*self);
if (len) {
@@ -331,7 +331,7 @@ cstr_erase(cstr_t* self, size_t pos, size_t n) {
}
}
-STC_IMP bool
+STC_DEF bool
cstr_getdelim(cstr_t *self, int delim, FILE *stream) {
size_t pos = 0, cap = cstr_capacity(*self);
for (;;) {
@@ -350,7 +350,7 @@ cstr_getdelim(cstr_t *self, int delim, FILE *stream) {
}
}
-STC_IMP char*
+STC_DEF char*
c_strnstr(const char* x, const char* needle, size_t n) {
ptrdiff_t sum = 0;
const char *y = x, *p = needle, *q = needle + n;
diff --git a/stc/cvec.h b/stc/cvec.h
index d9f1abb4..dcd44294 100644
--- a/stc/cvec.h
+++ b/stc/cvec.h
@@ -194,27 +194,27 @@
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
#define _c_implement_cvec_7(X, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw) \
\
- STC_IMP void \
+ STC_DEF void \
cvec_##X##_push_n(cvec_##X *self, const cvec_##X##_input_t in[], size_t size) { \
cvec_##X##_reserve(self, cvec_size(*self) + size); \
_cvec_size(self) += size; \
for (size_t i=0; i<size; ++i) self->data[i] = valueFromRaw(in[i]); \
} \
\
- STC_IMP void \
+ STC_DEF void \
cvec_##X##_clear(cvec_##X* self) { \
cvec_##X##_value_t* p = self->data; if (p) { \
for (cvec_##X##_value_t* q = p + _cvec_size(self); p != q; ++p) valueDestroy(p); \
_cvec_size(self) = 0; \
} \
} \
- STC_IMP void \
+ STC_DEF void \
cvec_##X##_del(cvec_##X* self) { \
cvec_##X##_clear(self); \
if (self->data) c_free(_cvec_alloced(self->data)); \
} \
\
- STC_IMP void \
+ STC_DEF void \
cvec_##X##_reserve(cvec_##X* self, size_t cap) { \
size_t len = cvec_size(*self); \
if (cap >= len) { \
@@ -224,14 +224,14 @@
rep[1] = cap; \
} \
} \
- STC_IMP void \
+ STC_DEF void \
cvec_##X##_resize(cvec_##X* self, size_t size, Value null_val) { \
cvec_##X##_reserve(self, size); \
for (size_t i=cvec_size(*self); i<size; ++i) self->data[i] = null_val; \
if (self->data) _cvec_size(self) = size; \
} \
\
- STC_IMP void \
+ STC_DEF void \
cvec_##X##_push_back(cvec_##X* self, Value value) { \
size_t len = cvec_size(*self); \
if (len == cvec_capacity(*self)) \
@@ -239,7 +239,7 @@
self->data[_cvec_size(self)++] = value; \
} \
\
- STC_IMP cvec_##X##_iter_t \
+ STC_DEF cvec_##X##_iter_t \
cvec_##X##_insert_range_p(cvec_##X* self, cvec_##X##_value_t* pos, cvec_##X##_value_t* first, cvec_##X##_value_t* finish) { \
size_t len = finish - first, idx = pos - self->data, size = cvec_size(*self); \
c_withbuffer (cvec_##X##_value_t, buf, len) { \
@@ -255,7 +255,7 @@
cvec_##X##_iter_t it = {pos}; return it; \
} \
\
- STC_IMP cvec_##X##_iter_t \
+ STC_DEF cvec_##X##_iter_t \
cvec_##X##_erase_range_p(cvec_##X* self, cvec_##X##_value_t* first, cvec_##X##_value_t* finish) { \
intptr_t len = finish - first; \
if (len > 0) { \
@@ -267,7 +267,7 @@
cvec_##X##_iter_t it = {first}; return it; \
} \
\
- STC_IMP cvec_##X##_iter_t \
+ STC_DEF cvec_##X##_iter_t \
cvec_##X##_find_in_range(const cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish, RawValue rawValue) { \
for (; first.val != finish.val; cvec_##X##_next(&first)) { \
RawValue r = valueToRaw(first.val); \
@@ -275,12 +275,12 @@
} \
return cvec_##X##_end(self); \
} \
- STC_IMP cvec_##X##_iter_t \
+ STC_DEF cvec_##X##_iter_t \
cvec_##X##_find(const cvec_##X* self, RawValue rawValue) { \
return cvec_##X##_find_in_range(self, cvec_##X##_begin(self), cvec_##X##_end(self), rawValue); \
} \
\
- STC_IMP int \
+ STC_DEF int \
cvec_##X##_value_compare(const cvec_##X##_value_t* x, const cvec_##X##_value_t* y) { \
RawValue rx = valueToRaw(x); \
RawValue ry = valueToRaw(y); \