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.
*/
#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);

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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;