[libvirt] [PATCHv3] fix failure when building with --disable-debug

When building with --disable-debug, VIR_DEBUG expands to a nop. But parameters to VIR_DEBUG can be variables that are passed only to VIR_DEBUG. In the case the building system complains about unused variables. --- src/util/logging.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util/logging.h b/src/util/logging.h index 70318d0..2e70af4 100644 --- a/src/util/logging.h +++ b/src/util/logging.h @@ -34,8 +34,21 @@ # define VIR_DEBUG_INT(category, f, l, ...) \ virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__) # else +/** + * virLogEatParam: + * + * Do nothing but eat parameters. + */ +static inline void virLogEatParam(const char *category, + const char *funcname, + long long linenr, ...) +{ + category = category; + funcname = funcname; + linenr = linenr; +} # define VIR_DEBUG_INT(category, f, l, ...) \ - do { } while (0) + virLogEatParam(category, f, l, __VA_ARGS__) # endif /* !ENABLE_DEBUG */ # define VIR_INFO_INT(category, f, l, ...) \ -- 1.7.10.2

On 13.07.2012 09:50, Hu Tao wrote:
When building with --disable-debug, VIR_DEBUG expands to a nop. But parameters to VIR_DEBUG can be variables that are passed only to VIR_DEBUG. In the case the building system complains about unused variables. --- src/util/logging.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/util/logging.h b/src/util/logging.h index 70318d0..2e70af4 100644 --- a/src/util/logging.h +++ b/src/util/logging.h @@ -34,8 +34,21 @@ # define VIR_DEBUG_INT(category, f, l, ...) \ virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__) # else +/** + * virLogEatParam: + * + * Do nothing but eat parameters. + */ +static inline void virLogEatParam(const char *category, + const char *funcname, + long long linenr, ...) +{ + category = category; + funcname = funcname; + linenr = linenr; +} # define VIR_DEBUG_INT(category, f, l, ...) \ - do { } while (0) + virLogEatParam(category, f, l, __VA_ARGS__) # endif /* !ENABLE_DEBUG */
# define VIR_INFO_INT(category, f, l, ...) \
Okay, this fixes the issue. However I think virLogEatParam() should be implemented in src/util/logging.c and in .h it should be only annotated. Michal

On Fri, Jul 13, 2012 at 11:46:17AM +0200, Michal Privoznik wrote:
On 13.07.2012 09:50, Hu Tao wrote:
When building with --disable-debug, VIR_DEBUG expands to a nop. But parameters to VIR_DEBUG can be variables that are passed only to VIR_DEBUG. In the case the building system complains about unused variables. --- src/util/logging.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/util/logging.h b/src/util/logging.h index 70318d0..2e70af4 100644 --- a/src/util/logging.h +++ b/src/util/logging.h @@ -34,8 +34,21 @@ # define VIR_DEBUG_INT(category, f, l, ...) \ virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__) # else +/** + * virLogEatParam: + * + * Do nothing but eat parameters. + */ +static inline void virLogEatParam(const char *category, + const char *funcname, + long long linenr, ...) +{ + category = category; + funcname = funcname; + linenr = linenr; +} # define VIR_DEBUG_INT(category, f, l, ...) \ - do { } while (0) + virLogEatParam(category, f, l, __VA_ARGS__) # endif /* !ENABLE_DEBUG */
# define VIR_INFO_INT(category, f, l, ...) \
Okay, this fixes the issue. However I think virLogEatParam() should be implemented in src/util/logging.c and in .h it should be only annotated.
No, the whole point in having it in logging.h, is that it expands to a no-op when you have debugging disabled. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 07/13/2012 01:50 AM, Hu Tao wrote:
When building with --disable-debug, VIR_DEBUG expands to a nop. But parameters to VIR_DEBUG can be variables that are passed only to VIR_DEBUG. In the case the building system complains about unused variables. --- src/util/logging.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
ACK.
diff --git a/src/util/logging.h b/src/util/logging.h index 70318d0..2e70af4 100644 --- a/src/util/logging.h +++ b/src/util/logging.h @@ -34,8 +34,21 @@ # define VIR_DEBUG_INT(category, f, l, ...) \ virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__) # else +/** + * virLogEatParam: + * + * Do nothing but eat parameters. + */ +static inline void virLogEatParam(const char *category, + const char *funcname, + long long linenr, ...)
Technically, we don't even need that many variables. I simplified this and pushed: diff --git i/src/util/logging.h w/src/util/logging.h index 2e70af4..db648cb 100644 --- i/src/util/logging.h +++ w/src/util/logging.h @@ -1,7 +1,7 @@ /* * logging.h: internal logging and debugging * - * Copyright (C) 2006-2008, 2011 Red Hat, Inc. + * Copyright (C) 2006-2008, 2011-2012 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,20 +35,17 @@ virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__) # else /** - * virLogEatParam: + * virLogEatParams: * * Do nothing but eat parameters. */ -static inline void virLogEatParam(const char *category, - const char *funcname, - long long linenr, ...) +static inline void virLogEatParams(const char *unused, ...) { - category = category; - funcname = funcname; - linenr = linenr; + /* Silence gcc */ + unused = unused; } # define VIR_DEBUG_INT(category, f, l, ...) \ - virLogEatParam(category, f, l, __VA_ARGS__) + virLogEatParams(category, f, l, __VA_ARGS__) # endif /* !ENABLE_DEBUG */ # define VIR_INFO_INT(category, f, l, ...) \ -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, 13 Jul 2012 at 07:50 GMT, Hu Tao <hutao@cn.fujitsu.com> wrote:
+/** + * virLogEatParam: + * + * Do nothing but eat parameters. + */ +static inline void virLogEatParam(const char *category, + const char *funcname, + long long linenr, ...) +{ + category = category; + funcname = funcname; + linenr = linenr; +}
Or (void) category; (void) funcname; (void) linenr;
participants (5)
-
Cong Wang
-
Daniel P. Berrange
-
Eric Blake
-
Hu Tao
-
Michal Privoznik