diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2013-11-12 18:21:51 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-11-21 16:37:07 +0000 |
commit | fecf6c6e84afdc31a59fe9584c80008b80d99520 (patch) | |
tree | 30cf8d494df1b4c3e8f011a6c0d005aac2ff2922 /libvirt-utils.h | |
parent | c7c830e3da1a2bb605f6fd1832a2dc71097fb1b4 (diff) | |
download | libvirt-python-v7-fecf6c6e84afdc31a59fe9584c80008b80d99520.tar.gz libvirt-python-v7-fecf6c6e84afdc31a59fe9584c80008b80d99520.tar.xz libvirt-python-v7-fecf6c6e84afdc31a59fe9584c80008b80d99520.zip |
Import code annotation macros from libvirt
Import ATTRIBUTE_RETURN_CHECK, ATTRIBUTE_UNUSED &
ATTRIBUTE_NONNULL macros
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'libvirt-utils.h')
-rw-r--r-- | libvirt-utils.h | 52 |
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__ */ |