Replace GCC "unused" and "format" attributes with portable macros

This commit is contained in:
Craig Barnes 2020-08-07 20:42:34 +01:00
parent f952d5a305
commit 7eb70a453b
7 changed files with 18 additions and 10 deletions

View file

@ -20,6 +20,7 @@
#define LOG_ENABLE_DBG 0 #define LOG_ENABLE_DBG 0
#include "log.h" #include "log.h"
#include "input.h" #include "input.h"
#include "macros.h"
#include "tokenize.h" #include "tokenize.h"
#include "util.h" #include "util.h"
#include "wayland.h" #include "wayland.h"
@ -1111,7 +1112,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path, bool errors_ar
/* Split up into key/value pair + trailing comment */ /* Split up into key/value pair + trailing comment */
char *key_value = strtok(line, "#"); char *key_value = strtok(line, "#");
char *comment __attribute__((unused)) = strtok(NULL, "\n"); char UNUSED *comment = strtok(NULL, "\n");
/* Check for new section */ /* Check for new section */
if (key_value[0] == '[') { if (key_value[0] == '[') {

View file

@ -26,6 +26,7 @@
#include "config.h" #include "config.h"
#include "commands.h" #include "commands.h"
#include "keymap.h" #include "keymap.h"
#include "macros.h"
#include "quirks.h" #include "quirks.h"
#include "render.h" #include "render.h"
#include "search.h" #include "search.h"
@ -1116,8 +1117,7 @@ wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,
} else { } else {
if (surface != NULL) { if (surface != NULL) {
/* Sway 1.4 sends this event with a NULL surface when we destroy the window */ /* Sway 1.4 sends this event with a NULL surface when we destroy the window */
const struct wl_window *win __attribute__((unused)) const struct wl_window UNUSED *win = wl_surface_get_user_data(surface);
= wl_surface_get_user_data(surface);
assert(old_moused == win->term); assert(old_moused == win->term);
} }

3
log.c
View file

@ -79,8 +79,7 @@ _log(enum log_class log_class, const char *module, const char *file, int lineno,
static void static void
_sys_log(enum log_class log_class, const char *module, _sys_log(enum log_class log_class, const char *module,
const char *file __attribute__((unused)), const char UNUSED *file, int UNUSED lineno,
int lineno __attribute__((unused)),
const char *fmt, int sys_errno, va_list va) const char *fmt, int sys_errno, va_list va)
{ {
if (!do_syslog) if (!do_syslog)

7
log.h
View file

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include "macros.h"
enum log_colorize { LOG_COLORIZE_NEVER, LOG_COLORIZE_ALWAYS, LOG_COLORIZE_AUTO }; enum log_colorize { LOG_COLORIZE_NEVER, LOG_COLORIZE_ALWAYS, LOG_COLORIZE_AUTO };
enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON }; enum log_facility { LOG_FACILITY_USER, LOG_FACILITY_DAEMON };
@ -11,16 +12,16 @@ void log_deinit(void);
void log_msg(enum log_class log_class, const char *module, void log_msg(enum log_class log_class, const char *module,
const char *file, int lineno, const char *file, int lineno,
const char *fmt, ...) __attribute__((format (printf, 5, 6))); const char *fmt, ...) PRINTF(5);
void log_errno(enum log_class log_class, const char *module, void log_errno(enum log_class log_class, const char *module,
const char *file, int lineno, const char *file, int lineno,
const char *fmt, ...) __attribute__((format (printf, 5, 6))); const char *fmt, ...) PRINTF(5);
void log_errno_provided( void log_errno_provided(
enum log_class log_class, const char *module, enum log_class log_class, const char *module,
const char *file, int lineno, int _errno, const char *file, int lineno, int _errno,
const char *fmt, ...) __attribute__((format (printf, 6, 7))); const char *fmt, ...) PRINTF(6);
#define LOG_ERR(fmt, ...) \ #define LOG_ERR(fmt, ...) \
log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__) log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__)

View file

@ -20,6 +20,12 @@
#define HAS_BUILTIN(x) 0 #define HAS_BUILTIN(x) 0
#endif #endif
#if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(unused) || defined(__TINYC__)
#define UNUSED __attribute__((__unused__))
#else
#define UNUSED
#endif
#if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(malloc) #if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(malloc)
#define MALLOC __attribute__((__malloc__)) #define MALLOC __attribute__((__malloc__))
#else #else

3
shm.c
View file

@ -22,6 +22,7 @@
#define LOG_MODULE "shm" #define LOG_MODULE "shm"
#define LOG_ENABLE_DBG 0 #define LOG_ENABLE_DBG 0
#include "log.h" #include "log.h"
#include "macros.h"
#define TIME_SCROLL 0 #define TIME_SCROLL 0
@ -398,7 +399,7 @@ static bool
wrap_buffer(struct wl_shm *shm, struct buffer *buf, off_t new_offset) wrap_buffer(struct wl_shm *shm, struct buffer *buf, off_t new_offset)
{ {
/* We don't allow overlapping offsets */ /* We don't allow overlapping offsets */
off_t diff __attribute__((unused)) = off_t UNUSED diff =
new_offset < buf->offset ? buf->offset - new_offset : new_offset - buf->offset; new_offset < buf->offset ? buf->offset - new_offset : new_offset - buf->offset;
assert(diff > buf->size); assert(diff > buf->size);

View file

@ -1032,7 +1032,7 @@ fdm_shutdown(struct fdm *fdm, int fd, int events, void *data)
wayl_win_destroy(term->window); wayl_win_destroy(term->window);
term->window = NULL; term->window = NULL;
struct wayland *wayl __attribute__((unused)) = term->wl; struct wayland *wayl = term->wl;
/* /*
* Normally we'd get unmapped when we destroy the Wayland * Normally we'd get unmapped when we destroy the Wayland