neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

func_attr.h (7512B)


      1 // Undefined DEFINE_FUNC_ATTRIBUTES and undefined DEFINE_EMPTY_ATTRIBUTES
      2 // leaves file with untouched FUNC_ATTR_* macros. This variant is used for
      3 // src/gen/gen_declarations.lua.
      4 //
      5 // Empty macros are used for *.c files.
      6 // (undefined DEFINE_FUNC_ATTRIBUTES and defined DEFINE_EMPTY_ATTRIBUTES)
      7 //
      8 // Macros defined as __attribute__((*)) are used by generated header files.
      9 // (defined DEFINE_FUNC_ATTRIBUTES and undefined DEFINE_EMPTY_ATTRIBUTES)
     10 
     11 // FUNC_ATTR_* macros should be in *.c files for declarations generator. If you
     12 // define a function for which declaration is not generated by
     13 // gen_declarations.lua (e.g. template hash implementation) then you should use
     14 // REAL_FATTR_* macros.
     15 
     16 // gcc and clang expose their version as follows:
     17 //
     18 // gcc 4.7.2:
     19 //   __GNUC__          = 4
     20 //   __GNUC_MINOR__    = 7
     21 //   __GNUC_PATCHLEVEL = 2
     22 //
     23 // clang 3.4 (claims compat with gcc 4.2.1):
     24 //   __GNUC__          = 4
     25 //   __GNUC_MINOR__    = 2
     26 //   __GNUC_PATCHLEVEL = 1
     27 //   __clang__         = 1
     28 //   __clang_major__   = 3
     29 //   __clang_minor__   = 4
     30 //
     31 // To view the default defines of these compilers, you can perform:
     32 //
     33 // $ gcc -E -dM - </dev/null
     34 // $ echo | clang -dM -E -
     35 
     36 #include "nvim/macros_defs.h"
     37 
     38 #ifdef FUNC_ATTR_MALLOC
     39 # undef FUNC_ATTR_MALLOC
     40 #endif
     41 
     42 #ifdef FUNC_ATTR_ALLOC_SIZE
     43 # undef FUNC_ATTR_ALLOC_SIZE
     44 #endif
     45 
     46 #ifdef FUNC_ATTR_ALLOC_SIZE_PROD
     47 # undef FUNC_ATTR_ALLOC_SIZE_PROD
     48 #endif
     49 
     50 #ifdef FUNC_ATTR_ALLOC_ALIGN
     51 # undef FUNC_ATTR_ALLOC_ALIGN
     52 #endif
     53 
     54 #ifdef FUNC_ATTR_PURE
     55 # undef FUNC_ATTR_PURE
     56 #endif
     57 
     58 #ifdef FUNC_ATTR_CONST
     59 # undef FUNC_ATTR_CONST
     60 #endif
     61 
     62 #ifdef FUNC_ATTR_WARN_UNUSED_RESULT
     63 # undef FUNC_ATTR_WARN_UNUSED_RESULT
     64 #endif
     65 
     66 #ifdef FUNC_ATTR_ALWAYS_INLINE
     67 # undef FUNC_ATTR_ALWAYS_INLINE
     68 #endif
     69 
     70 #ifdef FUNC_ATTR_UNUSED
     71 # undef FUNC_ATTR_UNUSED
     72 #endif
     73 
     74 #ifdef FUNC_ATTR_NONNULL_ALL
     75 # undef FUNC_ATTR_NONNULL_ALL
     76 #endif
     77 
     78 #ifdef FUNC_ATTR_NONNULL_ARG
     79 # undef FUNC_ATTR_NONNULL_ARG
     80 #endif
     81 
     82 #ifdef FUNC_ATTR_NONNULL_RET
     83 # undef FUNC_ATTR_NONNULL_RET
     84 #endif
     85 
     86 #ifdef FUNC_ATTR_NORETURN
     87 # undef FUNC_ATTR_NORETURN
     88 #endif
     89 
     90 #ifdef FUNC_ATTR_NO_SANITIZE_UNDEFINED
     91 # undef FUNC_ATTR_NO_SANITIZE_UNDEFINED
     92 #endif
     93 
     94 #ifdef FUNC_ATTR_NO_SANITIZE_ADDRESS
     95 # undef FUNC_ATTR_NO_SANITIZE_ADDRESS
     96 #endif
     97 
     98 #ifdef FUNC_ATTR_PRINTF
     99 # undef FUNC_ATTR_PRINTF
    100 #endif
    101 
    102 #ifndef DID_REAL_ATTR
    103 # define DID_REAL_ATTR
    104 # ifdef __GNUC__
    105 // For all gnulikes: gcc, clang, intel.
    106 
    107 // place these after the argument list of the function declaration
    108 // (not definition), like so:
    109 // void myfunc(void) REAL_FATTR_ALWAYS_INLINE;
    110 #  define REAL_FATTR_MALLOC __attribute__((malloc))
    111 #  define REAL_FATTR_ALLOC_ALIGN(x) __attribute__((alloc_align(x)))
    112 #  define REAL_FATTR_PURE __attribute__((pure))
    113 #  define REAL_FATTR_CONST __attribute__((const))
    114 #  define REAL_FATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
    115 #  define REAL_FATTR_ALWAYS_INLINE __attribute__((always_inline))
    116 #  define REAL_FATTR_UNUSED __attribute__((unused))
    117 #  define REAL_FATTR_NONNULL_ALL __attribute__((nonnull))
    118 #  define REAL_FATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__)))
    119 #  define REAL_FATTR_NORETURN __attribute__((noreturn))
    120 #  define REAL_FATTR_PRINTF(x, y) __attribute__((format(printf, x, y)))
    121 
    122 #  if NVIM_HAS_ATTRIBUTE(returns_nonnull)
    123 #   define REAL_FATTR_NONNULL_RET __attribute__((returns_nonnull))
    124 #  endif
    125 
    126 #  if NVIM_HAS_ATTRIBUTE(alloc_size)
    127 #   define REAL_FATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
    128 #   define REAL_FATTR_ALLOC_SIZE_PROD(x, y) __attribute__((alloc_size(x, y)))
    129 #  endif
    130 
    131 #  if NVIM_HAS_ATTRIBUTE(no_sanitize_undefined)
    132 #   define REAL_FATTR_NO_SANITIZE_UNDEFINED \
    133  __attribute__((no_sanitize_undefined))
    134 #  elif NVIM_HAS_ATTRIBUTE(no_sanitize)
    135 #   define REAL_FATTR_NO_SANITIZE_UNDEFINED \
    136  __attribute__((no_sanitize("undefined")))
    137 #  endif
    138 
    139 #  if NVIM_HAS_ATTRIBUTE(no_sanitize_address)
    140 #   define REAL_FATTR_NO_SANITIZE_ADDRESS \
    141  __attribute__((no_sanitize_address))
    142 #  endif
    143 # endif
    144 
    145 // Define attributes that are not defined for this compiler.
    146 
    147 # ifndef REAL_FATTR_MALLOC
    148 #  define REAL_FATTR_MALLOC
    149 # endif
    150 
    151 # ifndef REAL_FATTR_ALLOC_SIZE
    152 #  define REAL_FATTR_ALLOC_SIZE(x)
    153 # endif
    154 
    155 # ifndef REAL_FATTR_ALLOC_SIZE_PROD
    156 #  define REAL_FATTR_ALLOC_SIZE_PROD(x, y)
    157 # endif
    158 
    159 # ifndef REAL_FATTR_ALLOC_ALIGN
    160 #  define REAL_FATTR_ALLOC_ALIGN(x)
    161 # endif
    162 
    163 # ifndef REAL_FATTR_PURE
    164 #  define REAL_FATTR_PURE
    165 # endif
    166 
    167 # ifndef REAL_FATTR_CONST
    168 #  define REAL_FATTR_CONST
    169 # endif
    170 
    171 # ifndef REAL_FATTR_WARN_UNUSED_RESULT
    172 #  define REAL_FATTR_WARN_UNUSED_RESULT
    173 # endif
    174 
    175 # ifndef REAL_FATTR_ALWAYS_INLINE
    176 #  define REAL_FATTR_ALWAYS_INLINE
    177 # endif
    178 
    179 # ifndef REAL_FATTR_UNUSED
    180 #  define REAL_FATTR_UNUSED
    181 # endif
    182 
    183 # ifndef REAL_FATTR_NONNULL_ALL
    184 #  define REAL_FATTR_NONNULL_ALL
    185 # endif
    186 
    187 # ifndef REAL_FATTR_NONNULL_ARG
    188 #  define REAL_FATTR_NONNULL_ARG(...)
    189 # endif
    190 
    191 # ifndef REAL_FATTR_NONNULL_RET
    192 #  define REAL_FATTR_NONNULL_RET
    193 # endif
    194 
    195 # ifndef REAL_FATTR_NORETURN
    196 #  define REAL_FATTR_NORETURN
    197 # endif
    198 
    199 # ifndef REAL_FATTR_NO_SANITIZE_UNDEFINED
    200 #  define REAL_FATTR_NO_SANITIZE_UNDEFINED
    201 # endif
    202 
    203 # ifndef REAL_FATTR_NO_SANITIZE_ADDRESS
    204 #  define REAL_FATTR_NO_SANITIZE_ADDRESS
    205 # endif
    206 
    207 # ifndef REAL_FATTR_PRINTF
    208 #  define REAL_FATTR_PRINTF(x, y)
    209 # endif
    210 #endif
    211 
    212 #if defined(DEFINE_FUNC_ATTRIBUTES) || defined(DEFINE_EMPTY_ATTRIBUTES)
    213 /// Fast (non-deferred) API function.
    214 # define FUNC_API_FAST
    215 /// Return value needs to be freed
    216 # define FUNC_API_RET_ALLOC
    217 /// Internal C function not exposed in the RPC API.
    218 # define FUNC_API_NOEXPORT
    219 /// API function not exposed in Vimscript/eval.
    220 # define FUNC_API_REMOTE_ONLY
    221 /// API function not exposed in Vimscript/remote.
    222 # define FUNC_API_LUA_ONLY
    223 /// API function fails during textlock.
    224 # define FUNC_API_TEXTLOCK
    225 /// API function fails during textlock, but allows cmdwin.
    226 # define FUNC_API_TEXTLOCK_ALLOW_CMDWIN
    227 /// API function introduced at the given API level.
    228 # define FUNC_API_SINCE(X)
    229 /// API function deprecated since the given API level.
    230 # define FUNC_API_DEPRECATED_SINCE(X)
    231 #endif
    232 
    233 #if defined(DEFINE_FUNC_ATTRIBUTES)
    234 # define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC
    235 # define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x)
    236 # define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) REAL_FATTR_ALLOC_SIZE_PROD(x, y)
    237 # define FUNC_ATTR_ALLOC_ALIGN(x) REAL_FATTR_ALLOC_ALIGN(x)
    238 # define FUNC_ATTR_PURE REAL_FATTR_PURE
    239 # define FUNC_ATTR_CONST REAL_FATTR_CONST
    240 # define FUNC_ATTR_WARN_UNUSED_RESULT REAL_FATTR_WARN_UNUSED_RESULT
    241 # define FUNC_ATTR_ALWAYS_INLINE REAL_FATTR_ALWAYS_INLINE
    242 # define FUNC_ATTR_UNUSED REAL_FATTR_UNUSED
    243 # define FUNC_ATTR_NONNULL_ALL REAL_FATTR_NONNULL_ALL
    244 # define FUNC_ATTR_NONNULL_ARG(...) REAL_FATTR_NONNULL_ARG(__VA_ARGS__)
    245 # define FUNC_ATTR_NONNULL_RET REAL_FATTR_NONNULL_RET
    246 # define FUNC_ATTR_NORETURN REAL_FATTR_NORETURN
    247 # define FUNC_ATTR_NO_SANITIZE_UNDEFINED REAL_FATTR_NO_SANITIZE_UNDEFINED
    248 # define FUNC_ATTR_NO_SANITIZE_ADDRESS REAL_FATTR_NO_SANITIZE_ADDRESS
    249 # define FUNC_ATTR_PRINTF(x, y) REAL_FATTR_PRINTF(x, y)
    250 #elif defined(DEFINE_EMPTY_ATTRIBUTES)
    251 # define FUNC_ATTR_MALLOC
    252 # define FUNC_ATTR_ALLOC_SIZE(x)
    253 # define FUNC_ATTR_ALLOC_SIZE_PROD(x, y)
    254 # define FUNC_ATTR_ALLOC_ALIGN(x)
    255 # define FUNC_ATTR_PURE
    256 # define FUNC_ATTR_CONST
    257 # define FUNC_ATTR_WARN_UNUSED_RESULT
    258 # define FUNC_ATTR_ALWAYS_INLINE
    259 # define FUNC_ATTR_UNUSED
    260 # define FUNC_ATTR_NONNULL_ALL
    261 # define FUNC_ATTR_NONNULL_ARG(...)
    262 # define FUNC_ATTR_NONNULL_RET
    263 # define FUNC_ATTR_NORETURN
    264 # define FUNC_ATTR_NO_SANITIZE_UNDEFINED
    265 # define FUNC_ATTR_NO_SANITIZE_ADDRESS
    266 # define FUNC_ATTR_PRINTF(x, y)
    267 #endif