1 #ifndef JEMALLOC_INTERNAL_MACROS_H 2 #define JEMALLOC_INTERNAL_MACROS_H 3 4 #ifdef JEMALLOC_DEBUG 5 # define JEMALLOC_ALWAYS_INLINE static inline 6 #else 7 # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline 8 #endif 9 #ifdef _MSC_VER 10 # define inline _inline 11 #endif 12 13 #define UNUSED JEMALLOC_ATTR(unused) 14 15 #define ZU(z) ((size_t)z) 16 #define ZD(z) ((ssize_t)z) 17 #define QU(q) ((uint64_t)q) 18 #define QD(q) ((int64_t)q) 19 20 #define KZU(z) ZU(z##ULL) 21 #define KZD(z) ZD(z##LL) 22 #define KQU(q) QU(q##ULL) 23 #define KQD(q) QI(q##LL) 24 25 #ifndef __DECONST 26 # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 27 #endif 28 29 #if !defined(JEMALLOC_HAS_RESTRICT) || defined(__cplusplus) 30 # define restrict 31 #endif 32 33 /* Various function pointers are static and immutable except during testing. */ 34 #ifdef JEMALLOC_JET 35 # define JET_MUTABLE 36 #else 37 # define JET_MUTABLE const 38 #endif 39 40 #define JEMALLOC_VA_ARGS_HEAD(head, ...) head 41 #define JEMALLOC_VA_ARGS_TAIL(head, ...) __VA_ARGS__ 42 43 #if (defined(__GNUC__) || defined(__GNUG__)) && !defined(__clang__) \ 44 && defined(JEMALLOC_HAVE_ATTR) && (__GNUC__ >= 7) 45 #define JEMALLOC_FALLTHROUGH JEMALLOC_ATTR(fallthrough); 46 #else 47 #define JEMALLOC_FALLTHROUGH /* falls through */ 48 #endif 49 50 /* Diagnostic suppression macros */ 51 #if defined(_MSC_VER) && !defined(__clang__) 52 # define JEMALLOC_DIAGNOSTIC_PUSH __pragma(warning(push)) 53 # define JEMALLOC_DIAGNOSTIC_POP __pragma(warning(pop)) 54 # define JEMALLOC_DIAGNOSTIC_IGNORE(W) __pragma(warning(disable:W)) 55 # define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS 56 # define JEMALLOC_DIAGNOSTIC_IGNORE_TYPE_LIMITS 57 # define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN 58 # define JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS 59 /* #pragma GCC diagnostic first appeared in gcc 4.6. */ 60 #elif (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && \ 61 (__GNUC_MINOR__ > 5)))) || defined(__clang__) 62 /* 63 * The JEMALLOC_PRAGMA__ macro is an implementation detail of the GCC and Clang 64 * diagnostic suppression macros and should not be used anywhere else. 65 */ 66 # define JEMALLOC_PRAGMA__(X) _Pragma(#X) 67 # define JEMALLOC_DIAGNOSTIC_PUSH JEMALLOC_PRAGMA__(GCC diagnostic push) 68 # define JEMALLOC_DIAGNOSTIC_POP JEMALLOC_PRAGMA__(GCC diagnostic pop) 69 # define JEMALLOC_DIAGNOSTIC_IGNORE(W) \ 70 JEMALLOC_PRAGMA__(GCC diagnostic ignored W) 71 72 /* 73 * The -Wmissing-field-initializers warning is buggy in GCC versions < 5.1 and 74 * all clang versions up to version 7 (currently trunk, unreleased). This macro 75 * suppresses the warning for the affected compiler versions only. 76 */ 77 # if ((defined(__GNUC__) && !defined(__clang__)) && (__GNUC__ < 5)) || \ 78 defined(__clang__) 79 # define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS \ 80 JEMALLOC_DIAGNOSTIC_IGNORE("-Wmissing-field-initializers") 81 # else 82 # define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS 83 # endif 84 85 # define JEMALLOC_DIAGNOSTIC_IGNORE_TYPE_LIMITS \ 86 JEMALLOC_DIAGNOSTIC_IGNORE("-Wtype-limits") 87 # define JEMALLOC_DIAGNOSTIC_IGNORE_UNUSED_PARAMETER \ 88 JEMALLOC_DIAGNOSTIC_IGNORE("-Wunused-parameter") 89 # if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ >= 7) 90 # define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN \ 91 JEMALLOC_DIAGNOSTIC_IGNORE("-Walloc-size-larger-than=") 92 # else 93 # define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN 94 # endif 95 # define JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS \ 96 JEMALLOC_DIAGNOSTIC_PUSH \ 97 JEMALLOC_DIAGNOSTIC_IGNORE_UNUSED_PARAMETER 98 #else 99 # define JEMALLOC_DIAGNOSTIC_PUSH 100 # define JEMALLOC_DIAGNOSTIC_POP 101 # define JEMALLOC_DIAGNOSTIC_IGNORE(W) 102 # define JEMALLOC_DIAGNOSTIC_IGNORE_MISSING_STRUCT_FIELD_INITIALIZERS 103 # define JEMALLOC_DIAGNOSTIC_IGNORE_TYPE_LIMITS 104 # define JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN 105 # define JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS 106 #endif 107 108 /* 109 * Disables spurious diagnostics for all headers. Since these headers are not 110 * included by users directly, it does not affect their diagnostic settings. 111 */ 112 JEMALLOC_DIAGNOSTIC_DISABLE_SPURIOUS 113 114 #endif /* JEMALLOC_INTERNAL_MACROS_H */ 115