Skip to content

Commit

Permalink
added format __attribute__s to various functions and placed __GNUC__ …
Browse files Browse the repository at this point in the history
…preprocessor guards around the attributes; changed the version to 6.0.4
  • Loading branch information
nickeldan committed Aug 22, 2022
1 parent c028721 commit 3ffdeb3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ endif

all: _all

BUILD_DEPS :=
ifeq ($(MAKECMDGOALS),clean)
else ifeq ($(MAKECMDGOALS),format)
else
BUILD_DEPS := yes
endif

VASQ_DIR := .
include make.mk

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Vanilla Squad
=============

:Author: Daniel Walker
:Version: 6.0.3
:Date: 2022-08-16
:Version: 6.0.4
:Date: 2022-08-21

Overview
========
Expand Down
5 changes: 5 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
6.0.4:
- Added the format __attribute__ to several printf-like functions.
- Added the BUILD_DEPS variable to make.mk.
- deps.mk is now written to VASQ_OBJ_DIR.

6.0.3.:
- Deprecated various logging wrapper functions such as vasqMalloc.
- Added the use of LDFLAGS and VASQ_OBJ_DIR to make.mk.
Expand Down
2 changes: 1 addition & 1 deletion include/vasq/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @brief Current version of the library.
*/
#define VASQ_VERSION "6.0.3"
#define VASQ_VERSION "6.0.4"

#ifndef NO_OP
#define NO_OP ((void)0)
Expand Down
50 changes: 40 additions & 10 deletions include/vasq/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ vasqSetLoggerUserData(vasqLogger *logger, void *user);
* @param format A format string (corresponding to vasqSafeSnprintf's syntax) for the the message.
*/
void
vasqLogStatement(const vasqLogger *logger, vasqLogLevel_t level, VASQ_CONTEXT_DECL, const char *format, ...);
vasqLogStatement(const vasqLogger *logger, vasqLogLevel_t level, VASQ_CONTEXT_DECL, const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 6, 7)))
#endif
;

/**
* @brief Emit a message at the ALWAYS level.
Expand Down Expand Up @@ -273,7 +277,11 @@ vasqVLogStatement(const vasqLogger *logger, vasqLogLevel_t level, VASQ_CONTEXT_D
* @param format A format string (corresponding to vasqSafeSnprintf's syntax) for the the message.
*/
void
vasqRawLog(const vasqLogger *logger, const char *format, ...);
vasqRawLog(const vasqLogger *logger, const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;

/**
* @brief Same as vasqRawLog but takes a va_list insead of variable arguments.
Expand Down Expand Up @@ -313,7 +321,12 @@ vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const
*
* @return The same return value as malloc.
*/
void *__attribute__((deprecated)) vasqMalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t size);
void *
vasqMalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t size)
#ifdef __GNUC__
__attribute__((deprecated))
#endif
;

/**
* @brief Wrap vasqMalloc by automatically supplying the file name, function name, and line number.
Expand All @@ -334,8 +347,12 @@ void *__attribute__((deprecated)) vasqMalloc(const vasqLogger *logger, VASQ_CONT
*
* @return The same return value as calloc.
*/
void *__attribute__((deprecated))
vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t size);
void *
vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t size)
#ifdef __GNUC__
__attribute__((deprecated))
#endif
;

/**
* @brief Wrap vasqCalloc by automatically supplying the file name, function name, and line number.
Expand All @@ -356,8 +373,12 @@ vasqCalloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, size_t nmemb, size_t siz
*
* @return The same return value as realloc.
*/
void *__attribute__((deprecated))
vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size);
void *
vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size)
#ifdef __GNUC__
__attribute__((deprecated))
#endif
;

/**
* @brief Wrap vasqRealloc by automatically supplying the file name, function name, and line number.
Expand All @@ -377,7 +398,12 @@ vasqRealloc(const vasqLogger *logger, VASQ_CONTEXT_DECL, void *ptr, size_t size)
*
* @return The same return value as fork.
*/
pid_t __attribute__((deprecated)) vasqFork(const vasqLogger *logger, VASQ_CONTEXT_DECL);
pid_t
vasqFork(const vasqLogger *logger, VASQ_CONTEXT_DECL)
#ifdef __GNUC__
__attribute__((deprecated))
#endif
;

/**
* @brief Wrap vasqFork by automatically supplying the file name, function name, and line number.
Expand All @@ -397,8 +423,12 @@ pid_t __attribute__((deprecated)) vasqFork(const vasqLogger *logger, VASQ_CONTEX
* @param value The value passed to exit/_exit.
* @param quick If true, _exit is called. Otherwise, exit is called.
*/
void __attribute__((deprecated)) vasqExit(vasqLogger *logger, VASQ_CONTEXT_DECL, int value, bool quick)
__attribute__((noreturn));
void
vasqExit(vasqLogger *logger, VASQ_CONTEXT_DECL, int value, bool quick)
#ifdef __GNUC__
__attribute__((noreturn)) __attribute__((deprecated))
#endif
;

/**
* @brief Wrap vasqExit by automatically supplying the file name, function name, and line number and setting
Expand Down
12 changes: 10 additions & 2 deletions include/vasq/safe_snprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
* buffer or format is NULL or if size is 0, then -1 is returned.
*/
ssize_t
vasqSafeSnprintf(char *buffer, size_t size, const char *format, ...);
vasqSafeSnprintf(char *buffer, size_t size, const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
#endif
;

/**
* @brief Same as vasqSafeSnprintf but takes a va_list instead of variable arguments.
Expand All @@ -49,7 +53,11 @@ vasqSafeVsnprintf(char *buffer, size_t size, const char *format, va_list args);
* @return Same as for vasqSafeSnprintf.
*/
ssize_t
vasqIncSnprintf(char **output, size_t *capacity, const char *format, ...);
vasqIncSnprintf(char **output, size_t *capacity, const char *format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
#endif
;

/**
* @brief Same as vasqIncSnprintf but takes a va_list instead of variable arguments.
Expand Down
9 changes: 5 additions & 4 deletions source/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ vlogToBuffer(const vasqLogger *logger, vasqLogLevel_t level, VASQ_CONTEXT_DECL,

if (c == '%') {
switch (logger->format[++k]) {
unsigned int padding_length;
size_t len, idx;
unsigned int padding_length, len;
size_t idx;
char time_string[30], padding[LOG_LEVEL_NAME_MAX_PADDING + 1];

case 'M': vasqIncVsnprintf(dst, remaining, format, args); break;
Expand Down Expand Up @@ -438,7 +438,8 @@ vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const
char output[VASQ_LOGGING_LENGTH + HEXDUMP_BUFFER_SIZE];
char *dst = output;
int remote_errno;
size_t actual_dump_size, remaining = sizeof(output);
unsigned int actual_dump_size;
size_t remaining = sizeof(output);
vasqLogLevel_t dump_level;

if (!logger) {
Expand All @@ -455,7 +456,7 @@ vasqHexDump(const vasqLogger *logger, VASQ_CONTEXT_DECL, const char *name, const
"%s (%zu byte%s):", name, size, (size == 1) ? "" : "s");

actual_dump_size = MIN(size, VASQ_HEXDUMP_SIZE);
for (size_t k = 0; k < actual_dump_size; k += VASQ_HEXDUMP_WIDTH) {
for (unsigned int k = 0; k < actual_dump_size; k += VASQ_HEXDUMP_WIDTH) {
unsigned int line_length;
char print_buffer[VASQ_HEXDUMP_WIDTH];

Expand Down

0 comments on commit 3ffdeb3

Please sign in to comment.