90 Commits

Author SHA1 Message Date
6bf47f0ca6 Refactor to use portable minimum-width integers.
The signed and unsigned fixed-width integers (int32_t, uint32_t etc.) are optional
in C99 (and above). Use the non-optional minimum-width integers (int_fast32_t, uint_fast32_t and int_least32_t, uint_least32_t etc.) instead.

To simulate unsigned wrap-around, use the GUF_UWRAP macros in guf_common.h

cf. https://en.cppreference.com/w/c/types/integer (last-retrieved: 2025-05-18)
2025-12-23 14:11:06 +01:00
b7e3eec2c1 Add unsigned integer wrapping functions 2025-12-23 14:11:06 +01:00
5eb3c22a01 Add more dbuf_str tests 2025-12-23 14:11:06 +01:00
fad608e2ed Fix failed assertion in guf_str_copy
An assertion GUF_ASSERT(str_is_valid(dst)) failed in guf_str_copy when it called guf_str_cstr(dst)
 since guf_str_cstr assumes an already valid string, which was not the case when src was a short string.

Therefore, we get the dst's c_str now without calling guf_str_cstr(dst)

(Found by writing DbufStrTest.)
2025-12-23 14:11:06 +01:00
1a5a32d9b9 Prevent more potential int promotion bugs 2025-12-23 14:11:06 +01:00
bce0407674 Make signed guf_wrapping_mul more general
Don't fail on mod == 0 (in weird cases where the given UNSIGNED_TYPE_MAX == SIGNED_TYPE_MAX)
but
res = mod > 0 ? (1u * res % mod) : res;
2025-12-23 14:11:06 +01:00
26bab4efbe Use better terminology for overflow and integer 'underflow' 2025-12-23 14:11:06 +01:00
7b2334a668 Fix potential int-promotion bugs in ckdint
Expressions like
(uin16_t)a * (uint16_t)b * (uint16_t)c
might be promoted to (signed) int (in that example, on platforms where sizeof(int) > sizeof(uint16_t)),
and therefore lead to undefined behaviour on overflow.

The above expression can be fixed as
1u * (uint16_t)a * (uint16_t)b * (uint16_t)c
(The 1u makes sure a, b, and c would be promoted to unsigned int (instead of int) on platforms where sizeof(int) > sizeof(uint16_t))

cf. https://stackoverflow.com/questions/27001604/32-bit-unsigned-multiply-on-64-bit-causing-undefined-behavior
2025-12-23 14:11:05 +01:00
5828c4ecec Change C/CXX flags 2025-12-23 14:11:05 +01:00
64a71087b3 Refactor test 2025-12-23 14:11:05 +01:00
148cc741eb Add static/non-static option for guf_alloc_libc.h 2025-12-23 14:11:05 +01:00
08b7edbdf4 Add name to alloc_tracker 2025-12-23 14:11:05 +01:00
9cec01cc50 Add guf_alloc_tracker 2025-12-23 14:11:05 +01:00
5cb2f240e0 Fix implementation defined behaviour in guf_wrapping_mul 2025-12-23 14:11:05 +01:00
dd4155d944 Add math_ckdint tests 2025-12-23 14:11:05 +01:00
26015e2380 Refactor tests 2025-12-23 14:11:05 +01:00
e3b18473f9 Add guf_math_ckdint IMPL_STATIC etc. 2025-12-23 14:11:05 +01:00
52d9f2c859 Add checked mul arithmetic 2025-12-23 14:11:05 +01:00
4111f54159 Add checked arithmetic 2025-12-23 14:11:05 +01:00
111023b7b1 Add guf_tok test 2025-12-23 14:11:05 +01:00
f5a91be8df Add more guf_str tests 2025-12-23 14:11:05 +01:00
936a9dac56 Re-implement guf_str tokeniser 2025-12-23 14:11:05 +01:00
9b66649e01 Add guf_str hash functions 2025-12-23 14:11:05 +01:00
e923775769 Fix guf_str bugs and add tests 2025-12-23 14:11:05 +01:00
ac5e66b481 Minor guf_id_pool changes 2025-12-23 14:11:05 +01:00
e2036b768e Fix guf_dict_init_with_capacity kv_idx_cap calculation 2025-12-23 14:11:05 +01:00
082b004391 Comment guf_rand 2025-12-23 14:11:05 +01:00
5d2c4be265 Add separate 32/64 bit versions to guf_rand 2025-12-23 14:11:05 +01:00
e8ea48dc45 Add guf_rand_splitmix32 2025-12-23 14:11:05 +01:00
4a231dc58f Add guf_str_substr 2025-12-23 14:11:05 +01:00
883154f2ab Add guf_dict_shrink_capacity 2025-12-23 14:11:05 +01:00
b1a5094d2b Add more dict functions 2025-12-23 14:11:05 +01:00
ce4b25318d Add comments 2025-12-23 14:11:05 +01:00
b541100a76 Change directory structure 2025-12-23 14:11:05 +01:00
0376fd3e99 Add more guf_str functions 2025-12-23 14:11:05 +01:00
eed418e6cd Add changeable load factor 2025-12-23 14:11:05 +01:00
8b696b31fc Add move- and copy ctors to dict and guf_str 2025-12-23 14:11:05 +01:00
e1bc585f68 Use SIZE_MAX instead of SIZE_T_MAX 2025-12-23 14:11:05 +01:00
25cf7f17b7 Fix dict asserts 2025-12-23 14:11:05 +01:00
c8ffde8c19 Fix warnings in release 2025-12-23 14:11:05 +01:00
e1af4f76a7 Replace puts with fputs in guf_err_to_str 2025-12-23 14:11:05 +01:00
ec9cd97631 Pass key_hash to guf_dict_find_idx to avoid re-computation 2025-12-23 14:11:05 +01:00
18f4496204 Fix GUF_DICT_64_BIT_IDX and guf_dict_max_capacity() 2025-12-23 14:11:05 +01:00
f3f7cec5f4 Use single u32/u64 as GUF_DICT_KV_META_T instead of two 2025-12-23 14:11:05 +01:00
5d8fa1cc62 Fix allocation overflow for guf_dbuf and guf_dict
(Implement GUF_ALLOC_MAX_BYTES and GUF_ALLOC_MAX_CAPACITY).
2025-12-23 14:11:05 +01:00
52ca55f1d6 Improve guf_id_pool 2025-12-23 14:11:05 +01:00
81ab99ff15 Implement guf_str 2025-12-23 14:11:05 +01:00
517151b342 Change short-string approach to use 32 instead of 40 bytes 2025-12-23 14:11:05 +01:00
3d83ea0b17 Add 3x3 matrix inversion 2025-12-23 14:11:05 +01:00
7e348e74bc Change linalg mat_inverse.
Still not sure whether it's better to calculate
rref[pivot_row][col] * (rref[row][pivot_col] / pivot_val) (option 1)
vs.
rref[pivot_row][col] * rref[row][pivot_col] / pivot_val   (option 2)

(i.e.  a * b / c vs. "a * (b/c))

in terms of floating point error.

But I think option 1 (current commit) is better, since the scale factor
(rref[row][pivot_col] / pivot_val) is always <= 1 here (I think).
2025-12-23 14:11:05 +01:00