From 887092a05db4708b4f46e6d788ccfe2e25c70ef6 Mon Sep 17 00:00:00 2001 From: Benoit Dejean Date: Sun, 21 Jun 2015 22:35:52 +0200 Subject: [PATCH] Define glibtop_debug(_r) as macros, eventually calling real C function. Keep these as macros so that if debug is not enable, although the debug message is parsed, it's not run. It's better this way because the debug message is always parsed and checked instead of being deleted by the preprocessor. --- include/glibtop/error.h | 8 +++++--- sysdeps/common/error.c | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/glibtop/error.h b/include/glibtop/error.h index 76e1abe8..fdce2fd3 100644 --- a/include/glibtop/error.h +++ b/include/glibtop/error.h @@ -47,14 +47,16 @@ void glibtop_error_io (const char *format, ...) G_GNUC_PRINTF(1, 2) G_GNUC_NORET void glibtop_warn_io (const char *format, ...) G_GNUC_PRINTF(1, 2); /* FIXME: C99 */ -#define glibtop_debug(fmt, ...) \ +#define glibtop_debug_r(server, fmt, ...) \ G_STMT_START { \ if (LIBGTOP_ENABLE_DEBUG) \ - glibtop_debug_r(glibtop_global_server, fmt, ##__VA_ARGS__); \ + glibtop_debug_r_real(server, fmt, ##__VA_ARGS__); \ } G_STMT_END +#define glibtop_debug(...) glibtop_debug_r(glibtop_global_server, __VA_ARGS__) + void glibtop_debug_vr (glibtop *server, const char *format, va_list args); -void glibtop_debug_r (glibtop *server, const char *format, ...) G_GNUC_PRINTF(2, 3); +void glibtop_debug_r_real (glibtop *server, const char *format, ...) G_GNUC_PRINTF(2, 3); G_END_DECLS diff --git a/sysdeps/common/error.c b/sysdeps/common/error.c index 12363d40..6ef238e6 100644 --- a/sysdeps/common/error.c +++ b/sysdeps/common/error.c @@ -174,7 +174,7 @@ glibtop_debug_vr (glibtop *server, const char *format, va_list args) } void -glibtop_debug_r (glibtop *server, const char *format, ...) +glibtop_debug_r_real (glibtop *server, const char *format, ...) { va_list args;