Refactor __attribute__ usage

Use internal macros for compatibility with non GNUC compilers.
This commit is contained in:
Christian Göttsche 2020-09-09 21:35:15 +02:00 committed by cgzones
parent f4602f7b4e
commit 7107d1db0b
7 changed files with 24 additions and 24 deletions

4
CRT.h
View File

@ -7,6 +7,8 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Macros.h"
#include <stdbool.h> #include <stdbool.h>
#define KEY_WHEELUP KEY_F(20) #define KEY_WHEELUP KEY_F(20)
@ -107,7 +109,7 @@ typedef enum ColorElements_ {
LAST_COLORELEMENT LAST_COLORELEMENT
} ColorElements; } ColorElements;
void CRT_fatalError(const char* note) __attribute__ ((noreturn)); void CRT_fatalError(const char* note) ATTR_NORETURN;
extern struct sigaction old_sigsegv_handler; extern struct sigaction old_sigsegv_handler;
void CRT_handleSIGSEGV(int sgn); void CRT_handleSIGSEGV(int sgn);

View File

@ -13,4 +13,20 @@
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low)) #define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low))
#endif #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 #endif

View File

@ -53,14 +53,6 @@ void* xRealloc(void* ptr, size_t size) {
# define xStrdup(str_) (assert(str_), xStrdup_(str_)) # define xStrdup(str_) (assert(str_), xStrdup_(str_))
#endif #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) {
char* data = strdup(str); char* data = strdup(str);
if (!data) { if (!data) {

View File

@ -31,14 +31,6 @@ void* xRealloc(void* ptr, size_t size);
# define xStrdup(str_) (assert(str_), xStrdup_(str_)) # define xStrdup(str_) (assert(str_), xStrdup_(str_))
#endif #endif
#ifndef __has_attribute // Clang's macro char* xStrdup_(const char* str) ATTR_NONNULL;
# 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);
#endif #endif

View File

@ -22,8 +22,6 @@ in the source distribution for its full text.
#include <sys/param.h> #include <sys/param.h>
#define _UNUSED_ __attribute__((unused))
static int MIB_hw_physmem[2]; static int MIB_hw_physmem[2];
static int MIB_vm_stats_vm_v_page_count[4]; static int MIB_vm_stats_vm_v_page_count[4];
static int pageSize; static int pageSize;
@ -377,7 +375,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
struct kinfo_proc* kproc = &kprocs[i]; struct kinfo_proc* kproc = &kprocs[i];
bool preExisting = false; 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 // 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); Process* proc = ProcessList_getProcess(this, kproc->kp_ktaddr ? (pid_t)kproc->kp_ktaddr : kproc->kp_pid, &preExisting, (Process_New) DragonFlyBSDProcess_new);

View File

@ -51,8 +51,6 @@ typedef struct DragonFlyBSDProcessList_ {
Hashtable *jails; Hashtable *jails;
} DragonFlyBSDProcessList; } DragonFlyBSDProcessList;
#define _UNUSED_ __attribute__((unused))
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId);
void ProcessList_delete(ProcessList* this); void ProcessList_delete(ProcessList* this);

View File

@ -21,4 +21,6 @@ typedef struct ZfsArcStats_ {
} ZfsArcStats; } ZfsArcStats;
}*/ }*/
static int make_iso_compilers_happy __attribute__((unused)); #include "Macros.h"
static int make_iso_compilers_happy ATTR_UNUSED;