mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
func-attr: add some extra handy function attrs
The attributes in question are: - nonnull: specify whether a function argument cannot/may not be null - returns_nonnull: specify whether a function will not return a null pointer (example: xmalloc can't return null, so it should be annotated as such). Only available from gcc 4.9 onwards. Currently these attributes are only supported by gcc.
This commit is contained in:
parent
f5db0d01ba
commit
22e17e25f1
@ -40,9 +40,18 @@
|
|||||||
#elif defined(__INTEL_COMPILER)
|
#elif defined(__INTEL_COMPILER)
|
||||||
// intel only
|
// intel only
|
||||||
#else
|
#else
|
||||||
|
#define GCC_VERSION \
|
||||||
|
(__GNUC__ * 10000 + \
|
||||||
|
__GNUC_MINOR__ * 100 + \
|
||||||
|
__GNUC_PATCHLEVEL__)
|
||||||
// gcc only
|
// gcc only
|
||||||
#define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
|
#define FUNC_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x)))
|
||||||
#define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y)))
|
#define FUNC_ATTR_ALLOC_SIZE_PROD(x,y) __attribute__((alloc_size(x,y)))
|
||||||
|
#define FUNC_ATTR_NONNULL_ALL __attribute__((nonnull))
|
||||||
|
#define FUNC_ATTR_NONNULL_ARG(...) __attribute__((nonnull(__VA_ARGS__)))
|
||||||
|
#if GCC_VERSION >= 40900
|
||||||
|
#define FUNC_ATTR_NONNULL_RET __attribute__((returns_nonnull))
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -81,4 +90,16 @@
|
|||||||
#define FUNC_ATTR_ALWAYS_INLINE
|
#define FUNC_ATTR_ALWAYS_INLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FUNC_ATTR_NONNULL_ALL
|
||||||
|
#define FUNC_ATTR_NONNULL_ALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FUNC_ATTR_NONNULL_ARG
|
||||||
|
#define FUNC_ATTR_NONNULL_ARG(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FUNC_ATTR_NONNULL_RET
|
||||||
|
#define FUNC_ATTR_NONNULL_RET
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // NEOVIM_FUNC_ATTR_H
|
#endif // NEOVIM_FUNC_ATTR_H
|
||||||
|
Loading…
Reference in New Issue
Block a user