From 7f7566324b18833d2868ea45e2b28dcdc547d879 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Tue, 9 Apr 2024 11:17:46 -0400 Subject: Update - Separate al_str_c functions between compile-time and runtime - Remove volatile from atomics - Allow not specifying a section in the log - Cleanup Signed-off-by: Andrew Opalach --- src/lib.c | 4 ++-- src/log.c | 31 +++++++++++++++++++------------ src/ring_buffer.c | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/lib.c b/src/lib.c index 64a60a3..8838495 100644 --- a/src/lib.c +++ b/src/lib.c @@ -7,7 +7,7 @@ static void *(*_al_malloc)(size_t) = malloc; static void *(*_al_calloc)(size_t, size_t) = calloc; static void *(*_al_realloc)(void *, size_t) = realloc; static void (*_al_free)(void *) = free; -#ifdef HAVE_POSIX_MEMALIGN +#ifdef AL_HAVE_POSIX_MEMALIGN s32 (*_al_posix_memalign)(void **, size_t, size_t) = posix_memalign; #endif @@ -134,7 +134,7 @@ void al_free(void *ptr) _al_free(ptr); } -#ifdef HAVE_POSIX_MEMALIGN +#ifdef AL_HAVE_POSIX_MEMALIGN s32 al_posix_memalign(void **ptr, size_t alignment, size_t n) { s32 res = _al_posix_memalign(ptr, alignment, n); diff --git a/src/log.c b/src/log.c index 5c41248..370df07 100644 --- a/src/log.c +++ b/src/log.c @@ -1,10 +1,15 @@ #include "../include/al/log.h" -#define AL_LOG_SKIP 0 +#define AL_LOG_SKIP #define AL_LOG_MESSAGE_SIZE 511 +#define AL_LOG_USE_SECTION +#ifdef AL_LOG_USE_SECTION #define AL_LOG_TEMPLATE "%s:%d %s(): %s -> (%s) " +#else +#define AL_LOG_TEMPLATE "%s:%d %s(): %s -> " +#endif -#if !AL_LOG_SKIP +#ifndef AL_LOG_SKIP static s32 al_print_default(void *userdata, char *s) { (void)userdata; @@ -22,11 +27,15 @@ void al_set_print(s32 (*print_func)(void *, char *), void *userdata) _al_log_userdata = userdata; } -static char *get_buffer(const char *level, const char *section, const char *fmt, const char *name, - const s32 line, const char *func, va_list args) +static char *get_buffer(const char *level, const char *section, const char *fmt, const char *name, const s32 line, const char *func, va_list args) { char *buffer = al_calloc(1, AL_LOG_MESSAGE_SIZE + 1); +#ifdef AL_LOG_USE_SECTION s32 prefix = snprintf(buffer, AL_LOG_MESSAGE_SIZE, AL_LOG_TEMPLATE, name, line, func, level, section); +#else + (void)section; + s32 prefix = snprintf(buffer, AL_LOG_MESSAGE_SIZE, AL_LOG_TEMPLATE, name, line, func, level); +#endif prefix += vsnprintf(buffer + prefix, AL_LOG_MESSAGE_SIZE - prefix, fmt, args); buffer[strcspn(buffer, "\r\n")] = '\0'; return buffer; @@ -35,15 +44,14 @@ static char *get_buffer(const char *level, const char *section, const char *fmt, void al_set_print(s32 (*print_func)(void *, char *), void *userdata) { (void)print_func; (void)userdata; } #endif -s32 _al_log(const char *level, const char *section, const char *name, - const s32 line, const char *func, const char *fmt, ...) +s32 _al_log(const char *level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, ...) { #if AL_FORCE_DISABLE_OUTPUT return 0; #else va_list args; va_start(args, fmt); -#if AL_LOG_SKIP +#ifdef AL_LOG_SKIP s32 ret = al_printf(AL_LOG_TEMPLATE, name, line, func, level, section); ret += al_vprintf(fmt, args); if (strcspn(fmt, "\r\n") == al_strlen(fmt)) ret += al_printf("\n"); @@ -51,7 +59,7 @@ s32 _al_log(const char *level, const char *section, const char *name, char *buffer = get_buffer(level, section, fmt, name, line, func, args); #endif va_end(args); -#if AL_LOG_SKIP +#ifdef AL_LOG_SKIP return ret; #else return _al_print(_al_log_userdata, buffer); @@ -59,20 +67,19 @@ s32 _al_log(const char *level, const char *section, const char *name, #endif } -s32 _al_logv(const char *level, const char *section, const char *name, - const s32 line, const char *func, const char *fmt, va_list args) +s32 _al_logv(const char *level, const char *section, const char *name, const s32 line, const char *func, const char *fmt, va_list args) { #if AL_FORCE_DISABLE_OUTPUT return 0; #else -#if AL_LOG_SKIP +#ifdef AL_LOG_SKIP s32 ret = al_printf(AL_LOG_TEMPLATE, name, line, func, level, section); ret += al_vprintf(fmt, args); if (strcspn(fmt, "\r\n") == al_strlen(fmt)) ret += al_printf("\n"); #else char *buffer = get_buffer(level, section, fmt, name, line, func, args); #endif -#if AL_LOG_SKIP +#ifdef AL_LOG_SKIP return ret; #else return _al_print(_al_log_userdata, buffer); diff --git a/src/ring_buffer.c b/src/ring_buffer.c index 751ea4a..c985d86 100644 --- a/src/ring_buffer.c +++ b/src/ring_buffer.c @@ -18,7 +18,7 @@ static inline u8 *previous(struct al_ring_buffer *buf, u8 *ptr) return --ptr; } -static inline void add(struct al_ring_buffer *buf, volatile u8 **v, u8 *ptr, size_t n) +static inline void add(struct al_ring_buffer *buf, u8 **v, u8 *ptr, size_t n) { ptr += n; al_assert(ptr <= buf->end); -- cgit v1.2.3-101-g0448