summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2024-10-29 17:19:47 -0400
committerAndrew Opalach <andrew@akon.city> 2024-10-29 17:19:47 -0400
commita8bd86763e3db5c4320bfaf6684a803026213968 (patch)
tree7de30ae5b8d9dff44ae262f4ccfd6d6af2099bd0 /src
parent736f15908cf34a851140094897a13ff12d55fd0c (diff)
downloadlibalabaster-a8bd86763e3db5c4320bfaf6684a803026213968.tar.gz
libalabaster-a8bd86763e3db5c4320bfaf6684a803026213968.tar.bz2
libalabaster-a8bd86763e3db5c4320bfaf6684a803026213968.zip
all: Undo previous #ifdef style change
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
-rw-r--r--src/array.c6
-rw-r--r--src/lib.c26
-rw-r--r--src/log.c24
3 files changed, 27 insertions, 29 deletions
diff --git a/src/array.c b/src/array.c
index 2b06d23..9920267 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1,7 +1,3 @@
-#if !defined AL_ARRAY_MALLOC || !defined AL_ARRAY_REALLOC || !defined AL_ARRAY_FREE
-#error "define all of AL_ARRAY_MALLOC, AL_ARRAY_REALLOC, and AL_ARRAY_FREE before including array.c"
-#endif
-
#include "../include/al/lib.h"
#include "../include/al/array_sort.h"
@@ -83,7 +79,7 @@
(arr).size -= e - i; \
} while (0)
-#if AL_USE_STDLIB
+#ifdef AL_USE_STDLIB
#define al_array_sort(arr, type, cmp) AL_STDLIB_QSORT((arr).data, type, (arr).size, cmp)
#else
#define al_array_sort(arr, type, cmp) AL_INSERSION_SORT((arr).data, type, (arr).size, cmp)
diff --git a/src/lib.c b/src/lib.c
index 8f67be3..956c9b7 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -7,18 +7,18 @@
AL_ASSERT_TYPE_SIZE(int, 4);
AL_ASSERT_TYPE_SIZE(unsigned, 4);
-#if AL_USE_STDLIB
+#ifdef AL_USE_STDLIB
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;
-#if defined AL_HAVE_POSIX_MEMALIGN
+#ifdef AL_HAVE_POSIX_MEMALIGN
s32 (*_al_posix_memalign)(void **, size_t, size_t) = posix_memalign;
#endif
// Testing allocation tracking stuff (Very scuffed, not thread-safe!).
-#define AL_MEMORY_TRACKING 0
-#if AL_MEMORY_TRACKING
+//#define AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
struct alloc_t {
void *ptr;
size_t size;
@@ -41,14 +41,14 @@ static u32 total_allocated = 0;
void al_malloc_init(void)
{
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
al_array_init(allocations);
#endif
}
void al_malloc_close(void)
{
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
al_array_free(allocations);
#endif
}
@@ -56,7 +56,7 @@ void al_malloc_close(void)
void *al_malloc(size_t n)
{
void *ptr = _al_malloc(n);
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
printf("**al_malloc(%zu)\n", n);
struct alloc_t a = {
.ptr = ptr,
@@ -75,7 +75,7 @@ void *al_malloc(size_t n)
void *al_calloc(size_t n, size_t size)
{
void *ptr = _al_calloc(n, size);
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
printf("**al_calloc(%zu, %zu)\n", n, size);
struct alloc_t a = {
.ptr = ptr,
@@ -94,7 +94,7 @@ void *al_calloc(size_t n, size_t size)
void *al_realloc(void *ptr, size_t n)
{
void *nptr = _al_realloc(ptr, n);
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
printf("**al_realloc(%p, %zu)\n", ptr, n);
for (u32 i = 0; i < allocations.size; i++) {
struct alloc_t *a = &al_array_at(allocations, i);
@@ -125,7 +125,7 @@ void *al_realloc(void *ptr, size_t n)
void al_free(void *ptr)
{
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
printf("**al_free(%p)\n", ptr);
for (u32 i = 0; i < allocations.size; i++) {
struct alloc_t *a = &al_array_at(allocations, i);
@@ -139,11 +139,11 @@ void al_free(void *ptr)
_al_free(ptr);
}
-#if defined AL_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);
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
size_t actual_size = (n + alignment) - ((n + alignment) % alignment);
printf("**al_posix_memalign(%zu, %zu(%zu))\n", alignment, n, actual_size);
struct alloc_t a = {
@@ -163,7 +163,7 @@ s32 al_posix_memalign(void **ptr, size_t alignment, size_t n)
void al_malloc_stats(u32 *current, u32 *peak, u32 *total)
{
-#if AL_MEMORY_TRACKING
+#ifdef AL_MEMORY_TRACKING
*current = currently_allocated;
*peak = peak_allocated;
*total = total_allocated;
diff --git a/src/log.c b/src/log.c
index c64ca11..f9f4ba8 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,8 +1,8 @@
#include "../include/al/log.h"
-#define AL_LOG_SKIP 0
-#define AL_LOG_USE_SECTION 1
-#if AL_LOG_USE_SECTION
+#define AL_LOG_SKIP
+#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 -> "
@@ -10,7 +10,7 @@
#define AL_LOG_MESSAGE_MAX 511
-#if !AL_LOG_SKIP
+#ifndef AL_LOG_SKIP
static s32 al_print_default(void *userdata, char *s)
{
(void)userdata;
@@ -28,10 +28,11 @@ void al_set_print(s32 (*print_func)(void *, char *), void *userdata)
_al_log_userdata = userdata;
}
+#ifndef AL_FORCE_DISABLE_OUTPUT
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_malloc(AL_LOG_MESSAGE_MAX + 1);
-#if AL_LOG_USE_SECTION
+#ifdef AL_LOG_USE_SECTION
s32 prefix = al_snprintf(buffer, AL_LOG_MESSAGE_MAX, AL_LOG_TEMPLATE, name, line, func, level, section);
#else
(void)section;
@@ -41,13 +42,14 @@ static char *get_buffer(const char *level, const char *section, const char *fmt,
buffer[strcspn(buffer, "\r\n")] = '\0';
return buffer;
}
+#endif
#else
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, ...)
{
-#if AL_FORCE_DISABLE_OUTPUT
+#ifdef AL_FORCE_DISABLE_OUTPUT
(void)level;
(void)section;
(void)name;
@@ -59,7 +61,7 @@ s32 _al_log(const char *level, const char *section, const char *name, const s32
va_list args;
va_start(args, fmt);
if (!section) section = "";
-#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");
@@ -67,7 +69,7 @@ s32 _al_log(const char *level, const char *section, const char *name, const s32
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);
@@ -77,7 +79,7 @@ s32 _al_log(const char *level, const char *section, const char *name, const s32
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
+#ifdef AL_FORCE_DISABLE_OUTPUT
(void)level;
(void)section;
(void)name;
@@ -88,14 +90,14 @@ s32 _al_logv(const char *level, const char *section, const char *name, const s32
return 0;
#else
if (!section) section = "";
-#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);