From b3bd3df103a5a75d267b2b79e85558768b1dc4bb Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sun, 23 Mar 2025 22:11:15 -0500 Subject: Fix a whole bunch of shit, create an arena implementation --- src/shared.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/shared.h') diff --git a/src/shared.h b/src/shared.h index 3c23676..ee3e06b 100644 --- a/src/shared.h +++ b/src/shared.h @@ -2,9 +2,8 @@ #define __VXGG_REWRITE___SHARED_H___3880294315821___ #include -#include -#define STATICARR_SIZE(arr) (sizeof((arr))/sizeof((arr)[0])) +#define STATIC_ARRAY_LEN(arr) (sizeof((arr))/sizeof((arr)[0])) // Defines how `x___alloc()` functions should exit. `___VXGG___XALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions // registered with `atexit()` and `on_exit()`. `___VXGG___XALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `x___alloc()` @@ -15,6 +14,16 @@ // `___VXGG___VERBOSE_ERRORS___ > 0` will print diagnostic error messages, and will do nothing otherwise #define ___VXGG___VERBOSE_ERRORS___ 1 +// Macro to exit on an alloc error instead of doing the terrible nested if statement that was being used previously +#define XALLOC_EXIT(msg, ...) do {\ + if(!___VXGG___XALLOC_EXIT_ON_ERROR___)\ + abort();\ + if(!___VXGG___VERBOSE_ERRORS___)\ + exit(EXIT_FAILURE);\ + error(EXIT_FAILURE, errno, (msg)__VA_ARGS__);\ + exit(EXIT_FAILURE); /* Makes gcc happy */\ +} while (0) + // `calloc()` with error checking. Calls `error()` or `abort()` on error, depending on the value of `___VXGG___XALLOC_EXIT_ON_ERROR___` void* xcalloc(size_t nmemb, size_t size); -- cgit v1.2.3