diff --git a/src/guf_assert.h b/src/guf_assert.h index aab6509..f49013e 100644 --- a/src/guf_assert.h +++ b/src/guf_assert.h @@ -123,7 +123,7 @@ extern void guf_set_global_panic_handler(guf_panic_handler_fn panic_handler) extern const char *guf_err_to_str(guf_err err) { if (GUF_ARR_SIZE(guf_err_type_str) != GUF_ERR_TYPES_NUM) { - puts("Note: size of guf_err_type_str != GUF_ERR_TYPES_NUM"); + fputs("libguf warning (in guf_assert.h): array size of guf_err_type_str != GUF_ERR_TYPES_NUM", stderr); } if (err < 0 || err >= GUF_ERR_TYPES_NUM) { diff --git a/src/guf_dict.h b/src/guf_dict.h index 42b2f78..bf2cacb 100755 --- a/src/guf_dict.h +++ b/src/guf_dict.h @@ -405,7 +405,7 @@ static void GUF_CAT(GUF_DICT_NAME, _try_grow_if_necessary)(GUF_DICT_NAME *ht, gu guf_err_set_or_panic(err, GUF_ERR_ALLOC_FAIL, GUF_ERR_MSG("in function dict_try_insert: New kv_indices_capacity would overflow)")); return; } else { - GUF_ASSERT(new_size_bytes_test <= PTRDIFF_MAX); + GUF_ASSERT(new_size_bytes_test <= PTRDIFF_MAX && guf_is_pow2_size_t(new_size_bytes_test)); new_size_bytes = (ptrdiff_t)new_size_bytes_test; } GUF_ASSERT_RELEASE(new_size_bytes > old_size_bytes); @@ -416,7 +416,8 @@ static void GUF_CAT(GUF_DICT_NAME, _try_grow_if_necessary)(GUF_DICT_NAME *ht, gu guf_err_set_or_panic(err, GUF_ERR_ALLOC_FAIL, GUF_ERR_MSG("in function dict_try_insert: re-allocation failed")); return; } - allocator->free(ht->kv_indices, old_size_bytes, allocator->ctx); + // NOTE: would be more memory-efficient to free first, but that would leave the dict in an invalid state if the alloc fails. + allocator->free(ht->kv_indices, old_size_bytes, allocator->ctx); ht->kv_indices = new_kv_indices; ht->kv_indices_cap = ht->kv_indices_cap * KV_META_GROWTH_FAC;; GUF_ASSERT(guf_is_pow2_size_t(ht->kv_indices_cap)); diff --git a/src/guf_hash.h b/src/guf_hash.h index 97eced0..80b4f27 100644 --- a/src/guf_hash.h +++ b/src/guf_hash.h @@ -36,11 +36,6 @@ GUF_HASH_KWRDS uint64_t guf_hash64(const void *data, ptrdiff_t num_bytes, uint64 } #endif -// Calculate a mod pow2 (with pow2 being a power of two != 0) -static inline uint32_t guf_mod_pow2_u32(uint32_t a, uint32_t pow2) {return a & (pow2 - 1);} -static inline uint64_t guf_mod_pow2_u64(uint64_t a, uint64_t pow2) {return a & (pow2 - 1);} -static inline guf_hash_size_t guf_mod_pow2_hash(guf_hash_size_t a, guf_hash_size_t pow2) {return a & (pow2 - 1);} - #endif #if defined(GUF_HASH_IMPL) || defined(GUF_HASH_IMPL_STATIC)