summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2013-11-12 18:21:51 +0000
committerDaniel P. Berrange <berrange@redhat.com>2013-11-22 15:58:05 +0000
commitca48db168f28778bdcffa243709d545d6dc786e5 (patch)
tree6c98e7470f1e0e5826c457b4b98227b05a01bece
parent834ee782d80e39edc1174640b8db977c900a62dc (diff)
downloadlibvirt-python-v9-ca48db168f28778bdcffa243709d545d6dc786e5.zip
libvirt-python-v9-ca48db168f28778bdcffa243709d545d6dc786e5.tar.gz
libvirt-python-v9-ca48db168f28778bdcffa243709d545d6dc786e5.tar.xz
Import code annotation macros from libvirt
Import ATTRIBUTE_RETURN_CHECK, ATTRIBUTE_UNUSED & ATTRIBUTE_NONNULL macros Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
-rw-r--r--libvirt-utils.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/libvirt-utils.h b/libvirt-utils.h
index 961cc20..f608eb4 100644
--- a/libvirt-utils.h
+++ b/libvirt-utils.h
@@ -54,4 +54,56 @@
# define ignore_value(x) ((void) (x))
# endif
+# ifdef __GNUC__
+/**
+ * ATTRIBUTE_UNUSED:
+ *
+ * Macro to flag consciously unused parameters to functions
+ */
+# ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED __attribute__((__unused__))
+# endif
+
+/* gcc's handling of attribute nonnull is less than stellar - it does
+ * NOT improve diagnostics, and merely allows gcc to optimize away
+ * null code checks even when the caller manages to pass null in spite
+ * of the attribute, leading to weird crashes. Coverity, on the other
+ * hand, knows how to do better static analysis based on knowing
+ * whether a parameter is nonnull. Make this attribute conditional
+ * based on whether we are compiling for real or for analysis, while
+ * still requiring correct gcc syntax when it is turned off. See also
+ * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17308 */
+# ifndef ATTRIBUTE_NONNULL
+# if __GNUC_PREREQ (3, 3)
+# if STATIC_ANALYSIS
+# define ATTRIBUTE_NONNULL(m) __attribute__((__nonnull__(m)))
+# else
+# define ATTRIBUTE_NONNULL(m) __attribute__(())
+# endif
+# else
+# define ATTRIBUTE_NONNULL(m)
+# endif
+# endif
+
+# ifndef ATTRIBUTE_RETURN_CHECK
+# if __GNUC_PREREQ (3, 4)
+# define ATTRIBUTE_RETURN_CHECK __attribute__((__warn_unused_result__))
+# else
+# define ATTRIBUTE_RETURN_CHECK
+# endif
+# endif
+
+# else
+# ifndef ATTRIBUTE_UNUSED
+# define ATTRIBUTE_UNUSED
+# endif
+# ifndef ATTRIBUTE_NONNULL
+# define ATTRIBUTE_NONNULL(m)
+# endif
+# ifndef ATTRIBUTE_RETURN_CHECK
+# define ATTRIBUTE_RETURN_CHECK
+# endif
+# endif /* __GNUC__ */
+
+
#endif /* __LIBVIRT_UTILS_H__ */