[PATCH libvirt-python 08/14] Import code annotation macros from libvirt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Import ATTRIBUTE_RETURN_CHECK, ATTRIBUTE_UNUSED &
ATTRIBUTE_NONNULL macros

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 libvirt-utils.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/libvirt-utils.h b/libvirt-utils.h
index a62db2b..6d3da71 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__ */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]