diff options
| author | Tyge Løvset <[email protected]> | 2022-01-02 14:18:22 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-01-02 14:18:22 +0100 |
| commit | 9826f52e385e1ec019c63fd483f1c8acccf4a360 (patch) | |
| tree | 415a95e035b35995781392f04cf0c0bcb986b41c /include/stc | |
| parent | 8134d0f62ebc659741131eb79cec4fdcf5f774f7 (diff) | |
| download | STC-modified-9826f52e385e1ec019c63fd483f1c8acccf4a360.tar.gz STC-modified-9826f52e385e1ec019c63fd483f1c8acccf4a360.zip | |
Simplified and improved linkage configuration. Reorganized crandom.h a bit.
May define "i_opt c_shared", or "i_opt c_static" to specify individual container linkage, based on if STC_HEADER is defined,
i.e static linkage is default, STC_HEADER defined makes shared symbols default.
Diffstat (limited to 'include/stc')
| -rw-r--r-- | include/stc/alt/clist.h | 2 | ||||
| -rw-r--r-- | include/stc/alt/csmap.h | 2 | ||||
| -rw-r--r-- | include/stc/alt/cstr.h | 4 | ||||
| -rw-r--r-- | include/stc/carc.h | 2 | ||||
| -rw-r--r-- | include/stc/carr2.h | 5 | ||||
| -rw-r--r-- | include/stc/carr3.h | 5 | ||||
| -rw-r--r-- | include/stc/cbits.h | 7 | ||||
| -rw-r--r-- | include/stc/cbox.h | 2 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 21 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 5 | ||||
| -rw-r--r-- | include/stc/clist.h | 16 | ||||
| -rw-r--r-- | include/stc/cmap.h | 12 | ||||
| -rw-r--r-- | include/stc/cpque.h | 6 | ||||
| -rw-r--r-- | include/stc/crandom.h | 90 | ||||
| -rw-r--r-- | include/stc/csmap.h | 8 | ||||
| -rw-r--r-- | include/stc/cstack.h | 2 | ||||
| -rw-r--r-- | include/stc/cstr.h | 25 | ||||
| -rw-r--r-- | include/stc/csview.h | 4 | ||||
| -rw-r--r-- | include/stc/cvec.h | 12 |
19 files changed, 119 insertions, 111 deletions
diff --git a/include/stc/alt/clist.h b/include/stc/alt/clist.h index 7530ef5b..52f4ab5d 100644 --- a/include/stc/alt/clist.h +++ b/include/stc/alt/clist.h @@ -148,7 +148,7 @@ STC_API size_t _clist_count(const clist_VOID* self); /* -------------------------- IMPLEMENTATION ------------------------- */
-#if !defined(STC_SHARED) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
#define _c_implement_clist(_cx_self, i_val, i_cmp, i_valdrop, i_valfrom, i_valto, i_valraw) \
\
STC_DEF _cx_self \
diff --git a/include/stc/alt/csmap.h b/include/stc/alt/csmap.h index 0f5b59cc..07117c56 100644 --- a/include/stc/alt/csmap.h +++ b/include/stc/alt/csmap.h @@ -197,7 +197,7 @@ int main(void) { /* -------------------------- IMPLEMENTATION ------------------------- */
-#if !defined(STC_SHARED) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
_c_aatree_types(csmap_SENTINEL, csmap_, int, int);
_c_aatree_complete_types(csmap_SENTINEL, csmap_);
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index 8a2c2bd7..1a2fbe8b 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -261,8 +261,7 @@ STC_INLINE bool cstr_getline(cstr *self, FILE *fp) { }
/* -------------------------- IMPLEMENTATION ------------------------- */
-
-#if !defined(STC_SHARED) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
STC_DEF void cstr_internal_move_(cstr* self, size_t pos1, size_t pos2) {
if (pos1 == pos2)
@@ -400,3 +399,4 @@ STC_DEF void cstr_erase_n(cstr* self, size_t pos, size_t n) { #endif
#endif
+#undef i_opt
\ No newline at end of file diff --git a/include/stc/carc.h b/include/stc/carc.h index b4e2e435..4c92c72e 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -47,10 +47,10 @@ int main() { c_drop(carc_person, &p, &q);
}
*/
+#include "ccommon.h"
#ifndef CARC_H_INCLUDED
#define CARC_H_INCLUDED
-#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
diff --git a/include/stc/carr2.h b/include/stc/carr2.h index 9d49253a..4864881b 100644 --- a/include/stc/carr2.h +++ b/include/stc/carr2.h @@ -20,9 +20,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include "ccommon.h" + #ifndef CARR2_H_INCLUDED #define CARR2_H_INCLUDED -#include "ccommon.h" #include "forward.h" #include <stdlib.h> #endif @@ -97,7 +98,7 @@ STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } /* -------------------------- IMPLEMENTATION ------------------------- */ -#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION) +#if defined(_i_implement) STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, _cx_value* block) { _cx_self _arr = {c_alloc_n(_cx_value*, xdim), xdim, ydim}; diff --git a/include/stc/carr3.h b/include/stc/carr3.h index 957cda81..ef5dc303 100644 --- a/include/stc/carr3.h +++ b/include/stc/carr3.h @@ -20,9 +20,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#include "ccommon.h" + #ifndef CARR3_H_INCLUDED #define CARR3_H_INCLUDED -#include "ccommon.h" #include "forward.h" #include <stdlib.h> #endif @@ -101,7 +102,7 @@ STC_INLINE void _cx_memb(_next)(_cx_iter* it) { ++it->ref; } /* -------------------------- IMPLEMENTATION ------------------------- */ -#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION) +#if defined(_i_implement) STC_DEF _cx_self _cx_memb(_with_storage)(size_t xdim, size_t ydim, size_t zdim, _cx_value* block) { _cx_self _arr = {c_alloc_n(_cx_value**, xdim*(ydim + 1)), xdim, ydim, zdim}; diff --git a/include/stc/cbits.h b/include/stc/cbits.h index b4ff287d..f99867e9 100644 --- a/include/stc/cbits.h +++ b/include/stc/cbits.h @@ -20,9 +20,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include "ccommon.h"
+
#ifndef CBITS_H_INCLUDED
#define CBITS_H_INCLUDED
-
/*
Similar to boost::dynamic_bitset / std::bitset
@@ -54,7 +55,6 @@ int main() { */
#include <stdlib.h>
#include <string.h>
-#include "ccommon.h"
struct cbits {
uint64_t *data64;
@@ -168,7 +168,7 @@ STC_INLINE void cbits_xor(cbits *self, cbits other) { }
#endif
-#if !defined(STC_SHARED) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
STC_DEF cbits* cbits_copy(cbits* self, cbits other) {
if (self->data64 == other.data64) return self;
@@ -241,3 +241,4 @@ STC_DEF bool cbits_disjoint(cbits s, cbits other) { _cbits_SETOP(&, 0); } #endif
#endif
+#undef i_opt
\ No newline at end of file diff --git a/include/stc/cbox.h b/include/stc/cbox.h index 7ed0d641..c79839b6 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -57,10 +57,10 @@ int main() { }
}
*/
+#include "ccommon.h"
#ifndef CBOX_H_INCLUDED
#define CBOX_H_INCLUDED
-#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 1d760348..1c351c05 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -101,6 +101,7 @@ typedef const char c_strlit[]; #define c_no_clone 4
#define c_no_cmp 8
#define c_static 16
+#define c_shared 32
/* Generic algorithms */
@@ -212,23 +213,21 @@ STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { #define c_umul128(a, b, lo, hi) \
asm("mulq %3" : "=a"(*(lo)), "=d"(*(hi)) : "a"(a), "rm"(b))
#endif
-#endif
+#endif // CCOMMON_H_INCLUDED
#undef STC_API
#undef STC_DEF
-#undef STC_LIBRARY_ONLY
-#undef STC_STATIC_ONLY
-#ifdef STC_HEADER // [deprecated]
-# define STC_SHARED
-#endif
-#if !c_option(c_static) && (defined(STC_SHARED) || defined(STC_IMPLEMENTATION))
+#undef _i_static
+#undef _i_implement
+
+#if (c_option(c_shared) || defined(STC_HEADER) || defined(STC_IMPLEMENTATION)) && !c_option(c_static)
# define STC_API extern
# define STC_DEF
-# define STC_LIBRARY_ONLY(...) __VA_ARGS__
-# define STC_STATIC_ONLY(...)
#else
+# define _i_static
# define STC_API static inline
# define STC_DEF static inline
-# define STC_LIBRARY_ONLY(...)
-# define STC_STATIC_ONLY(...) __VA_ARGS__
+#endif
+#if defined(STC_IMPLEMENTATION) ^ defined(_i_static)
+# define _i_implement
#endif
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index 2de4f69b..5eae848b 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -20,8 +20,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifndef CDEQ_H_INCLUDED
#include "ccommon.h"
+
+#ifndef CDEQ_H_INCLUDED
#include "forward.h"
#include <stdlib.h>
#include <string.h>
@@ -211,7 +212,7 @@ _cx_memb(_sort)(_cx_self* self) { #endif // _i_queue
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
#ifndef CDEQ_H_INCLUDED
static struct cdeq_rep _cdeq_sentinel = {0, 0};
diff --git a/include/stc/clist.h b/include/stc/clist.h index b9a3df24..d53c35c8 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -51,9 +51,9 @@ }
}
*/
+#include "ccommon.h"
#ifndef CLIST_H_INCLUDED
-#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
@@ -75,7 +75,6 @@ _c_clist_complete_types(clist_VOID, dummy); else entry->next = entry; \
entry->value = val
// +: set self->last based on node
-
#endif // CLIST_H_INCLUDED
#ifndef _i_prefix
@@ -184,8 +183,7 @@ _cx_memb(_get_mut)(_cx_self* self, i_valraw val) { #endif
// -------------------------- IMPLEMENTATION -------------------------
-
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
#if !c_option(c_no_clone)
STC_DEF _cx_self
@@ -330,10 +328,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { }
#endif // !c_no_cmp
-#endif // TEMPLATE IMPLEMENTATION
-
-#if !defined(CLIST_H_INCLUDED) && \
- (!defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION))
+#ifndef CLIST_H_INCLUDED
STC_DEF size_t
_clist_count(const clist_VOID* self) {
@@ -395,6 +390,7 @@ _clist_mergesort(clist_VOID_node *list, int (*cmp)(const clist_VOID_node*, const }
}
#endif // !c_no_cmp
-#endif // NON-TEMPLATE IMPLEMENTATION
-#include "template.h"
+#endif // !CLIST_H_INCLUDED
+#endif // _i_implement
#define CLIST_H_INCLUDED
+#include "template.h"
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 2cd42bc6..51f606a5 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -47,13 +47,12 @@ int main(void) { }
}
*/
+#include "ccommon.h"
#ifndef CMAP_H_INCLUDED
-#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
-
#define _cmap_inits {NULL, NULL, 0, 0, 0.85f}
typedef struct { MAP_SIZE_T idx; uint_fast8_t hx; } chash_bucket_t;
#endif // CMAP_H_INCLUDED
@@ -141,6 +140,7 @@ _cx_memb(_value_clone)(_cx_value _val) { _i_MAP_ONLY( _val.second = i_valfrom(i_valto(&_val.second)); )
return _val;
}
+
#if !defined _i_no_raw
STC_INLINE _cx_result
_cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) {
@@ -230,8 +230,7 @@ _cx_memb(_erase_at)(_cx_self* self, _cx_iter it) { }
/* -------------------------- IMPLEMENTATION ------------------------- */
-
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
#ifndef CMAP_H_INCLUDED
//STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n)
@@ -274,6 +273,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { else { i_keydrop(&_key); i_valdrop(&_res.ref->second); }
_res.ref->second = _mapped; return _res;
}
+
#if !c_option(c_no_clone) && !defined _i_no_raw
STC_DEF _cx_result
_cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) {
@@ -379,10 +379,10 @@ _cx_memb(_erase_entry)(_cx_self* self, _cx_value* _val) { --self->size;
}
-#endif // TEMPLATED IMPLEMENTATION
+#endif // _i_implement
#undef _i_isset
#undef _i_keyref
#undef _i_MAP_ONLY
#undef _i_SET_ONLY
-#include "template.h"
#define CMAP_H_INCLUDED
+#include "template.h"
diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 2347fc55..91d2ef04 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -20,10 +20,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include "ccommon.h"
#ifndef CPQUE_H_INCLUDED
#include <stdlib.h>
-#include "ccommon.h"
#include "forward.h"
#endif
@@ -105,7 +105,7 @@ STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) #endif
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
STC_DEF void
_cx_memb(_sift_down_)(_cx_value* arr, const size_t idx, const size_t n) {
@@ -153,5 +153,5 @@ _cx_memb(_push)(_cx_self* self, _cx_value value) { }
#endif
-#include "template.h"
#define CPQUE_H_INCLUDED
+#include "template.h"
diff --git a/include/stc/crandom.h b/include/stc/crandom.h index 2861f6cd..887e5f51 100644 --- a/include/stc/crandom.h +++ b/include/stc/crandom.h @@ -20,9 +20,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include "ccommon.h"
+
#ifndef CRANDOM_H_INCLUDED
#define CRANDOM_H_INCLUDED
-
/*
// crandom: Pseudo-random number generator
#include "stc/crandom.h"
@@ -39,7 +40,6 @@ int main() { double xn = stc64_normalf(&rng, &dist3);
}
*/
-#include "ccommon.h"
#include <string.h>
#include <math.h>
@@ -62,12 +62,15 @@ typedef struct stc64_normalf { double mean, stddev, next; unsigned has_next; } s */
/* Global STC64 PRNG */
-STC_API void stc64_srandom(uint64_t seed);
-STC_API uint64_t stc64_random(void);
+STC_API void stc64_srandom(uint64_t seed);
+STC_API uint64_t stc64_random(void);
+
+STC_API uint64_t stc64_rand(stc64_t* rng);
+STC_API uint32_t stc32_rand(stc32_t* rng);
/* Init with sequence number */
-STC_API stc64_t stc64_with_seq(uint64_t seed, uint64_t seq);
-STC_API stc32_t stc32_with_seq(uint32_t seed, uint32_t seq);
+STC_API stc64_t stc64_with_seq(uint64_t seed, uint64_t seq);
+STC_API stc32_t stc32_with_seq(uint32_t seed, uint32_t seq);
/* Int uniform distributed RNG, range [low, high]. */
STC_API stc64_uniform_t stc64_uniform_init(int64_t low, int64_t high);
@@ -80,6 +83,9 @@ STC_API stc64_uniformf_t stc64_uniformf_init(double low, double high); STC_API stc64_normalf_t stc64_normalf_init(double mean, double stddev);
STC_API double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist);
+/* Unbiased bounded uniform distribution. */
+STC_API int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* d);
+
STC_INLINE stc64_t stc64_init(uint64_t seed) {
return stc64_with_seq(seed, seed + 0x3504f333d3aa0b37);
}
@@ -88,24 +94,6 @@ STC_INLINE stc32_t stc32_init(uint32_t seed) { return stc32_with_seq(seed, seed + 0xd3aa0b37);
}
-STC_INLINE uint64_t stc64_rand(stc64_t* rng) {
- uint64_t *s = rng->state; enum {LR=24, RS=11, LS=3};
- const uint64_t result = (s[0] ^ (s[3] += s[4])) + s[1];
- s[0] = s[1] ^ (s[1] >> RS);
- s[1] = s[2] + (s[2] << LS);
- s[2] = ((s[2] << LR) | (s[2] >> (64 - LR))) + result;
- return result;
-}
-
-STC_INLINE uint32_t stc32_rand(stc32_t* rng) {
- uint32_t *s = rng->state; enum {LR=21, RS=9, LS=3};
- const uint32_t result = (s[0] ^ (s[3] += s[4])) + s[1];
- s[0] = s[1] ^ (s[1] >> RS);
- s[1] = s[2] + (s[2] << LS);
- s[2] = ((s[2] << LR) | (s[2] >> (32 - LR))) + result;
- return result;
-}
-
/* Float64 random number in range [0.0, 1.0). */
STC_INLINE double stc64_randf(stc64_t* rng) {
union {uint64_t i; double f;} u = {0x3FF0000000000000ull | (stc64_rand(rng) >> 12)};
@@ -117,22 +105,6 @@ STC_INLINE double stc64_uniformf(stc64_t* rng, stc64_uniformf_t* dist) { return stc64_randf(rng)*dist->range + dist->lower;
}
-/* Unbiased bounded uniform distribution. */
-STC_INLINE int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* d) {
-#ifdef c_umul128
- uint64_t lo, hi;
- do { c_umul128(stc64_rand(rng), d->range, &lo, &hi); } while (lo < d->threshold);
- return d->lower + hi;
-#else
- uint64_t x, r;
- do {
- x = stc64_rand(rng);
- r = x % d->range;
- } while (x - r > -d->range);
- return d->lower + r;
-#endif
-}
-
STC_INLINE int32_t stc32_uniform(stc32_t* rng, stc32_uniform_t* d) {
uint64_t val;
do { val = stc32_rand(rng) * (uint64_t)d->range; } while ((uint32_t)val < d->threshold);
@@ -140,8 +112,7 @@ STC_INLINE int32_t stc32_uniform(stc32_t* rng, stc32_uniform_t* d) { }
/* -------------------------- IMPLEMENTATION ------------------------- */
-
-#if !defined(STC_SHARED) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
/* Global random() */
static stc64_t stc64_global = {{
@@ -191,6 +162,39 @@ STC_DEF stc32_uniform_t stc32_uniform_init(int32_t low, int32_t high) { #pragma warning(default: 4146)
#endif
+STC_DEF uint64_t stc64_rand(stc64_t* rng) {
+ uint64_t *s = rng->state; enum {LR=24, RS=11, LS=3};
+ const uint64_t result = (s[0] ^ (s[3] += s[4])) + s[1];
+ s[0] = s[1] ^ (s[1] >> RS);
+ s[1] = s[2] + (s[2] << LS);
+ s[2] = ((s[2] << LR) | (s[2] >> (64 - LR))) + result;
+ return result;
+}
+
+STC_DEF uint32_t stc32_rand(stc32_t* rng) {
+ uint32_t *s = rng->state; enum {LR=21, RS=9, LS=3};
+ const uint32_t result = (s[0] ^ (s[3] += s[4])) + s[1];
+ s[0] = s[1] ^ (s[1] >> RS);
+ s[1] = s[2] + (s[2] << LS);
+ s[2] = ((s[2] << LR) | (s[2] >> (32 - LR))) + result;
+ return result;
+}
+
+STC_DEF int64_t stc64_uniform(stc64_t* rng, stc64_uniform_t* d) {
+#ifdef c_umul128
+ uint64_t lo, hi;
+ do { c_umul128(stc64_rand(rng), d->range, &lo, &hi); } while (lo < d->threshold);
+ return d->lower + hi;
+#else
+ uint64_t x, r;
+ do {
+ x = stc64_rand(rng);
+ r = x % d->range;
+ } while (x - r > -d->range);
+ return d->lower + r;
+#endif
+}
+
/* Init uniform distributed float64 RNG, range [low, high). */
STC_DEF stc64_uniformf_t stc64_uniformf_init(double low, double high) {
return c_make(stc64_uniformf_t){low, high - low};
@@ -214,6 +218,6 @@ STC_DEF double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist) { dist->next = u2 * m;
return (u1 * m) * dist->stddev + dist->mean;
}
-
#endif
#endif
+#undef i_opt
\ No newline at end of file diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 0d03f176..5bbc6ba4 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -48,9 +48,9 @@ int main(void) { }
}
*/
+#include "ccommon.h"
#ifndef CSMAP_H_INCLUDED
-#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
@@ -223,7 +223,7 @@ _cx_memb(_advance)(_cx_iter it, size_t n) { }
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
#ifndef CSMAP_H_INCLUDED
static struct csmap_rep _csmap_sentinel = {0, 0, 0, 0, 0};
@@ -511,10 +511,10 @@ _cx_memb(_drop)(_cx_self* self) { }
}
-#endif // IMPLEMENTATION
+#endif // _i_implement
#undef _i_isset
#undef _i_keyref
#undef _i_MAP_ONLY
#undef _i_SET_ONLY
-#include "template.h"
#define CSMAP_H_INCLUDED
+#include "template.h"
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 5999441e..bdf6090b 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -20,11 +20,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include "ccommon.h"
#ifndef CSTACK_H_INCLUDED
#define CSTACK_H_INCLUDED
#include <stdlib.h>
-#include "ccommon.h"
#include "forward.h"
#endif // CSTACK_H_INCLUDED
diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 67bbf56c..8c87cb5a 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -20,10 +20,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+#include "ccommon.h"
+
#ifndef CSTR_H_INCLUDED
#define CSTR_H_INCLUDED
-#include "ccommon.h"
#include <stdlib.h> /* malloc */
#include <string.h>
#include <stdarg.h>
@@ -33,14 +34,16 @@ typedef struct cstr { char* str; } cstr;
typedef struct cstr_iter { char *ref; } cstr_iter;
typedef char cstr_value;
-
-#define cstr_npos (SIZE_MAX >> 1)
-STC_LIBRARY_ONLY( extern const cstr cstr_null; )
+#define cstr_npos (SIZE_MAX >> 1)
typedef struct { size_t size, cap; char str[sizeof(size_t)]; } _cstr_rep_t;
#define _cstr_rep(self) c_container_of((self)->str, _cstr_rep_t, str)
-STC_STATIC_ONLY( static _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
- static const cstr cstr_null = {_cstr_nullrep.str}; )
+#if defined(_i_static)
+ static _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
+ static const cstr cstr_null = {_cstr_nullrep.str};
+#else
+ extern const cstr cstr_null;
+#endif
/* optimal memory: based on malloc_usable_size() sequence: 24, 40, 56, ... */
#define _cstr_opt_mem(cap) ((((offsetof(_cstr_rep_t, str) + (cap) + 8)>>4)<<4) + 8)
/* optimal string capacity: 7, 23, 39, ... */
@@ -172,11 +175,12 @@ cstr_ends_with(cstr s, const char* sub) { #define cstr_hash(xp, dummy) c_strhash((xp)->str)
/* -------------------------- IMPLEMENTATION ------------------------- */
+#if defined(_i_implement)
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
-
-STC_LIBRARY_ONLY( static _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
- const cstr cstr_null = {_cstr_nullrep.str}; )
+#if !defined(_i_static)
+ static _cstr_rep_t _cstr_nullrep = {0, 0, {0}};
+ const cstr cstr_null = {_cstr_nullrep.str}; )
+#endif
STC_DEF size_t
cstr_reserve(cstr* self, const size_t cap) {
@@ -386,3 +390,4 @@ c_strnstrn(const char *s, const char *needle, size_t slen, const size_t nlen) { #endif
#endif
+#undef i_opt
\ No newline at end of file diff --git a/include/stc/csview.h b/include/stc/csview.h index 2536c274..e1f82272 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -122,8 +122,7 @@ STC_INLINE int csview_cmp(const csview* x, const csview* y) { #define csview_eq(xp, yp) (!csview_cmp(xp, yp))
/* -------------------------- IMPLEMENTATION ------------------------- */
-
-#if !defined(STC_SHARED) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
STC_DEF csview
csview_substr(csview sv, intptr_t pos, size_t n) {
@@ -150,3 +149,4 @@ csview_token(csview sv, csview sep, size_t* start) { #endif
#endif
+#undef i_opt
\ No newline at end of file diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 4bd1cd23..41415419 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -57,9 +57,9 @@ int main() { cvec_str_drop(&svec);
}
*/
+#include "ccommon.h"
#ifndef CVEC_H_INCLUDED
-#include "ccommon.h"
#include "forward.h"
#include <stdlib.h>
#include <string.h>
@@ -233,7 +233,7 @@ _cx_memb(_sort)(_cx_self* self) { }
#endif // !c_no_cmp
/* -------------------------- IMPLEMENTATION ------------------------- */
-#if !defined(STC_SHARED) || c_option(c_static) || defined(STC_IMPLEMENTATION)
+#if defined(_i_implement)
#ifndef CVEC_H_INCLUDED
static struct cvec_rep _cvec_sentinel = {0, 0};
@@ -358,8 +358,8 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1);
return it;
}
-#endif
-#endif
+#endif // !_i_no_raw
+#endif // !c_no_clone
#if !c_option(c_no_cmp)
@@ -392,6 +392,6 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { return i_cmp(&rx, &ry);
}
#endif // !c_no_cmp
-#endif
-#include "template.h"
+#endif // _i_implement
#define CVEC_H_INCLUDED
+#include "template.h"
|
