diff --git a/README.rst b/README.rst index 9cb886a..78f96b2 100644 --- a/README.rst +++ b/README.rst @@ -3,8 +3,8 @@ Vanilla Squad ============= :Author: Daniel Walker -:Version: 5.2.2 -:Date: 2022-01-26 +:Version: 5.2.3 +:Date: 2022-01-31 Overview ======== diff --git a/changelog b/changelog index cc75057..e7622b0 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +5.2.3: + - Fixed the expansion of the logger macros when VASQ_NO_LOGGING is defined. + 5.2.2: - Fixed a typo in the VASQ_REALLOC macro definition for when VASQ_NO_LOGGING is defined. diff --git a/include/vasq/definitions.h b/include/vasq/definitions.h index 270f145..730f30d 100644 --- a/include/vasq/definitions.h +++ b/include/vasq/definitions.h @@ -9,7 +9,7 @@ /** * @brief Current version of the library. */ -#define VASQ_VERSION "5.2.2" +#define VASQ_VERSION "5.2.3" #ifndef NO_OP #define NO_OP ((void)0) diff --git a/include/vasq/logger.h b/include/vasq/logger.h index 76ebbe1..5fabeec 100644 --- a/include/vasq/logger.h +++ b/include/vasq/logger.h @@ -28,11 +28,11 @@ typedef enum vasqLogLevel { VASQ_LL_DEBUG, } vasqLogLevel_t; +#ifndef VASQ_NO_LOGGING + #define VASQ_CONTEXT_DECL const char *file_name, const char *function_name, unsigned int line_no #define VASQ_CONTEXT_PARAMS __FILE__, __func__, __LINE__ -#ifndef VASQ_NO_LOGGING - typedef struct vasqLogger vasqLogger; /* @@ -190,6 +190,74 @@ vasqSetLoggerUserData(vasqLogger *logger, void *user); void vasqLogStatement(const vasqLogger *logger, vasqLogLevel_t level, VASQ_CONTEXT_DECL, const char *format, ...); +/** + * @brief Emit a message at the ALWAYS level. + */ +#define VASQ_ALWAYS(logger, format, ...) \ + vasqLogStatement(logger, VASQ_LL_ALWAYS, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) + +/** + * @brief Emit a message at the CRITICAL level. + */ +#define VASQ_CRITICAL(logger, format, ...) \ + vasqLogStatement(logger, VASQ_LL_CRITICAL, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) + +/** + * @brief Emit a message at the ERROR level. + */ +#define VASQ_ERROR(logger, format, ...) \ + vasqLogStatement(logger, VASQ_LL_ERROR, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) + +/** + * @brief Emit a message at the WARNING level. + */ +#define VASQ_WARNING(logger, format, ...) \ + vasqLogStatement(logger, VASQ_LL_WARNING, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) + +/** + * @brief Emit a message at the INFO level. + */ +#define VASQ_INFO(logger, format, ...) \ + vasqLogStatement(logger, VASQ_LL_INFO, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) + +/** + * @brief Emit a message at the DEBUG level. + */ +#define VASQ_DEBUG(logger, format, ...) \ + vasqLogStatement(logger, VASQ_LL_DEBUG, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) + +/** + * @brief Logging equivalent of the perror function at the CRITICAL level. + * + * @param logger The logger handle. + * @param msg The argument that would normally be passed to perror. + * @param errnum The errno value. + * + * @warning msg must be a string literal and not a variable. + */ +#define VASQ_PCRITICAL(logger, msg, errnum) VASQ_CRITICAL(logger, msg ": %s", strerror(errnum)) +/** + * @brief Logging equivalent of the perror function at the ERROR level. + * + * @param logger The logger handle. + * @param msg The argument that would normally be passed to perror. + * @param errnum The errno value. + * + * @warning msg must be a string literal and not a variable. + */ +#define VASQ_PERROR(logger, msg, errnum) VASQ_ERROR(logger, msg ": %s", strerror(errnum)) + +/** + * @brief Logging equivalent of the perror function at the WARNING level. + * + * @param logger The logger handle. + * @param msg The argument that would normally be passed to perror. + * @param errnum The errno value. + * + * @warning msg must be a string literal and not a variable. + */ +#define VASQ_PWARNING(logger, msg, errnum) VASQ_WARNING(logger, msg ": %s", strerror(errnum)) + /** * @brief Same as vasqLogStatement but takes a va_list instead of variable arguments. */ @@ -226,6 +294,11 @@ vasqVRawLog(const vasqLogger *logger, const char *format, va_list args); void vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const void *data, size_t size); +/** + * @brief Wrap vasqHexDump by automatically supplying the file name, function name, and line number. + */ +#define VASQ_HEXDUMP(logger, name, data, size) vasqHexDump(logger, VASQ_CONTEXT_PARAMS, name, data, size) + /** * @brief Wrap malloc. * @@ -242,6 +315,11 @@ vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const void * vasqMalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t size); +/** + * @brief Wrap vasqMalloc by automatically supplying the file name, function name, and line number. + */ +#define VASQ_MALLOC(logger, size) vasqMalloc(logger, VASQ_CONTEXT_PARAMS, size) + /** * @brief Wrap calloc. * @@ -259,6 +337,11 @@ vasqMalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t size); void * vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t size); +/** + * @brief Wrap vasqCalloc by automatically supplying the file name, function name, and line number. + */ +#define VASQ_CALLOC(logger, nmemb, size) vasqCalloc(logger, VASQ_CONTEXT_PARAMS, nmemb, size) + /** * @brief Wrap realloc. * @@ -276,6 +359,11 @@ vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t siz void * vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size); +/** + * @brief Wrap vasqRealloc by automatically supplying the file name, function name, and line number. + */ +#define VASQ_REALLOC(logger, ptr, size) vasqRealloc(logger, VASQ_CONTEXT_PARAMS, ptr, size) + /** * @brief Wrap fork. * @@ -292,6 +380,11 @@ vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size) pid_t vasqFork(const vasqLogger *logger, VASQ_CONTEXT_DECL); +/** + * @brief Wrap vasqFork by automatically supplying the file name, function name, and line number. + */ +#define VASQ_FORK(logger) vasqFork(logger, VASQ_DECL_PARAMS) + /** * @brief Wrap exit or _exit. * @@ -308,12 +401,25 @@ vasqFork(const vasqLogger *logger, VASQ_CONTEXT_DECL); void vasqExit(vasqLogger *logger, VASQ_CONTEXT_DECL, int value, bool quick) __attribute__((noreturn)); +/** + * @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting + * quick to false. + */ +#define VASQ_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, false) + +/** + * @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting + * quick to true. + */ +#define VASQ_QUICK_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, true) + #else // VASQ_NO_LOGGING #define vasqLoggerCreate(...) VASQ_RET_OK #define vasqLoggerFree(logger) NO_OP #define vasqLoggerFd(logger) -1 #define vasqSetLoggerFormat(logger, format) true +#define vasqLoggerLevel(logger) VASQ_LL_NONE #define vasqsetLoggerLevel(logger, level) NO_OP #define vasqSetLoggerProcessor(logger, processor) NO_OP #define vasqLoggerUserData(logger) NULL @@ -321,123 +427,31 @@ vasqExit(vasqLogger *logger, VASQ_CONTEXT_DECL, int value, bool quick) __attribu #define vasqLogStatement(...) NO_OP #define vasqVLogStatement(...) NO_OP +#define VASQ_ALWAYS(...) NO_OP +#define VASQ_CRITICAL(...) NO_OP +#define VASQ_ERROR(...) NO_OP +#define VASQ_WARNING(...) NO_OP +#define VASQ_INFO(...) NO_OP +#define VASQ_DEBUG(...) NO_OP #define vasqRawLog(...) NO_OP #define vasqVRawLog(...) NO_OP #define vasqHexDump(...) NO_OP +#define VASQ_HEXDUMP(...) NO_OP #define vasqMalloc(logger, file, func, line, size) malloc(size) +#define VASQ_MALLOC(logger, size) malloc(size) #define vasqCalloc(logger, file, func, line, nmemb, size) calloc(nmemb, size) +#define VASQ_CALLOC(logger, nmemb, size) calloc(nmemb, size) #define vasqRealloc(logger, file, func, line, ptr, size) realloc(ptr, size) +#define VASQ_REALLOC(logger, ptr, size) realloc(ptr, size) #define vasqFork(...) fork() +#define VASQ_FORK() fork() #define vasqExit(logger, file, func, line, value, quick) (((quick) ? _exit : exit)(value)) +#define VASQ_EXIT(logger, value) exit(value) +#define VASQ_QUICK_EXIT(logger, value) _exit(value) #endif // VASQ_NO_LOGGING -/** - * @brief Emit a message at the ALWAYS level. - */ -#define VASQ_ALWAYS(logger, format, ...) \ - vasqLogStatement(logger, VASQ_LL_ALWAYS, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) - -/** - * @brief Emit a message at the CRITICAL level. - */ -#define VASQ_CRITICAL(logger, format, ...) \ - vasqLogStatement(logger, VASQ_LL_CRITICAL, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) - -/** - * @brief Emit a message at the ERROR level. - */ -#define VASQ_ERROR(logger, format, ...) \ - vasqLogStatement(logger, VASQ_LL_ERROR, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) - -/** - * @brief Emit a message at the WARNING level. - */ -#define VASQ_WARNING(logger, format, ...) \ - vasqLogStatement(logger, VASQ_LL_WARNING, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) - -/** - * @brief Emit a message at the INFO level. - */ -#define VASQ_INFO(logger, format, ...) \ - vasqLogStatement(logger, VASQ_LL_INFO, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) - -/** - * @brief Emit a message at the DEBUG level. - */ -#define VASQ_DEBUG(logger, format, ...) \ - vasqLogStatement(logger, VASQ_LL_DEBUG, VASQ_CONTEXT_PARAMS, format, ##__VA_ARGS__) - -/** - * @brief Logging equivalent of the perror function at the CRITICAL level. - * - * @param logger The logger handle. - * @param msg The argument that would normally be passed to perror. - * @param errnum The errno value. - * - * @warning msg must be a string literal and not a variable. - */ -#define VASQ_PCRITICAL(logger, msg, errnum) VASQ_CRITICAL(logger, msg ": %s", strerror(errnum)) -/** - * @brief Logging equivalent of the perror function at the ERROR level. - * - * @param logger The logger handle. - * @param msg The argument that would normally be passed to perror. - * @param errnum The errno value. - * - * @warning msg must be a string literal and not a variable. - */ -#define VASQ_PERROR(logger, msg, errnum) VASQ_ERROR(logger, msg ": %s", strerror(errnum)) - -/** - * @brief Logging equivalent of the perror function at the WARNING level. - * - * @param logger The logger handle. - * @param msg The argument that would normally be passed to perror. - * @param errnum The errno value. - * - * @warning msg must be a string literal and not a variable. - */ -#define VASQ_PWARNING(logger, msg, errnum) VASQ_WARNING(logger, msg ": %s", strerror(errnum)) - -/** - * @brief Wrap vasqHexDump by automatically supplying the file name, function name, and line number. - */ -#define VASQ_HEXDUMP(logger, name, data, size) vasqHexDump(logger, VASQ_CONTEXT_PARAMS, name, data, size) - -/** - * @brief Wrap vasqMalloc by automatically supplying the file name, function name, and line number. - */ -#define VASQ_MALLOC(logger, size) vasqMalloc(logger, VASQ_CONTEXT_PARAMS, size) - -/** - * @brief Wrap vasqCalloc by automatically supplying the file name, function name, and line number. - */ -#define VASQ_CALLOC(logger, nmemb, size) vasqCalloc(logger, VASQ_CONTEXT_PARAMS, nmemb, size) - -/** - * @brief Wrap vasqRealloc by automatically supplying the file name, function name, and line number. - */ -#define VASQ_REALLOC(logger, ptr, size) vasqRealloc(logger, VASQ_CONTEXT_PARAMS, ptr, size) - -/** - * @brief Wrap vasqFork by automatically supplying the file name, function name, and line number. - */ -#define VASQ_FORK(logger) vasqFork(logger, VASQ_DECL_PARAMS) - -/** - * @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting - * quick to false. - */ -#define VASQ_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, false) - -/** - * @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting - * quick to true. - */ -#define VASQ_QUICK_EXIT(logger, value) vasqExit(logger, VASQ_CONTEXT_PARAMS, value, true) - #ifdef DEBUG #ifdef VASQ_TEST_ASSERT