commit 51e51b47ccc08d7a97b661b66baa8d37cfde5440
parent bfa14488c667993aa619ccb2dbc98e14e108ec9a
Author: Jonathan Boeing <jonathan@claws-mail.org>
Date: Wed, 4 Aug 2021 02:07:55 -0700
Reduce the amount of file I/O from debug_print
Calls to debug_print on Windows generated two file writes and flushes
per call.
Add a definition of debug_print that uses the __VA_OPT__ macro to
expand to a single call to debug_print_real.
Diffstat:
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -379,6 +379,19 @@ else
fi
AC_SUBST(SM_LIBS)
+dnl Check for __VA_OPT__ macro
+AC_CACHE_CHECK([for __VA_OPT__],
+ [ac_cv_va_opt],
+ [AC_TRY_COMPILE([#include <stdio.h>],
+ [#define va_opt_printf(format, ...) fprintf(stderr, format __VA_OPT__(,) __VA_ARGS__)
+ va_opt_printf("success\n");],
+ [ac_cv_va_opt=yes],
+ [ac_cv_va_opt=no])]
+)
+if test "$ac_cv_va_opt" = yes; then
+ AC_DEFINE([HAVE_VA_OPT], [1], [Define if __VA_OPT__ macro works])
+fi
+
dnl Check for d_type member in struct dirent
AC_MSG_CHECKING([whether struct dirent has d_type member])
AC_CACHE_VAL(ac_cv_dirent_d_type,[
diff --git a/src/common/utils.c b/src/common/utils.c
@@ -2953,6 +2953,24 @@ gboolean debug_get_mode(void)
return debug_mode;
}
+#ifdef HAVE_VA_OPT
+void debug_print_real(const char *file, int line, const gchar *format, ...)
+{
+ va_list args;
+ gchar buf[BUFFSIZE];
+ gint prefix_len;
+
+ if (!debug_mode) return;
+
+ prefix_len = g_snprintf(buf, sizeof(buf), "%s:%d:", debug_srcname(file), line);
+
+ va_start(args, format);
+ g_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, format, args);
+ va_end(args);
+
+ g_print("%s", buf);
+}
+#else
void debug_print_real(const gchar *format, ...)
{
va_list args;
@@ -2966,6 +2984,7 @@ void debug_print_real(const gchar *format, ...)
g_print("%s", buf);
}
+#endif
const char * debug_srcname(const char *file)
diff --git a/src/common/utils.h b/src/common/utils.h
@@ -236,14 +236,11 @@ typedef gpointer (*GNodeMapFunc) (gpointer nodedata, gpointer data);
void debug_set_mode (gboolean mode);
gboolean debug_get_mode (void);
-#ifndef __CYGWIN__
-#define debug_print \
- debug_print_real("%s:%d:", debug_srcname(__FILE__), __LINE__), \
- debug_print_real
+#ifdef HAVE_VA_OPT
+#define debug_print(format, ...) debug_print_real(__FILE__, __LINE__, format __VA_OPT__(,) __VA_ARGS__)
#else
- /* FIXME: cygwin: why debug_srcname couldn't be resolved in library? */
#define debug_print \
- debug_print_real("%s:%d:", __FILE__, __LINE__), \
+ debug_print_real("%s:%d:", debug_srcname(__FILE__), __LINE__), \
debug_print_real
#endif
@@ -464,7 +461,11 @@ size_t fast_strftime (gchar *buf,
struct tm *lt);
/* debugging */
-void debug_print_real (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+#ifdef HAVE_VA_OPT
+void debug_print_real (const char *file, int line, const gchar *format, ...) G_GNUC_PRINTF(3, 4);
+#else
+void debug_print_real (const gchar *format, ...) G_GNUC_PRINTF(1, 2);
+#endif
const char * debug_srcname (const char *file);
/* subject threading */