Skip to content

Commit

Permalink
Reverted linkage selection to work as before: i_static, i_implement.
Browse files Browse the repository at this point in the history
  • Loading branch information
tylov committed Jan 8, 2025
1 parent 6b6e7bd commit 0dcdb1a
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 44 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ distclean:
lib: $(LIB_PATH)

$(LIB_PATH): $(LIB_OBJS)
@printf "\r\e[2K%s\n" "$(AR_RCS) $@"
@printf "\r\e[2K%s" "$(AR_RCS) $@"
@$(AR_RCS) $@ $(LIB_OBJS)
# @echo ""

$(OBJ_DIR)/%.o: %.c
@$(MKDIR_P) $(@D)
Expand All @@ -85,7 +84,7 @@ $(OBJ_DIR)/%$(DOTEXE): %.c $(LIB_PATH)
@$(CC) -o $@ $(CFLAGS) -s $< $(LDFLAGS) -L$(BUILDDIR) -l$(LIB_NAME)

$(TEST_EXE): $(TEST_OBJS)
@printf "\r\e[2K%s" "$(CC) -o $@ $(notdir $(TEST_OBJS))"
@printf "\r\e[2K%s" "$(CC) -o $@"
@$(CC) -o $@ $(TEST_OBJS) -s $(LDFLAGS) -L$(BUILDDIR) -l$(LIB_NAME)


Expand Down
45 changes: 18 additions & 27 deletions include/stc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,19 @@ typedef const char* cstr_raw;

// General functions

// substring in substring?
char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen);

// hashing
size_t c_basehash_n(const void* key, isize len);
STC_INLINE size_t c_basehash_n(const void* key, isize len) {
size_t block = 0, hash = 0x811c9dc5;
const uint8_t* msg = (const uint8_t*)key;
while (len >= c_sizeof(size_t)) {
memcpy(&block, msg, sizeof(size_t));
hash = (hash ^ block) * (size_t)0x89bb179901000193;
msg += c_sizeof(size_t);
len -= c_sizeof(size_t);
}
c_memcpy(&block, msg, len);
hash = (hash ^ block) * (size_t)0xb0340f4501000193;
return hash ^ (hash >> 3);
}

