Rename GUF_STATIC_BUF_SIZE

This commit is contained in:
jun 2025-03-06 12:01:16 +01:00
parent e489dd694b
commit d057d76334
5 changed files with 19 additions and 18 deletions

View File

@ -122,14 +122,14 @@ 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_STATIC_BUF_SIZE(guf_err_type_str) != GUF_ERR_TYPES_NUM) {
if (GUF_ARR_SIZE(guf_err_type_str) != GUF_ERR_TYPES_NUM) {
puts("Note: size of guf_err_type_str != GUF_ERR_TYPES_NUM");
}
if (err < 0 || err >= GUF_ERR_TYPES_NUM) {
return "Invalid error code";
} else {
if (err > GUF_STATIC_BUF_SIZE(guf_err_type_str)) {
if (err > GUF_ARR_SIZE(guf_err_type_str)) {
return "Invalid error string";
}
return guf_err_type_str[err];

View File

@ -15,7 +15,7 @@
#elif SIZE_MAX == UINT8_MAX
#define GUF_PLATFORM_BITS 8
#else
#define "Could not detect GUF_PLATFORM_BITS"
#error "Could not detect GUF_PLATFORM_BITS"
#endif
/*
@ -39,7 +39,8 @@ typedef enum guf_cpy_opt {
} guf_cpy_opt;
#define GUF_SWAP(TYPE, val_a, val_b) do {TYPE guf_swap_tmp = val_a; val_a = val_b; val_b = guf_swap_tmp;} while (0);
#define GUF_STATIC_BUF_SIZE(BUF) (sizeof((BUF)) / (sizeof((BUF)[0])))
#define GUF_ARR_SIZE(ARR) (sizeof((ARR)) / (sizeof((ARR)[0])))
#define GUF_MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#define GUF_MAX(X, Y) ((X) > (Y) ? (X) : (Y))

View File

@ -76,25 +76,25 @@ GUF_RAND_KWRDS void guf_randstate_init(guf_randstate *state, uint64_t seed)
{
GUF_ASSERT_RELEASE(state);
#ifdef GUF_RAND_32_BIT
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(state->s); ++i) {
for (size_t i = 0; i < GUF_ARR_SIZE(state->s); ++i) {
state->s[i] = (uint32_t)(guf_rand_splitmix64(&seed) >> 32);
}
if (!state->s[0] && !state->s[1] && !state->s[2] && !state->s[3]) { // State must not be only zeroes:
state->s[0] = 0x9e3779b9; // arbitrary constant != 0
seed = 0x9e3779b97f4a7c15;
for (size_t i = 1; i < GUF_STATIC_BUF_SIZE(state->s); ++i) {
for (size_t i = 1; i < GUF_ARR_SIZE(state->s); ++i) {
state->s[i] = (uint32_t)(guf_rand_splitmix64(&seed) >> 32);
}
}
#else
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(state->s); ++i) {
for (size_t i = 0; i < GUF_ARR_SIZE(state->s); ++i) {
state->s[i] = guf_rand_splitmix64(&seed);
}
if (!state->s[0] && !state->s[1] && !state->s[2] && !state->s[3]) { // State must not be only zeroes:
state->s[0] = 0x9e3779b97f4a7c15; // arbitrary constant != 0
seed = state->s[0];
for (size_t i = 1; i < GUF_STATIC_BUF_SIZE(state->s); ++i) {
for (size_t i = 1; i < GUF_ARR_SIZE(state->s); ++i) {
state->s[i] = guf_rand_splitmix64(&seed);
}
}

View File

@ -157,7 +157,7 @@ guf_str *guf_str_reserve(guf_str *str, size_t new_cap)
if (is_short(str)) { // a) Was short string.
char tmp_buf[GUF_STR_SSO_BUFSIZE];
GUF_ASSERT_RELEASE(GUF_STATIC_BUF_SIZE(tmp_buf) >= str_len + 1);
GUF_ASSERT_RELEASE(GUF_ARR_SIZE(tmp_buf) >= str_len + 1);
memcpy(tmp_buf, str->data.stack.c_str, str_len + 1);
str->data.heap.c_str = calloc(new_cap + 1, sizeof(str->data.heap.c_str[0]));
@ -195,8 +195,8 @@ guf_str guf_str_new(guf_str_view str_view)
guf_str str = GUF_STR_UNINITIALISED;
// Temporary debug; TODO: remove
GUF_ASSERT_RELEASE(GUF_STATIC_BUF_SIZE(str.data.stack.c_str) == GUF_STR_SSO_BUFSIZE);
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(str.data.stack.c_str); ++i) {
GUF_ASSERT_RELEASE(GUF_ARR_SIZE(str.data.stack.c_str) == GUF_STR_SSO_BUFSIZE);
for (size_t i = 0; i < GUF_ARR_SIZE(str.data.stack.c_str); ++i) {
GUF_ASSERT_RELEASE(str.data.stack.c_str[i] == '\0');
}
@ -223,8 +223,8 @@ guf_str guf_str_new_with_extra_cap(guf_str_view str_view, size_t extra_capacity)
guf_str str = GUF_STR_UNINITIALISED;
// Temporary debug; TODO: remove
GUF_ASSERT_RELEASE(GUF_STATIC_BUF_SIZE(str.data.stack.c_str) == GUF_STR_SSO_BUFSIZE);
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(str.data.stack.c_str); ++i) {
GUF_ASSERT_RELEASE(GUF_ARR_SIZE(str.data.stack.c_str) == GUF_STR_SSO_BUFSIZE);
for (size_t i = 0; i < GUF_ARR_SIZE(str.data.stack.c_str); ++i) {
GUF_ASSERT_RELEASE(str.data.stack.c_str[i] == '\0');
}

View File

@ -99,7 +99,7 @@ GUF_UTF8_KWRDS bool guf_utf8_encode(guf_utf8_char *result, uint32_t cp)
return false;
}
memset(result->bytes, '\0', GUF_STATIC_BUF_SIZE(result->bytes));
memset(result->bytes, '\0', GUF_ARR_SIZE(result->bytes));
int num_bytes = 0, first_byte_bits = 0;
if (cp <= 0x7F) { // binary: 0xxx.xxxx
@ -219,7 +219,7 @@ GUF_UTF8_KWRDS guf_utf8_stat guf_utf8_char_next(guf_utf8_char *res, guf_str_view
str->len--;
str->str = str->len ? str->str + 1 : NULL;
for (size_t i = 1; i < GUF_STATIC_BUF_SIZE(res->bytes); ++i) {
for (size_t i = 1; i < GUF_ARR_SIZE(res->bytes); ++i) {
res->bytes[i] = '\0';
}
@ -344,7 +344,7 @@ GUF_UTF8_KWRDS bool guf_utf8_char_is_whitespace(const guf_utf8_char *c)
switch (num_bytes)
{
case 1:
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(ws_one_byte); ++i) {
for (size_t i = 0; i < GUF_ARR_SIZE(ws_one_byte); ++i) {
if (c->bytes[0] == ws_one_byte[i][0]) {
return true;
}
@ -352,7 +352,7 @@ GUF_UTF8_KWRDS bool guf_utf8_char_is_whitespace(const guf_utf8_char *c)
return false;
case 2:
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(ws_two_bytes); ++i) {
for (size_t i = 0; i < GUF_ARR_SIZE(ws_two_bytes); ++i) {
if (c->bytes[0] == ws_two_bytes[i][0] && c->bytes[1] == ws_two_bytes[i][1]) {
return true;
}
@ -360,7 +360,7 @@ GUF_UTF8_KWRDS bool guf_utf8_char_is_whitespace(const guf_utf8_char *c)
return false;
case 3:
for (size_t i = 0; i < GUF_STATIC_BUF_SIZE(ws_three_bytes); ++i) {
for (size_t i = 0; i < GUF_ARR_SIZE(ws_three_bytes); ++i) {
if (c->bytes[0] == ws_three_bytes[i][0] && c->bytes[1] == ws_three_bytes[i][1] && c->bytes[2] == ws_three_bytes[i][2]) {
return true;
}