summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-09-09 21:35:15 +0200
committercgzones <cgzones@googlemail.com>2020-09-18 12:28:40 +0200
commit7107d1db0b3361a3e880d903a45920b64a05e9d6 (patch)
tree926c71c5d2095f156bda3863fc3f8dbcacbc017f
parentf4602f7b4e7fdcf4b3a5d2c0c353b50fef98aa7e (diff)
Refactor __attribute__ usage
Use internal macros for compatibility with non GNUC compilers.
-rw-r--r--CRT.h4
-rw-r--r--Macros.h16
-rw-r--r--XAlloc.c8
-rw-r--r--XAlloc.h10
-rw-r--r--dragonflybsd/DragonFlyBSDProcessList.c4
-rw-r--r--dragonflybsd/DragonFlyBSDProcessList.h2
-rw-r--r--zfs/ZfsArcStats.c4
7 files changed, 24 insertions, 24 deletions
diff --git a/CRT.h b/CRT.h
index 4199837e..d7d01e2c 100644
--- a/CRT.h
+++ b/CRT.h
@@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
+#include "Macros.h"
+
#include <stdbool.h>
#define KEY_WHEELUP KEY_F(20)
@@ -107,7 +109,7 @@ typedef enum ColorElements_ {
LAST_COLORELEMENT
} ColorElements;
-void CRT_fatalError(const char* note) __attribute__ ((noreturn));
+void CRT_fatalError(const char* note) ATTR_NORETURN;
extern struct sigaction old_sigsegv_handler;
void CRT_handleSIGSEGV(int sgn);
diff --git a/Macros.h b/Macros.h
index cb84b291..ef4e8908 100644
--- a/Macros.h
+++ b/Macros.h
@@ -13,4 +13,20 @@
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low))
#endif
+#ifdef __GNUC__ // defined by GCC and Clang
+
+#define ATTR_FORMAT(type, index, check) __attribute__((format (type, index, check)))
+#define ATTR_NONNULL __attribute__((nonnull))
+#define ATTR_NORETURN __attribute__((noreturn))
+#define ATTR_UNUSED __attribute__((unused))
+
+#else /* __GNUC__ */
+
+#define ATTR_FORMAT(type, index, check)
+#define ATTR_NONNULL
+#define ATTR_NORETURN
+#define ATTR_UNUSED
+
+#endif /* __GNUC__ */
+
#endif
diff --git a/XAlloc.c b/XAlloc.c
index 38616dfc..c0fa7547 100644
--- a/XAlloc.c
+++ b/XAlloc.c
@@ -53,14 +53,6 @@ void* xRealloc(void* ptr, size_t size) {
# define xStrdup(str_) (assert(str_), xStrdup_(str_))
#endif
-#ifndef __has_attribute // Clang's macro
-# define __has_attribute(x) 0
-#endif
-#if (__has_attribute(nonnull) || \
- ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
-char* xStrdup_(const char* str) __attribute__((nonnull));
-#endif // __has_attribute(nonnull) || GNU C 3.3 or later
-
char* xStrdup_(const char* str) {
char* data = strdup(str);
if (!data) {
diff --git a/XAlloc.h b/XAlloc.h
index b9334238..3a2c658c 100644
--- a/XAlloc.h
+++ b/XAlloc.h
@@ -31,14 +31,6 @@ void* xRealloc(void* ptr, size_t size);
# define xStrdup(str_) (assert(str_), xStrdup_(str_))
#endif
-#ifndef __has_attribute // Clang's macro
-# define __has_attribute(x) 0
-#endif
-#if (__has_attribute(nonnull) || \
- ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)))
-char* xStrdup_(const char* str) __attribute__((nonnull));
-#endif // __has_attribute(nonnull) || GNU C 3.3 or later
-
-char* xStrdup_(const char* str);
+char* xStrdup_(const char* str) ATTR_NONNULL;
#endif
diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c
index cd5526a7..8901bc45 100644
--- a/dragonflybsd/DragonFlyBSDProcessList.c
+++ b/dragonflybsd/DragonFlyBSDProcessList.c
@@ -22,8 +22,6 @@ in the source distribution for its full text.
#include <sys/param.h>
-#define _UNUSED_ __attribute__((unused))
-
static int MIB_hw_physmem[2];
static int MIB_vm_stats_vm_v_page_count[4];
static int pageSize;
@@ -377,7 +375,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
for (int i = 0; i < count; i++) {
struct kinfo_proc* kproc = &kprocs[i];
bool preExisting = false;
- bool _UNUSED_ isIdleProcess = false;
+ bool ATTR_UNUSED isIdleProcess = false;
// note: dragonflybsd kernel processes all have the same pid, so we misuse the kernel thread address to give them a unique identifier
Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new);
diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h
index 84ab1c5a..9665a60f 100644
--- a/dragonflybsd/DragonFlyBSDProcessList.h
+++ b/dragonflybsd/DragonFlyBSDProcessList.h
@@ -51,8 +51,6 @@ typedef struct DragonFlyBSDProcessList_ {
Hashtable *jails;
} DragonFlyBSDProcessList;
-#define _UNUSED_ __attribute__((unused))
-
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId);
void ProcessList_delete(ProcessList* this);
diff --git a/zfs/ZfsArcStats.c b/zfs/ZfsArcStats.c
index bfed07d3..6c02c2c1 100644
--- a/zfs/ZfsArcStats.c
+++ b/zfs/ZfsArcStats.c
@@ -21,4 +21,6 @@ typedef struct ZfsArcStats_ {
} ZfsArcStats;
}*/
-static int make_iso_compilers_happy __attribute__((unused));
+#include "Macros.h"
+
+static int make_iso_compilers_happy ATTR_UNUSED;

© 2014-2024 Faster IT GmbH | imprint | privacy policy