STC_INLINE size_t c_hash_n(const void* key, isize len) {
uint64_t b8; uint32_t b4;
Expand All @@ -255,12 +263,13 @@ STC_INLINE size_t c_hash_n(const void* key, isize len) {
STC_INLINE size_t c_hash_str(const char *str)
{ return c_basehash_n(str, c_strlen(str)); }

#define c_hash_mix(...) /* non-commutative hash combine! */ \
_chash_mix(c_make_array(size_t, {__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))

STC_INLINE size_t _chash_mix(size_t h[], int n) {
for (int i = 1; i < n; ++i) h[0] += h[0] ^ h[i];
return h[0];
}
#define c_hash_mix(...) /* non-commutative hash combine! */ \
_chash_mix(c_make_array(size_t, {__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))

// generic typesafe swap
#define c_swap(xp, yp) do { \
Expand All @@ -283,12 +292,8 @@ STC_INLINE isize c_next_pow2(isize n) {
#endif
return n + 1;
}
#endif // STC_COMMON_H_INCLUDED

#if !defined STC_COMMON_C_INCLUDED && defined STC_IMPLEMENT
#define STC_COMMON_C_INCLUDED

char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen) {
STC_INLINE char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen) {
if (nlen == 0) return (char *)str;
if (nlen > slen) return NULL;
slen -= nlen;
Expand All @@ -299,18 +304,4 @@ char* c_strnstrn(const char *str, isize slen, const char *needle, isize nlen) {
} while (slen--);
return NULL;
}

size_t c_basehash_n(const void* key, isize len) {
size_t block = 0, hash = 0x811c9dc5;
const uint8_t* msg = (const uint8_t*)key;
while (len >= c_sizeof(size_t)) {
memcpy(&block, msg, sizeof(size_t));
hash = (hash ^ block) * (size_t)0x89bb179901000193;
msg += c_sizeof(size_t);
len -= c_sizeof(size_t);
}
c_memcpy(&block, msg, len);
hash = (hash ^ block) * (size_t)0xb0340f4501000193;
return hash ^ (hash >> 3);
}
#endif // STC_COMMON_C_INCLUDED
#endif // STC_COMMON_H_INCLUDED
2 changes: 1 addition & 1 deletion include/stc/cspan.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ STC_API _istride* _cspan_shape2stride(cspan_layout layout, _istride shape[], int
#endif // STC_CSPAN_H_INCLUDED

/* --------------------- IMPLEMENTATION --------------------- */
#if defined i_implement || defined i_static
#if defined i_implement

STC_DEF void _cspan_print_assist(_istride pos[], const _istride shape[], const int rank,
char result[2][16], const char* brackets) {
Expand Down
2 changes: 1 addition & 1 deletion include/stc/cstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#endif // STC_CSTR_H_INCLUDED

#if defined i_implement || defined STC_IMPLEMENT || \
#if defined i_implement || \
defined STC_CSTR_CORE || \
defined STC_CSTR_IO || \
defined STC_CSTR_UTF8
Expand Down
2 changes: 1 addition & 1 deletion include/stc/deque.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ _c_MEMB(_find)(const Self* self, _m_raw raw) {
#endif // _i_has_cmp

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement) || defined(i_static)
#if defined i_implement

STC_DEF _m_value*
_c_MEMB(_push_front)(Self* self, _m_value value) {
Expand Down
2 changes: 1 addition & 1 deletion include/stc/hmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ _c_MEMB(_eq)(const Self* self, const Self* other) {
}

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement) || defined(i_static)
#if defined i_implement

STC_DEF _m_iter _c_MEMB(_begin)(const Self* self) {
_m_iter it = {self->table, self->table, self->meta};
Expand Down
2 changes: 1 addition & 1 deletion include/stc/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ STC_INLINE bool _c_MEMB(_eq)(const Self* self, const Self* other) {
#endif

// -------------------------- IMPLEMENTATION -------------------------
#if defined(i_implement) || defined(i_static)
#if defined i_implement

#if !defined i_no_clone
STC_DEF Self
Expand Down
2 changes: 1 addition & 1 deletion include/stc/pqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ STC_INLINE void _c_MEMB(_emplace)(Self* self, _m_raw raw)
#endif // !i_no_emplace

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement) || defined(i_static)
#if defined i_implement

STC_DEF void
_c_MEMB(_sift_down_)(Self* self, const isize idx, const isize n) {
Expand Down
6 changes: 3 additions & 3 deletions include/stc/priv/linkage.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#undef STC_API
#undef STC_DEF

#if !defined i_static && !defined STC_STATIC && (defined i_header || defined STC_HEADER || \
defined i_implement || defined STC_IMPLEMENT)
#if !defined i_static && !defined STC_STATIC && (defined i_header || defined STC_HEADER || \
defined i_implement || defined STC_IMPLEMENT)
#define STC_API extern
#define STC_DEF
#else
#define i_static
#define i_implement
#if defined __GNUC__ || defined __clang__
#define STC_API static __attribute__((unused))
#else
Expand Down
2 changes: 1 addition & 1 deletion include/stc/priv/queue_prv.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ STC_INLINE void _c_MEMB(_adjust_end_)(Self* self, isize n)
{ self->end = (self->end + n) & self->capmask; }

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined i_implement || defined i_static
#if defined i_implement

STC_DEF _m_iter _c_MEMB(_advance)(_m_iter it, isize n) {
isize len = _c_MEMB(_size)(it._s);
Expand Down
2 changes: 1 addition & 1 deletion include/stc/priv/sort_prv.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _c_MEMB(_binary_search)(const Self* self, const _m_raw raw)
#endif

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined i_implement || defined i_static
#if defined i_implement

static void _c_MEMB(_insertsort_lowhigh)(Self* self, isize lo, isize hi) {
for (isize j = lo, i = lo + 1; i <= hi; j = i, ++i) {
Expand Down
2 changes: 1 addition & 1 deletion include/stc/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ STC_INLINE int64_t crand32_uniform(crand32_uniform_dist* d)
#endif // STC_RANDOM_H_INCLUDED

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined i_implement || defined i_static
#if defined i_implement

#ifndef STC_RANDOM_C_INCLUDED
#define STC_RANDOM_C_INCLUDED
Expand Down
2 changes: 1 addition & 1 deletion include/stc/smap.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ STC_INLINE Self _c_MEMB(_with_n)(const _m_raw* raw, isize n)
{ Self cx = {0}; _c_MEMB(_put_n)(&cx, raw, n); return cx; }

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined(i_implement) || defined(i_static)
#if defined i_implement

STC_DEF void
_c_MEMB(_next)(_m_iter *it) {
Expand Down
2 changes: 1 addition & 1 deletion include/stc/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ STC_INLINE bool _c_MEMB(_eq)(const Self* self, const Self* other) {
#endif // _i_has_cmp

/* -------------------------- IMPLEMENTATION ------------------------- */
#if defined i_implement || defined i_static
#if defined i_implement

STC_DEF void
_c_MEMB(_clear)(Self* self) {
Expand Down

0 comments on commit 0dcdb1a

Please sign in to comment.