summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-04-09 11:17:46 -0400
committerAndrew Opalach <andrew@akon.city> 2024-04-09 11:17:46 -0400
commit7f7566324b18833d2868ea45e2b28dcdc547d879 (patch)
tree952b6ef9e391e6a3dca1a4337a023e83b1f92b7e /src
parent4da4b06c8ae79370340a60ca83bd1f0206068ed3 (diff)
downloadlibalabaster-7f7566324b18833d2868ea45e2b28dcdc547d879.tar.gz
libalabaster-7f7566324b18833d2868ea45e2b28dcdc547d879.tar.bz2
libalabaster-7f7566324b18833d2868ea45e2b28dcdc547d879.zip
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 <andrew@akon.city>
Diffstat (limited to 'src')
-rw-r--r--src/lib.c4
-rw-r--r--src/log.c31
-rw-r--r--src/ring_buffer.c2
3 files changed, 22 insertions, 15 deletions
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);