Buildsystem: Removed include/basalt_window.h. See prior commit #cac50b01

Library:
Added logging and memory modules.
The logging module provides a flexible interface for adding and removing logging streams (think stdout, stderr, a file) and supports ANSI colouring and including the date and time of each log call. Its header also provides several definitions for assertions, each corresponding to a specific log level and some other side effects such as debug_break(), returning, exiting or doing nothing.
The memory module wraps (_)aligned_alloc and free functions and includes memory tagging by class and location and the ability to fetch a formatted string containing this information. This can allow you to narrow down where memory leaks and double frees occur to particular sections within a module. Memory can be aligned to any, 32, 64 or 4096 byte boundaries using this module.
This commit is contained in:
2025-06-22 03:02:42 +10:00
parent cac50b0134
commit 8d7bfe0bc9
5 changed files with 600 additions and 29 deletions

View File

@@ -0,0 +1,94 @@
#pragma once
#include "basalt_defines.h"
#include <stdio.h>
#include <stdlib.h>
#ifndef BASALT_LOGGER_MAX_STREAMS
#define BASALT_LOGGER_MAX_STREAMS 7
#endif
typedef enum LOG_LEVEL {
LOG_FATAL = 1,
LOG_ERROR = 2,
LOG_WARN = 4,
LOG_INFO = 8,
LOG_OK = 16,
LOG_WEIRD = 32,
LOG_DEBUG = 64,
LOG_TRACE = 128,
LOG_MASK_ERRORS = LOG_FATAL | LOG_ERROR,
LOG_MASK_DEBUGGING = LOG_WEIRD | LOG_DEBUG | LOG_TRACE,
LOG_MASK_INFO = LOG_WARN | LOG_INFO | LOG_OK,
LOG_MASK_ALL = LOG_MASK_ERRORS | LOG_MASK_DEBUGGING | LOG_MASK_INFO,
LOG_MASK_DEFAULT = LOG_MASK_ERRORS | LOG_MASK_INFO,
} LOG_LEVEL;
typedef enum LOG_STREAM_FLAGS {
// Ignore this flag - it is internal to the library
LOG_STREAM_FLAG_INTERNAL_ALLOCATED_BIT = 1,
LOG_STREAM_FLAG_SUPPORTS_ANSI_BIT = 2,
LOG_STREAM_FLAG_INCLUDE_DATETIME_BIT = 4,
LOG_STREAM_FLAG_DISABLE_PREFIXES = 8,
} LOG_STREAM_BIT_FLAGS;
typedef struct logger_stream_t {
u64 stream : 48;
u64 mask : 8 ;
u64 flags : 8 ;
} logger_stream_t;
void initialize_logger();
void terminate_logger ();
FILE* logger_stream_get_file(logger_stream_t* state);
u8 logger_add_stream(FILE* output, LOG_LEVEL mask, LOG_STREAM_FLAGS flags);
void logger_remove_stream(u8 index);
u8 logger_find_stream(FILE* target);
void basalt_log(const LOG_LEVEL level, const char* msg, ...);
void basalt_write(const LOG_LEVEL level, const char* msg, ...);
#define BFATAL(msg, ...) basalt_log(LOG_FATAL, msg, ##__VA_ARGS__);
#define BERROR(msg, ...) basalt_log(LOG_ERROR, msg, ##__VA_ARGS__);
#define BWARN(msg, ...) basalt_log(LOG_WARN, msg, ##__VA_ARGS__);
#define BINFO(msg, ...) basalt_log(LOG_INFO, msg, ##__VA_ARGS__);
#define BOK(msg, ...) basalt_log(LOG_OK, msg, ##__VA_ARGS__);
#define BWEIRD(msg, ...) basalt_log(LOG_WEIRD, msg, ##__VA_ARGS__);
#define BDEBUG(msg, ...) basalt_log(LOG_DEBUG, msg, ##__VA_ARGS__);
#define BTRACE(msg, ...) basalt_log(LOG_TRACE, msg, ##__VA_ARGS__);
#define BASSERT_FATAL(cond, msg, ...) \
if (cond){} \
else { \
BFATAL(msg, #cond, __FILE__, __LINE__, ##__VA_ARGS__); \
debug_break(); \
exit(-1); \
}
#define BASSERT_ERROR(cond, ret, msg, ...) \
if (cond){} \
else { \
BERROR(msg, #cond, __FILE__, __LINE__, ##__VA_ARGS__); \
ret \
}
#define BASSERT_WARN(cond, msg, ...) \
if (cond){} \
else { \
BWARN(msg, #cond, __FILE__, __LINE__, ##__VA_ARGS__); \
}
#ifdef BDEBUG
#define BASSERT_WEIRD(cond, msg, ...) \
if (cond){} \
else { \
BWEIRD(msg, #cond, __FILE__, __LINE__, ##__VA_ARGS__); \
}
#define BASSERT_DEBUG(cond, msg, ...) \
if (cond){} \
else { \
BFATAL(msg, #cond, __FILE__, __LINE__, ##__VA_ARGS__); \
debug_break(); \
}
#else
#define BASSERT_WEIRD(cond, msg, ...)
#define BASSERT_DEBUG(cond, msg, ...)
#endif