aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Hillegeer <nicolas@hillegeer.com>2014-03-31 18:55:13 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-03-31 18:42:17 -0300
commit22e17e25f11ecabe27c752275da73d8ee75c953e (patch)
treec7a8142688c9155b4182d0638ada323e0ddc4f05
parentf5db0d01bacc1cebf53bd1e3e2ce79b66116d8cb (diff)
downloadrneovim-22e17e25f11ecabe27c752275da73d8ee75c953e.tar.gz
rneovim-22e17e25f11ecabe27c752275da73d8ee75c953e.tar.bz2
rneovim-22e17e25f11ecabe27c752275da73d8ee75c953e.zip
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.
-rw-r--r--src/func_attr.h21
1 files changed, 21 insertions, 0 deletions
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