From 22e17e25f11ecabe27c752275da73d8ee75c953e Mon Sep 17 00:00:00 2001 From: Nicolas Hillegeer Date: Mon, 31 Mar 2014 18:55:13 +0200 Subject: [PATCH] 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. --- src/func_attr.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/func_attr.h b/src/func_attr.h index 34023f05d8..94bab79a97 100644 --- a/src/func_attr.h +++ b/src/func_attr.h @@ -40,9 +40,18 @@ #elif defined(__INTEL_COMPILER) // intel only #else + #define GCC_VERSION \ + (__GNUC__ * 10000 + \ + __GNUC_MINOR__ * 100 + \ + __GNUC_PATCHLEVEL__) // gcc only #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_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 @@ -81,4 +90,16 @@ #define FUNC_ATTR_ALWAYS_INLINE #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