macros.h 2.35 KB
Newer Older
1
/* SPDX-License-Identifier: Zlib */
2 3 4 5

#ifndef GIRARA_MACROS_H
#define GIRARA_MACROS_H

6 7 8
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
9 10 11 12

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
13

14
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
Sebastian Ramacher's avatar
Sebastian Ramacher committed
15
#  define GIRARA_GNUC_CHECK(maj, min) \
16 17 18 19 20
    (((__GNUC__ << 20) + (__GNUC_MINOR__ << 10)) >= (((maj) << 20) + ((min) << 10)))
#else
#  define GIRARA_GNUC_CHECK(maj, min) 0
#endif

21
#ifndef GIRARA_PRINTF
22
# if GIRARA_GNUC_CHECK(2, 5) || defined(__clang__)
23 24 25 26 27 28 29 30
#  define GIRARA_PRINTF(format_idx, arg_idx) \
    __attribute__((__format__ (__printf__, format_idx, arg_idx)))
# else
#  define GIRARA_PRINTF(format_idx, arg_idx)
# endif
#endif

#ifndef GIRARA_UNUSED
Sebastian Ramacher's avatar
Sebastian Ramacher committed
31
# if defined(__GNUC__) || defined(__clang__)
32 33 34 35 36 37
#  define GIRARA_UNUSED(x) UNUSED_ ## x __attribute__((unused))
# elif defined(__LCLINT__)
#  define GIRARA_UNUSED(x) /*@unused@*/ x
# else
#  define GIRARA_UNUSED(x) x
# endif
38 39
#endif

40
#ifndef GIRARA_HIDDEN
41
# if GIRARA_GNUC_CHECK(4, 0) || __has_attribute(visibility)
42
#  define GIRARA_HIDDEN __attribute__((visibility("hidden")))
Sebastian Ramacher's avatar
Sebastian Ramacher committed
43 44
# elif defined(__SUNPRO_C)
#  define GIRARA_HIDDEN __hidden
45 46 47 48 49
# else
#  define GIRARA_HIDDEN
# endif
#endif

50
#ifndef GIRARA_VISIBLE
51
# if GIRARA_GNUC_CHECK(4, 0) || __has_attribute(visibility)
52 53 54 55 56 57
#  define GIRARA_VISIBLE __attribute__((visibility("default")))
# else
#  define GIRARA_VISIBLE
# endif
#endif

58
#ifndef GIRARA_DEPRECATED
59
# if defined(__GNUC__) || __has_attribute(deprecated)
60
#  define GIRARA_DEPRECATED(x) x __attribute__((deprecated))
61
#  define GIRARA_DEPRECATED_ __attribute__((deprecated))
62 63
# else
#  define GIRARA_DEPRECATED(x) x
64
#  define GIRARA_DEPRECATED_
65 66 67
# endif
#endif

68
#ifndef GIRARA_ALLOC_SIZE
69
# if (!defined(__clang__) && GIRARA_GNUC_CHECK(4, 3)) || \
70
      (defined(__clang__) && __has_attribute(__alloc_size__))
71 72 73 74 75 76
#  define GIRARA_ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
# else
#  define GIRARA_ALLOC_SIZE(x)
# endif
#endif

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#ifndef GIRARA_DO_PRAGMA
# if defined(__GNUC__) || defined(__clang__)
#  define GIRARA_DO_PRAGMA(x) _Pragma(#x)
# else
#  define GIRARA_DO_PRAGMA(x)
# endif
#endif

#ifndef GIRARA_IGNORE_DEPRECATED
# define GIRARA_IGNORE_DEPRECATED \
    GIRARA_DO_PRAGMA(GCC diagnostic push) \
    GIRARA_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
#endif

#ifndef GIRARA_UNIGNORE
# define GIRARA_UNIGNORE \
    GIRARA_DO_PRAGMA(GCC diagnostic pop)
#endif

96
#endif