summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-11-26 16:09:26 -0500
committerAndrew Opalach <andrew@akon.city> 2024-11-26 16:09:26 -0500
commit35d0684f1d6f6b0bd1d463e866689bbaac73d156 (patch)
treef1f25eb12d69035655c9d54b4a55e8ee7d5b0d2d
parent90acc831f543182dfc78363a2a9c0ab3fec274d4 (diff)
downloadlibalabaster-35d0684f1d6f6b0bd1d463e866689bbaac73d156.tar.gz
libalabaster-35d0684f1d6f6b0bd1d463e866689bbaac73d156.tar.bz2
libalabaster-35d0684f1d6f6b0bd1d463e866689bbaac73d156.zip
all: Cleanup macro usage
Signed-off-by: Andrew Opalach <andrew@akon.city>
-rw-r--r--include/al/array_typed.h62
-rw-r--r--include/al/atomic.h41
-rw-r--r--include/al/lib.h97
-rw-r--r--include/al/macros.h84
-rw-r--r--include/al/random.h13
-rw-r--r--include/al/str.h9
-rw-r--r--include/al/types.h1
-rw-r--r--include/al/wstr.h2
-rw-r--r--meson.build11
-rw-r--r--src/array.c3
-rw-r--r--src/log.c8
-rw-r--r--src/ring_buffer.c20
-rw-r--r--tests/lib.c4
-rw-r--r--tests/str.c4
14 files changed, 213 insertions, 146 deletions
diff --git a/include/al/array_typed.h b/include/al/array_typed.h
index a48b230..ae93bf4 100644
--- a/include/al/array_typed.h
+++ b/include/al/array_typed.h
@@ -5,38 +5,40 @@
#error "missing required GNU C extensions"
#endif
-#define AL_EMPTY_DEFAULT(...) AL_EMPTY_DEFAULT_0(__VA_ARGS__, , )
-#define AL_EMPTY_DEFAULT_0(FUNC, T, S, ...) FUNC(T, S)
-#define AL_PASTER_EVALUATOR(X, Y) X##_##Y
-#define AL_PASTER(X, Y) AL_PASTER_EVALUATOR(X, Y)
+#include "macros.h"
-#define _array(N, ...) AL_PASTER(array, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_init(N, ...) AL_PASTER(_array_init, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_data(N, ...) AL_PASTER(_array_data, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_reserve(N, ...) AL_PASTER(_array_reserve, AL_PASTER(N, __VA_ARGS__))
-#define __al_array_reserve_internal(N, ...) AL_PASTER(_array_reserve_internal, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_at(N, ...) AL_PASTER(_array_at, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_last(N, ...) AL_PASTER(_array_last, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_push(N, ...) AL_PASTER(_array_push, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_pop(N, ...) AL_PASTER(_array_pop, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_remove_at(N, ...) AL_PASTER(_array_remove_at, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_pop_at(N, ...) AL_PASTER(_array_pop_at, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_insert(N, ...) AL_PASTER(_array_insert, AL_PASTER(N, __VA_ARGS__))
-#define _al_array_free(N, ...) AL_PASTER(_array_free, AL_PASTER(N, __VA_ARGS__))
+#define AL_ARRAY_EMPTY_DEFAULT_0(FUNC, T, S, ...) FUNC(T, S)
+#define AL_ARRAY_EMPTY_DEFAULT(...) AL_ARRAY_EMPTY_DEFAULT_0(__VA_ARGS__, , )
+#define AL_ARRAY_PASTER_EVALUATOR(X, Y) X##_##Y
+#define AL_ARRAY_PASTER(X, Y) AL_ARRAY_PASTER_EVALUATOR(X, Y)
-#define array(...) AL_EMPTY_DEFAULT(_array, __VA_ARGS__)
-#define al_array_init(...) AL_EMPTY_DEFAULT(_al_array_init, __VA_ARGS__)
-#define al_array_data(...) AL_EMPTY_DEFAULT(_al_array_data, __VA_ARGS__)
-#define _al_array_reserve_internal(...) AL_EMPTY_DEFAULT(__al_array_reserve_internal, __VA_ARGS__)
-#define al_array_reserve(...) AL_EMPTY_DEFAULT(_al_array_reserve, __VA_ARGS__)
-#define al_array_at(...) AL_EMPTY_DEFAULT(_al_array_at, __VA_ARGS__)
-#define al_array_last(...) AL_EMPTY_DEFAULT(_al_array_last, __VA_ARGS__)
-#define al_array_push(...) AL_EMPTY_DEFAULT(_al_array_push, __VA_ARGS__)
-#define al_array_pop(...) AL_EMPTY_DEFAULT(_al_array_pop, __VA_ARGS__)
-#define al_array_remove_at(...) AL_EMPTY_DEFAULT(_al_array_remove_at, __VA_ARGS__)
-#define al_array_pop_at(...) AL_EMPTY_DEFAULT(_al_array_pop_at, __VA_ARGS__)
-#define al_array_insert(...) AL_EMPTY_DEFAULT(_al_array_insert, __VA_ARGS__)
-#define al_array_free(...) AL_EMPTY_DEFAULT(_al_array_free, __VA_ARGS__)
+#define _array(N, ...) AL_ARRAY_PASTER(array, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_init(N, ...) AL_ARRAY_PASTER(_array_init, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_data(N, ...) AL_ARRAY_PASTER(_array_data, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_reserve(N, ...) AL_ARRAY_PASTER(_array_reserve, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define __al_array_reserve_internal(N, ...) AL_ARRAY_PASTER(_array_reserve_internal, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_at(N, ...) AL_ARRAY_PASTER(_array_at, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_last(N, ...) AL_ARRAY_PASTER(_array_last, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_push(N, ...) AL_ARRAY_PASTER(_array_push, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_pop(N, ...) AL_ARRAY_PASTER(_array_pop, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_remove_at(N, ...) AL_ARRAY_PASTER(_array_remove_at, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_pop_at(N, ...) AL_ARRAY_PASTER(_array_pop_at, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_insert(N, ...) AL_ARRAY_PASTER(_array_insert, AL_ARRAY_PASTER(N, __VA_ARGS__))
+#define _al_array_free(N, ...) AL_ARRAY_PASTER(_array_free, AL_ARRAY_PASTER(N, __VA_ARGS__))
+
+#define array(...) AL_ARRAY_EMPTY_DEFAULT(_array, __VA_ARGS__)
+#define al_array_init(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_init, __VA_ARGS__)
+#define al_array_data(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_data, __VA_ARGS__)
+#define _al_array_reserve_internal(...) AL_ARRAY_EMPTY_DEFAULT(__al_array_reserve_internal, __VA_ARGS__)
+#define al_array_reserve(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_reserve, __VA_ARGS__)
+#define al_array_at(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_at, __VA_ARGS__)
+#define al_array_last(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_last, __VA_ARGS__)
+#define al_array_push(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_push, __VA_ARGS__)
+#define al_array_pop(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_pop, __VA_ARGS__)
+#define al_array_remove_at(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_remove_at, __VA_ARGS__)
+#define al_array_pop_at(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_pop_at, __VA_ARGS__)
+#define al_array_insert(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_insert, __VA_ARGS__)
+#define al_array_free(...) AL_ARRAY_EMPTY_DEFAULT(_al_array_free, __VA_ARGS__)
#define AL_ARRAY_DEFINE_FUNCTIONS(N, T, ...) \
static inline T *al_array_at(N, __VA_ARGS__)(array(N, __VA_ARGS__) *a, u32 i) \
diff --git a/include/al/atomic.h b/include/al/atomic.h
index 594413c..a8bb6b2 100644
--- a/include/al/atomic.h
+++ b/include/al/atomic.h
@@ -3,7 +3,7 @@
#include <c89atomic.h>
-#include "types.h"
+#include "lib.h"
#define AL_ATOMIC_RELAXED c89atomic_memory_order_relaxed
#define AL_ATOMIC_CONSUME c89atomic_memory_order_consume
@@ -30,26 +30,28 @@ typedef f32 c89atomic_f32;
#define AL_ATOMIC_DEFINE(T, C, S) \
typedef c89atomic_##C atomic(T); \
- static inline T al_atomic_load(T)(atomic(T) *a, int order) \
+ static inline T al_atomic_load(T)(atomic(T) *a, s32 order) \
{ \
return c89atomic_load_explicit_##S(a, order); \
} \
- static inline void al_atomic_store(T)(atomic(T) *a, T value, int order) \
+ static inline void al_atomic_store(T)(atomic(T) *a, T value, s32 order) \
{ \
c89atomic_store_explicit_##S(a, value, order); \
} \
- static inline T al_atomic_add(T)(atomic(T) *a, T value, int order) \
+ static inline T al_atomic_compare_and_swap(T)(atomic(T) *a, T expected, T desired) \
+ { \
+ return c89atomic_compare_and_swap_##S(a, expected, desired); \
+ }
+
+#define AL_ATOMIC_DEFINE_EXT(T, C, S) \
+ static inline T al_atomic_add(T)(atomic(T) *a, T value, s32 order) \
{ \
return c89atomic_fetch_add_explicit_##S(a, value, order); \
} \
- static inline T al_atomic_sub(T)(atomic(T) *a, T value, int order) \
+ static inline T al_atomic_sub(T)(atomic(T) *a, T value, s32 order) \
{ \
return c89atomic_fetch_sub_explicit_##S(a, value, order); \
} \
- static inline T al_atomic_compare_and_swap(T)(atomic(T) *a, T expected, T desired) \
- { \
- return c89atomic_compare_and_swap_##S(a, expected, desired); \
- }
#if defined C89ATOMIC_64BIT
AL_ATOMIC_DEFINE(size_t, uint64, 64)
@@ -57,14 +59,35 @@ AL_ATOMIC_DEFINE(size_t, uint64, 64)
AL_ATOMIC_DEFINE(size_t, uint32, 32)
#endif
AL_ATOMIC_DEFINE(u64, uint64, 64);
+AL_ATOMIC_DEFINE_EXT(u64, uint64, 64);
AL_ATOMIC_DEFINE(s64, int64, i64);
AL_ATOMIC_DEFINE(u32, uint32, 32);
AL_ATOMIC_DEFINE(s32, int32, i32);
+AL_ATOMIC_DEFINE_EXT(s32, int32, i32);
AL_ATOMIC_DEFINE(u16, uint16, 16);
+AL_ATOMIC_DEFINE_EXT(u16, uint16, 16);
AL_ATOMIC_DEFINE(s16, int16, i16);
AL_ATOMIC_DEFINE(u8, uint8, 8);
AL_ATOMIC_DEFINE(s8, int8, i8);
AL_ATOMIC_DEFINE(f64, f64, f64);
AL_ATOMIC_DEFINE(f32, f32, f32);
+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;
+}
+
+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;
+}
+
#endif // _AL_ATOMIC_H
diff --git a/include/al/lib.h b/include/al/lib.h
index 5748293..e13a7c7 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -7,7 +7,7 @@
//#define AL_MEMORY_TRACKING
//#define AL_FORCE_DISABLE_OUTPUT
-#if defined __clang__ || defined __GNUC__
+#if defined __GNUC__ || defined __clang__
#define AL_UNUSED_FUNCTION_PUSH \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wunused-function\"")
@@ -25,8 +25,6 @@
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
-#include <math.h>
-#include <time.h>
#ifdef AL_MEMORY_TRACKING
void al_malloc_init(void);
@@ -112,72 +110,15 @@ static inline void *al_memrchr(const void *s, s32 c, size_t n)
return NULL;
}
-AL_UNUSED_FUNCTION_POP
-#endif
-
-#ifndef LIKELY
-#ifdef AL_HAVE_BUILTIN_EXPECT
-#define LIKELY(x) __builtin_expect((x), 1)
-#else
-#define LIKELY(x) x
-#endif
-#endif
-
-#ifndef UNLIKELY
-#ifdef AL_HAVE_BUILTIN_EXPECT
-#define UNLIKELY(x) __builtin_expect((x), 0)
-#else
-#define UNLIKELY(x) x
-#endif
-#endif
-
-#if __GNUC__ >= 3
-#define AL_MAX(a, b) \
-({ \
- __typeof__(a) _a = a; \
- __typeof__(b) _b = b; \
- _a > _b ? _a : _b; \
-})
-#define AL_MIN(a, b) \
-({ \
- __typeof__(a) _a = a; \
- __typeof__(b) _b = b; \
- _a < _b ? _a : _b; \
-})
-#else
-#define AL_MAX(x, y) (((x) > (y)) ? (x) : (y))
-#define AL_MIN(x, y) (((x) < (y)) ? (x) : (y))
-#endif
-#define AL_CLAMP(n, lo, hi) AL_MIN(hi, AL_MAX(lo, n))
-
-#define AL_SWAP(a, b, type) do { \
- type tmp = a; \
- a = b; \
- b = tmp; \
-} while (0)
-
-#define AL_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-#define AL_BOOLSTR(b) ((b) ? "true" : "false")
-
-#ifndef _MSVC_
-#define __al_thread __thread
-#else
-#define __al_thread __declspec(thread)
-#endif
-
-#define __al_fallthrough __attribute__((fallthrough))
-
-#if __has_attribute(__counted_by__)
-#define __al_counted_by(member) __attribute__((__counted_by__(member)))
-#else
-#define __al_counted_by(member)
-#endif
+static inline char *al_memdup0(const char *s, size_t n)
+{
+ char *buf = (char *)al_malloc(n + 1);
+ al_memcpy(buf, s, n);
+ buf[n] = '\0';
+ return buf;
+}
-#if __has_attribute(__sized_by__)
-#define __al_sized_by(member) __attribute__((__sized_by__(member)))
-#else
-#define __al_sized_by(member)
+AL_UNUSED_FUNCTION_POP
#endif
AL_UNUSED_FUNCTION_PUSH
@@ -197,6 +138,26 @@ static inline bool al_isspace(char c)
return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
}
+static inline bool al_isupper(char c)
+{
+ return isupper(c);
+}
+
+static inline bool al_islower(char c)
+{
+ return islower(c);
+}
+
+static inline char al_tolower(char c)
+{
+ return al_isupper(c) ? c - 'A' + 'a' : c;
+}
+
+static inline char al_toupper(char c)
+{
+ return al_islower(c) ? c - 'a' + 'A' : c;
+}
+
static inline u32 al_u32_inc_wrap(u32 v)
{
return (v == UINT32_MAX) ? 0 : v + 1;
diff --git a/include/al/macros.h b/include/al/macros.h
new file mode 100644
index 0000000..b767191
--- /dev/null
+++ b/include/al/macros.h
@@ -0,0 +1,84 @@
+#ifndef _AL_MACROS_H
+#define _AL_MACROS_H
+
+#if defined LIKELY || defined UNLIKELY
+#error "Conflicting definitions for LIKELY/UNLIKELY"
+#endif
+
+#ifdef AL_HAVE_BUILTIN_EXPECT
+#define LIKELY(x) __builtin_expect((x), 1)
+#else
+#define LIKELY(x) x
+#endif
+
+#ifdef AL_HAVE_BUILTIN_EXPECT
+#define UNLIKELY(x) __builtin_expect((x), 0)
+#else
+#define UNLIKELY(x) x
+#endif
+
+#if defined MAX || defined MIN || defined CLAMP || defined SWAP || defined ARRAY_SIZE || defined BOOLSTR
+#error "Conflicting definitions for common macros"
+#endif
+
+#define MAX(a, b) \
+({ \
+ __typeof__(a) _a = a; \
+ __typeof__(b) _b = b; \
+ (void)(&_a == &_b); \
+ _a > _b ? _a : _b; \
+})
+
+#define MIN(a, b) \
+({ \
+ __typeof__(a) _a = a; \
+ __typeof__(b) _b = b; \
+ (void)(&_a == &_b); \
+ _a < _b ? _a : _b; \
+})
+
+#define CLAMP(n, lo, hi) MIN(hi, MAX(lo, n))
+
+#define SWAP(a, b) do { \
+ __typeof__(a) tmp = a; \
+ a = b; \
+ b = tmp; \
+} while (0)
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+#define BOOLSTR(b) ((b) ? "true" : "false")
+
+#if defined KB || defined MB || defined GB || defined TB || defined PB || defined EB
+#error "Conflicting definitions for byte size macros"
+#endif
+
+// http://www.blackbeltcoder.com/Articles/controls/precisely-defining-kilobytes-megabytes-and-gigabytes
+#define KB(n) (((u64)0x400)*((u64)(n)))
+#define MB(n) (((u64)0x100000)*((u64)(n)))
+#define GB(n) (((u64)0x40000000)*((u64)(n)))
+#define TB(n) (((u64)0x10000000000)*((u64)(n)))
+#define PB(n) (((u64)0x4000000000000)*((u64)(n)))
+#define EB(n) (((u64)0x1000000000000000)*((u64)(n)))
+
+#if defined __counted_by || defined __sized_by
+#error "Conflicting definitions for common attributes"
+#endif
+
+#if __has_attribute(__counted_by__)
+#define __counted_by(member) __attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+#if __has_attribute(__sized_by__)
+#define __sized_by(member) __attribute__((__sized_by__(member)))
+#else
+#define __sized_by(member)
+#endif
+
+#ifdef _MSVC_
+#define __thread __declspec(thread)
+#endif
+
+#endif // _AL_MACROS_H
diff --git a/include/al/random.h b/include/al/random.h
index 31da3f3..358a915 100644
--- a/include/al/random.h
+++ b/include/al/random.h
@@ -2,7 +2,8 @@
#define _AL_RANDOM_H
#include "lib.h"
-#include "atomic.h"
+
+#include <time.h>
#define AL_RAND_MAX RAND_MAX
@@ -18,16 +19,6 @@ static s32 al_rand(void)
return rand();
}
-// Each file that includes this header will have a separate counter.
-static atomic(u16) _al_inc_value = 0;
-
-// This is apart of random because currently al_inc_u16() is used as a substitute
-// for proper random id generation.
-static u16 al_inc_u16(void)
-{
- return al_atomic_add(u16)(&_al_inc_value, 1, AL_ATOMIC_RELEASE);
-}
-
AL_UNUSED_FUNCTION_POP
#endif // _AL_RANDOM_H
diff --git a/include/al/str.h b/include/al/str.h
index b06bf57..0878f5b 100644
--- a/include/al/str.h
+++ b/include/al/str.h
@@ -2,11 +2,12 @@
#define _AL_STR_H
#include "lib.h"
+#include "macros.h"
typedef struct {
u32 len;
u32 alloc;
- char *data;
+ char *__sized_by(alloc) data;
} str;
#define al_str_zero() (str){ 0, 0, NULL }
@@ -22,7 +23,7 @@ typedef struct {
#define AL_STR_FMT "%.*s"
#define AL_STR_PRINTF(s) (s)->len, (s)->data
-#define AL_STR_PRINTF_MAXLEN(s, l) AL_MIN((s)->len, (l)), (s)->data
+#define AL_STR_PRINTF_MAXLEN(s, l) MIN((s)->len, (l)), (s)->data
AL_UNUSED_FUNCTION_PUSH
@@ -79,7 +80,7 @@ static inline void al_str_from(str *s, const char *c_str)
static inline void al_str_to_lower(str *s)
{
for (u32 i = 0; i < s->len; i++) {
- al_str_at(s, i) = tolower(al_str_at(s, i));
+ al_str_at(s, i) = al_tolower(al_str_at(s, i));
}
}
@@ -123,7 +124,7 @@ static inline s32 al_str_cmp(str *s, str *c, u32 start, u32 len)
static inline bool al_str_eq(str *s, str *c)
{
- return al_str_cmp(s, c, 0, AL_MAX(s->len, c->len)) == 0;
+ return al_str_cmp(s, c, 0, MAX(s->len, c->len)) == 0;
}
static inline s32 al_str_find(str *s, char c)
diff --git a/include/al/types.h b/include/al/types.h
index cf3d0e8..fc2bb10 100644
--- a/include/al/types.h
+++ b/include/al/types.h
@@ -21,6 +21,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <float.h>
+#include <limits.h>
#include <sys/types.h>
typedef int8_t s8;
diff --git a/include/al/wstr.h b/include/al/wstr.h
index 8113575..444cc32 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -9,7 +9,7 @@
typedef struct {
u32 len;
u32 alloc;
- wchar_t *data;
+ wchar_t *__sized_by(alloc) data;
} wstr;
#define al_wstr_zero() (wstr){ 0, 0, NULL }
diff --git a/meson.build b/meson.build
index a05df28..d3d83e1 100644
--- a/meson.build
+++ b/meson.build
@@ -8,9 +8,10 @@ is_msvc_specifically = compiler.cmd_array()[0] == 'cl'
supports_needed_gnu_extensions = not is_msvc_specifically
+have_builtin_expect = compiler.has_function('__builtin_expect')
+have_typeof = compiler.has_function('__typeof__')
have_posix_memalign = compiler.has_function(
'posix_memalign', prefix: '#define _POSIX_C_SOURCE 200112L\n#include <stdlib.h>')
-have_builtin_expect = compiler.has_function('__builtin_expect')
have_wide_string = compiler.has_function('wcswidth')
alabaster_args = []
@@ -27,14 +28,14 @@ if supports_needed_gnu_extensions
alabaster_args += ['-DAL_HAVE_GNU_EXTENSIONS']
endif
-if have_posix_memalign
- alabaster_args += ['-DAL_HAVE_POSIX_MEMALIGN']
-endif
-
if have_builtin_expect
alabaster_args += ['-DAL_HAVE_BUILTIN_EXPECT']
endif
+if have_posix_memalign
+ alabaster_args += ['-DAL_HAVE_POSIX_MEMALIGN']
+endif
+
if have_wide_string
alabaster_args += ['-DAL_HAVE_WIDE_STRING']
endif
diff --git a/src/array.c b/src/array.c
index 9920267..40e5577 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1,4 +1,5 @@
#include "../include/al/lib.h"
+#include "../include/al/macros.h"
#include "../include/al/array_sort.h"
// https://github.com/lifthrasiir/angolmois/blob/master/angolmois.c#L79
@@ -8,7 +9,7 @@
struct { \
u32 size; \
u32 alloc; \
- type *__al_sized_by(alloc) data; \
+ type *__sized_by(alloc) data; \
}
#define al_array_init(arr) ((arr).size = 0, (arr).alloc = 0, (arr).data = NULL)
diff --git a/src/log.c b/src/log.c
index f9f4ba8..7bdba95 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,6 +1,6 @@
#include "../include/al/log.h"
-#define AL_LOG_SKIP
+//#define AL_LOG_SKIP
#define AL_LOG_USE_SECTION
#ifdef AL_LOG_USE_SECTION
#define AL_LOG_TEMPLATE "%s:%d %s(): %s -> (%s) "
@@ -11,11 +11,11 @@
#define AL_LOG_MESSAGE_MAX 511
#ifndef AL_LOG_SKIP
-static s32 al_print_default(void *userdata, char *s)
+static s32 al_print_default(void *userdata, char *message)
{
(void)userdata;
- s32 ret = al_printf("%*.*s\n", 0, AL_LOG_MESSAGE_MAX, s);
- al_free(s);
+ s32 ret = al_printf("%*.*s\n", 0, AL_LOG_MESSAGE_MAX, message);
+ al_free(message);
return ret;
}
diff --git a/src/ring_buffer.c b/src/ring_buffer.c
index adb22ad..a96584f 100644
--- a/src/ring_buffer.c
+++ b/src/ring_buffer.c
@@ -1,6 +1,6 @@
#include "../include/al/ring_buffer.h"
#include "../include/al/atomic.h"
-#include "../include/al/lib.h"
+#include "../include/al/macros.h"
// https://github.com/MusicPlayerDaemon/MPD/blob/master/src/util/RingBuffer.hxx
// https://andrea.lattuada.me/blog/2019/the-design-and-implementation-of-a-lock-free-ring-buffer-with-contiguous-reservations.html
@@ -71,13 +71,13 @@ size_t al_ring_buffer_write(struct al_ring_buffer *buf, u8 *data, size_t n)
u8 *wp = al_atomic_load(void)(&buf->write, AL_ATOMIC_ACQUIRE);
u8 *rp = previous(buf, al_atomic_load(void)(&buf->read, AL_ATOMIC_RELAXED));
- size_t size = AL_MIN((wp <= rp ? rp : buf->end) - wp, (ptrdiff_t)n);
+ size_t size = MIN((wp <= rp ? rp : buf->end) - wp, (ptrdiff_t)n);
al_memcpy(wp, data, size);
wp += size;
if (wp >= buf->end) {
- size_t wrap = AL_MIN(rp - buf->start, (ptrdiff_t)(n - size));
+ size_t wrap = MIN(rp - buf->start, (ptrdiff_t)(n - size));
al_memcpy(buf->start, data + size, wrap);
wp = buf->start + wrap;
size += wrap;
@@ -93,13 +93,13 @@ size_t al_ring_buffer_read(struct al_ring_buffer *buf, u8 *ptr, size_t n)
u8 *rp = al_atomic_load(void)(&buf->read, AL_ATOMIC_ACQUIRE);
u8 *wp = al_atomic_load(void)(&buf->write, AL_ATOMIC_RELAXED);
- size_t size = AL_MIN((rp <= wp ? wp : buf->end) - rp, (ptrdiff_t)n);
+ size_t size = MIN((rp <= wp ? wp : buf->end) - rp, (ptrdiff_t)n);
al_memcpy(ptr, rp, size);
rp += size;
if (rp >= buf->end) {
- size_t wrap = AL_MIN(wp - buf->start, (ptrdiff_t)(n - size));
+ size_t wrap = MIN(wp - buf->start, (ptrdiff_t)(n - size));
al_memcpy(ptr + size, buf->start, wrap);
rp = buf->start + wrap;
size += wrap;
@@ -119,12 +119,12 @@ size_t al_ring_buffer_peek(struct al_ring_buffer *buf, u8 *ptr, size_t offset, s
if (rp <= wp) {
rp += offset;
- size = AL_MIN(wp - rp, (ptrdiff_t)n);
+ size = MIN(wp - rp, (ptrdiff_t)n);
if (size < 0) return 0;
al_memcpy(ptr, rp, size);
} else {
rp += offset;
- size = AL_MIN(buf->end - rp, (ptrdiff_t)n);
+ size = MIN(buf->end - rp, (ptrdiff_t)n);
if (size > 0) {
al_memcpy(ptr, rp, size);
n -= size;
@@ -133,7 +133,7 @@ size_t al_ring_buffer_peek(struct al_ring_buffer *buf, u8 *ptr, size_t offset, s
rp = buf->start - size;
size = 0;
}
- ptrdiff_t wrap = AL_MIN(wp - rp, (ptrdiff_t)n);
+ ptrdiff_t wrap = MIN(wp - rp, (ptrdiff_t)n);
if (wrap > 0) {
al_memcpy(ptr + size, rp, wrap);
size += wrap;
@@ -148,11 +148,11 @@ size_t al_ring_buffer_discard(struct al_ring_buffer *buf, size_t n)
u8 *rp = al_atomic_load(void)(&buf->read, AL_ATOMIC_ACQUIRE);
u8 *wp = al_atomic_load(void)(&buf->write, AL_ATOMIC_RELAXED);
- size_t discard = AL_MIN((rp <= wp ? wp : buf->end) - rp, (ptrdiff_t)n);
+ size_t discard = MIN((rp <= wp ? wp : buf->end) - rp, (ptrdiff_t)n);
rp += discard;
if (rp >= buf->end) {
- size_t wrap = AL_MIN(wp - buf->start, (ptrdiff_t)(n - discard));
+ size_t wrap = MIN(wp - buf->start, (ptrdiff_t)(n - discard));
rp = buf->start + wrap;
discard += wrap;
}
diff --git a/tests/lib.c b/tests/lib.c
index aa66803..64f886d 100644
--- a/tests/lib.c
+++ b/tests/lib.c
@@ -30,6 +30,7 @@ static bool lib_test_add_wrap(void)
AL_TEST_END();
}
+/*
static bool lib_test_add_wrap_atomic(void)
{
AL_TEST_START("lib_add_wrap_atomic");
@@ -55,13 +56,14 @@ static bool lib_test_add_wrap_atomic(void)
AL_TEST_END();
}
+*/
bool lib_tests_run(void)
{
AL_TEST_START_GROUP("lib");
AL_TEST_RUN(lib_test_add_wrap);
- AL_TEST_RUN(lib_test_add_wrap_atomic);
+ //AL_TEST_RUN(lib_test_add_wrap_atomic);
AL_TEST_END_GROUP();
}
diff --git a/tests/str.c b/tests/str.c
index 4af5dc4..00d0c98 100644
--- a/tests/str.c
+++ b/tests/str.c
@@ -130,11 +130,11 @@ static bool str_test_get_line(void)
u32 c = 0;
for (; al_str_get_line(lines, '\n', &line); ) {
- AL_TEST_LT(c, (u32)AL_ARRAY_SIZE(lines_array), u32);
+ AL_TEST_LT(c, (u32)ARRAY_SIZE(lines_array), u32);
AL_TEST_TRUE(al_str_eq(&line, lines_array[c++]));
}
- AL_TEST_EQ(c, (u32)AL_ARRAY_SIZE(lines_array), u32);
+ AL_TEST_EQ(c, (u32)ARRAY_SIZE(lines_array), u32);
lines = al_str_c("");