summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-12-26 15:13:32 -0500
committerAndrew Opalach <andrew@akon.city> 2024-12-26 15:13:32 -0500
commit97a20386f6e95923a24a30818e00685999298ddc (patch)
tree7abb3f73c228ddc91ce125f0a17688468b368f4c
parentbb4d5418f2173bf9a2fa1c0be31c3eb9f2025a21 (diff)
downloadlibalabaster-97a20386f6e95923a24a30818e00685999298ddc.tar.gz
libalabaster-97a20386f6e95923a24a30818e00685999298ddc.tar.bz2
libalabaster-97a20386f6e95923a24a30818e00685999298ddc.zip
Revise style
Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--include/al/array_typed.h9
-rw-r--r--include/al/atomic.h6
-rw-r--r--include/al/lib.h4
-rw-r--r--include/al/list.h11
-rw-r--r--include/al/str.h25
-rw-r--r--include/al/wstr.h15
-rw-r--r--meson_options.txt2
-rw-r--r--src/array.c18
-rw-r--r--src/lib.c5
-rw-r--r--src/log.c4
-rw-r--r--src/ring_buffer.c4
-rw-r--r--src/str.c11
12 files changed, 72 insertions, 42 deletions
diff --git a/include/al/array_typed.h b/include/al/array_typed.h
index 5c77507..076f58f 100644
--- a/include/al/array_typed.h
+++ b/include/al/array_typed.h
@@ -88,8 +88,9 @@
} \
static inline void _al_array_reserve_internal(N, __VA_ARGS__)(array(N, __VA_ARGS__) *a, u32 size) \
{ \
- if (a->alloc >= size) \
+ if (a->alloc >= size) { \
return; \
+ } \
size = size < al_grow_step ? al_next_power_of_two(size) : \
(size + al_grow_step) & ~al_grow_step; \
a->data = (T *)(!a->data ? al_malloc(sizeof(T) * size) : al_realloc(a->data, sizeof(T) * size)); \
@@ -145,12 +146,14 @@
AL_ARRAY_DEFINE_FUNCTIONS(N, T, S) \
static inline void al_array_reserve(N, S)(array(N, S) *a, u32 size) \
{ \
- if (S >= size) \
+ if (S >= size) { \
return; \
+ } \
bool copy_inline = a->data == NULL; \
_al_array_reserve_internal(N, S)(a, size); \
- if (UNLIKELY(copy_inline)) \
+ if (UNLIKELY(copy_inline)) { \
al_memcpy(a->data, a->inline_data, sizeof(T) * a->size); \
+ } \
}
#endif // _AL_ARRAY_TYPED_H
diff --git a/include/al/atomic.h b/include/al/atomic.h
index f30b6e8..39b0c25 100644
--- a/include/al/atomic.h
+++ b/include/al/atomic.h
@@ -77,8 +77,7 @@ static inline f32 _al_atomic_add_f32(atomic(f32) *a, f32 value, s32 order)
(void)a;
(void)value;
(void)order;
- al_assert(false);
- return 0.f;
+ al_assert_and_return(0.f);
}
static inline f32 _al_atomic_sub_f32(atomic(f32) *a, f32 value, s32 order)
@@ -86,8 +85,7 @@ static inline f32 _al_atomic_sub_f32(atomic(f32) *a, f32 value, s32 order)
(void)a;
(void)value;
(void)order;
- al_assert(false);
- return 0.f;
+ al_assert_and_return(0.f);
}
#endif // _AL_ATOMIC_H
diff --git a/include/al/lib.h b/include/al/lib.h
index de5008c..30f54b0 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -2,6 +2,7 @@
#define _AL_LIB_H
#include "types.h"
+#include "macros.h"
#define AL_USE_STDLIB
//#define AL_MEMORY_TRACKING
@@ -121,8 +122,9 @@ static inline void *al_memrchr(const void *s, s32 c, size_t n)
const u8 *src = (const u8 *)s + n - 1;
u8 d = (u8)c;
while (n--) {
- if (*src == d)
+ if (*src == d) {
return (void *)src;
+ }
src--;
}
return NULL;
diff --git a/include/al/list.h b/include/al/list.h
index 52628a4..333d2a4 100644
--- a/include/al/list.h
+++ b/include/al/list.h
@@ -93,16 +93,19 @@
} \
static inline list_##name *list_remove_##name(list_##name *l, list_##name *n) \
{ \
- if (!l) return l; \
- else if (l == n) { \
- if (n->next) \
+ if (!l) { \
+ return l; \
+ } else if (l == n) { \
+ if (n->next) { \
n->next->prev = NULL; \
+ } \
l = n->next; \
list_free_node_##name(n); \
} else { \
n->prev->next = n->next; \
- if (n->next) \
+ if (n->next) { \
n->next->prev = n->prev; \
+ } \
list_free_node_##name(n); \
} \
return l; \
diff --git a/include/al/str.h b/include/al/str.h
index 8a7746e..74cf922 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -39,8 +39,9 @@ static inline void al_str_free(str *s)
static inline u32 al_str_reserve(str *s, u32 size)
{
- if (size <= s->alloc)
+ if (size <= s->alloc) {
return s->alloc;
+ }
size = size < al_grow_step ? al_next_power_of_two(size) :
(size + al_grow_step) & ~al_grow_step;
@@ -111,8 +112,9 @@ static inline void al_str_prepend(str *s, str *c)
static inline s32 al_str_cmp(str *s, str *c, u32 i, u32 len)
{
- if (i + len > s->len || len > c->len)
+ if (i + len > s->len || len > c->len) {
return -1;
+ }
return al_memcmp(&al_str_at(s, i), c->data, len);
}
@@ -124,28 +126,32 @@ static inline bool al_str_eq(str *s, str *c)
static inline s32 al_str_find(str *s, char c)
{
char *loc = (char *)al_memchr(s->data, c, s->len);
- if (!loc) return -1;
+ if (!loc) {
+ return -1;
+ }
return (s32)(loc - s->data);
}
static inline s32 al_str_rfind(str *s, char c)
{
char *loc = (char *)al_memrchr(s->data, c, s->len);
- if (!loc) return -1;
+ if (!loc) {
+ return -1;
+ }
return (s32)(loc - s->data);
}
// extremely slow.
static inline s32 al_str_find_str(str *s, str *c)
{
- if (c->len > s->len)
+ if (c->len > s->len) {
return -1;
+ }
for (u32 i = 0; i < s->len - c->len; i++) {
- if (al_str_at(s, i) != al_str_at(c, 0))
- continue;
- if (al_str_cmp(s, c, i, c->len) == 0)
+ if (al_str_at(s, i) == al_str_at(c, 0) && al_str_cmp(s, c, i, c->len) == 0) {
return i;
+ }
}
return -1;
@@ -154,8 +160,9 @@ static inline s32 al_str_find_str(str *s, str *c)
static inline u32 al_str_hash(str *s)
{
u32 hash = 5381;
- for (u32 i = 0; i < s->len; i++)
+ for (u32 i = 0; i < s->len; i++) {
hash = ((hash << 5) + hash) + al_str_at(s, i); /* hash * 33 + c */
+ }
return hash;
}
diff --git a/include/al/wstr.h b/include/al/wstr.h
index 765445b..561e236 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -45,8 +45,9 @@ static inline void al_wstr_free(wstr *w)
static inline u32 al_wstr_reserve(wstr *w, u32 size)
{
- if (size <= w->alloc)
+ if (size <= w->alloc) {
return w->alloc;
+ }
size = size < al_grow_step ? al_next_power_of_two(size) :
(size + al_grow_step) & ~al_grow_step;
@@ -76,8 +77,9 @@ static inline bool al_wstr_from_cstr(wstr *w, char *c)
#ifdef AL_HAVE_WIDE_STRING
mbstate_t mbstate = { 0 };
size_t len = mbsrtowcs(NULL, (const char **)&c, 0, &mbstate);
- if (len == (size_t)-1)
+ if (len == (size_t)-1) {
return false;
+ }
al_wstr_sized(w, (u32)(len + 1));
w->len = (u32)mbsrtowcs(w->data, (const char **)&c, len, &mbstate);
al_assert(w->len == (u32)len);
@@ -104,8 +106,9 @@ static inline bool al_wstr_to_str(wstr *w, str *s)
wchar_t *data = w->data;
mbstate_t mbstate = { 0 };
size_t len = wcsrtombs(NULL, (const wchar_t **)&w->data, 0, &mbstate);
- if (len == (size_t)-1)
+ if (len == (size_t)-1) {
return false;
+ }
al_str_sized(s, (u32)len);
// Excludes the null terminator.
s->len = (u32)wcsrtombs(s->data, (const wchar_t **)&w->data, len, &mbstate);
@@ -145,8 +148,9 @@ static inline s32 al_wstr_cmp(wstr *w, wstr *c, u32 start, u32 len)
static inline s32 al_wstr_find(wstr *w, wchar_t c)
{
for (s32 i = 0; i < (s32)w->len; i++) {
- if (al_wstr_at(w, i) == c)
+ if (al_wstr_at(w, i) == c) {
return i;
+ }
}
return -1;
}
@@ -154,8 +158,9 @@ static inline s32 al_wstr_find(wstr *w, wchar_t c)
static inline s32 al_wstr_rfind(wstr *w, wchar_t c)
{
for (s32 i = (s32)w->len - 1; i >= 0; i--) {
- if (al_wstr_at(w, i) == c)
+ if (al_wstr_at(w, i) == c) {
return i;
+ }
}
return -1;
}
diff --git a/meson_options.txt b/meson_options.txt
index ea1045c..39efa83 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1 +1 @@
-option('tests', type: 'boolean', value: true)
+option('tests', type: 'boolean', value: false)
diff --git a/src/array.c b/src/array.c
index 0459c96..58d3c7f 100644
--- a/src/array.c
+++ b/src/array.c
@@ -87,13 +87,14 @@ AL_MACRO_WRAP \
} \
})
-#define al_array_remove_all(arr, elem) \
-AL_MACRO_WRAP \
-({ \
- for (u32 i = (arr).size; i-- > 0;) { \
- if (al_array_at(arr, i) == elem) \
- al_array_remove_at(arr, i); \
- } \
+#define al_array_remove_all(arr, elem) \
+AL_MACRO_WRAP \
+({ \
+ for (u32 i = (arr).size; i-- > 0;) { \
+ if (al_array_at(arr, i) == elem) { \
+ al_array_remove_at(arr, i); \
+ } \
+ } \
})
#define al_array_remove_at(arr, i) \
@@ -149,8 +150,9 @@ AL_UNUSED_FUNCTION_PUSH
static inline u32 _al_array_reserve(void **ptr, u32 item_size, u32 prev_size, u32 size)
{
- if (size <= prev_size)
+ if (size <= prev_size) {
return prev_size;
+ }
size = size < al_grow_step ? al_next_power_of_two(size) :
(size + al_grow_step) & ~al_grow_step;
diff --git a/src/lib.c b/src/lib.c
index 9a658cf..ca737e4 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -44,8 +44,9 @@ static size_t total_alloc = 0;
#define current_changed_by(n) \
current_alloc += (n); \
- if (current_alloc > peak_alloc) \
- peak_alloc = current_alloc;
+ if (current_alloc > peak_alloc) { \
+ peak_alloc = current_alloc; \
+ }
void al_malloc_init(void)
{
diff --git a/src/log.c b/src/log.c
index 436ac16..c4b24f0 100644
--- a/src/log.c
+++ b/src/log.c
@@ -92,7 +92,9 @@ s32 _al_logv(u8 level, const char *section, const char *name, const s32 line, co
ret += al_printf(AL_LOG_TEMPLATE, name, line, func, level);
#endif
ret += al_vprintf(fmt, args);
- if (strcspn(fmt, "\r\n") == al_strlen(fmt)) ret += al_printf("\n");
+ if (strcspn(fmt, "\r\n") == al_strlen(fmt)) {
+ ret += al_printf("\n");
+ }
#else
char *buffer = get_message_buffer(level, section, fmt, name, line, func, args);
#endif
diff --git a/src/ring_buffer.c b/src/ring_buffer.c
index cf72d2b..1c39b7b 100644
--- a/src/ring_buffer.c
+++ b/src/ring_buffer.c
@@ -14,7 +14,9 @@ void al_ring_buffer_init(struct al_ring_buffer *buf, u8 *data, size_t length)
static inline u8 *previous(struct al_ring_buffer *buf, u8 *ptr)
{
- if (ptr == buf->start) ptr = buf->end;
+ if (ptr == buf->start) {
+ ptr = buf->end;
+ }
return --ptr;
}
diff --git a/src/str.c b/src/str.c
index 2cde190..c955d51 100644
--- a/src/str.c
+++ b/src/str.c
@@ -7,7 +7,9 @@ s64 al_str_to_long(str *s, s32 base)
u32 i = 0;
s32 neg = 0;
- while (al_isspace(al_str_at(s, i)) && i < s->len) i++;
+ while (al_isspace(al_str_at(s, i)) && i < s->len) {
+ i++;
+ }
if (al_str_at(s, i) == '-') {
neg = 1;
@@ -50,8 +52,11 @@ s64 al_str_to_long(str *s, s32 base)
ret = ret * base + c;
}
- if (error) ret = neg ? INT64_MIN : INT64_MAX;
- else if (neg) ret = -ret;
+ if (error) {
+ ret = neg ? INT64_MIN : INT64_MAX;
+ } else if (neg) {
+ ret = -ret;
+ }
return ret;
}