[Commits] [SCM] claws branch, master, updated. 3.18.0-32-g51e51b47c

jonathan at claws-mail.org jonathan at claws-mail.org
Sun Aug 8 03:33:40 CEST 2021


The branch, master has been updated
       via  51e51b47ccc08d7a97b661b66baa8d37cfde5440 (commit)
       via  bfa14488c667993aa619ccb2dbc98e14e108ec9a (commit)
       via  fb28d25c2fdf57527b06f0956923649efdda9c0b (commit)
      from  6b3b78d5aaf0907ff0f2b78cd22d8381d0283594 (commit)

Summary of changes:
 configure.ac       |  13 +++++++
 src/common/utils.c |  19 ++++++++++
 src/common/utils.h |  15 ++++----
 src/main.c         | 102 +++++++++++++++++++++++++++++++++++++++--------------
 4 files changed, 115 insertions(+), 34 deletions(-)


- Log -----------------------------------------------------------------
commit 51e51b47ccc08d7a97b661b66baa8d37cfde5440
Author: Jonathan Boeing <jonathan at claws-mail.org>
Date:   Wed Aug 4 02:07:55 2021 -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.

diff --git a/configure.ac b/configure.ac
index e1fa5837b..e12584cc8 100644
--- 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
index cd01eb530..8b1cbf0eb 100644
--- 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
index 842e467b3..4b1b42219 100644
--- 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 */

commit bfa14488c667993aa619ccb2dbc98e14e108ec9a
Author: Jonathan Boeing <jonathan at claws-mail.org>
Date:   Wed Aug 4 05:45:23 2021 -0700

    Defer closing of Windows log
    
    The Windows logfile was being closed too early and missing part of the
    shutdown process.

diff --git a/src/main.c b/src/main.c
index 844210f5a..a5984dd9d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1469,9 +1469,6 @@ int main(int argc, char *argv[])
 		}
 		if(!account_get_list()) {
 			exit_claws(mainwin);
-#ifdef G_OS_WIN32
-			win32_close_log();
-#endif
 			exit(1);
 		}
 		never_ran = TRUE;
@@ -1620,9 +1617,6 @@ int main(int argc, char *argv[])
 				   "external plugin. Please reinstall the "
 				   "plugin and try again."));
 			exit_claws(mainwin);
-#ifdef G_OS_WIN32
-			win32_close_log();
-#endif
 			exit(1);
 		}
 	}
@@ -1706,9 +1700,6 @@ int main(int argc, char *argv[])
 	uninstall_dbus_status_handler();
 	if(connection)
 		dbus_g_connection_unref(connection);
-#endif
-#ifdef G_OS_WIN32
-	win32_close_log();
 #endif
 	utils_free_regex();
 	exit_claws(mainwin);
@@ -1834,6 +1825,9 @@ static void exit_claws(MainWindow *mainwin)
 	gtkaspell_checkers_quit();
 #endif
 	plugin_unload_all("Common");
+#ifdef G_OS_WIN32
+	win32_close_log();
+#endif
 	claws_done();
 }
 

commit fb28d25c2fdf57527b06f0956923649efdda9c0b
Author: Jonathan Boeing <jonathan at claws-mail.org>
Date:   Mon Aug 2 22:57:15 2021 -0700

    Add GLib structured log handler for Windows
    
    Add a structured log handler for Windows.  This enables the capturing
    of messages from GTK and GLib in the same file as the Claws debug
    messages.
    
    This change also replaces the stdio file functions used by the Windows
    logging with Win32 API functions.

diff --git a/src/main.c b/src/main.c
index bcfa938c7..844210f5a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -693,30 +693,66 @@ void main_set_show_at_startup(gboolean show)
 }
 
 #ifdef G_OS_WIN32
-static FILE* win32_debug_fp=NULL;
+static HANDLE win32_debug_log = NULL;
 static guint win32_log_handler_app_id;
 static guint win32_log_handler_glib_id;
 static guint win32_log_handler_gtk_id;
 
+static void win32_log_WriteFile(const gchar *string)
+{
+	BOOL ret;
+	DWORD bytes_written;
+
+	ret = WriteFile(win32_debug_log, string, strlen(string), &bytes_written, NULL);
+	if (!ret) {
+		DWORD err = GetLastError();
+		gchar *tmp;
+
+		tmp = g_strdup_printf("Error: WriteFile in failed with error 0x%lx.  Buffer contents:\n%s", err, string);
+		OutputDebugString(tmp);
+		g_free(tmp);
+	}
+}
+
 static void win32_print_stdout(const gchar *string)
 {
-	if (win32_debug_fp) {
-		fprintf(win32_debug_fp, "%s", string);
-		fflush(win32_debug_fp);
+	if (win32_debug_log) {
+		win32_log_WriteFile(string);
 	}
 }
 
 static void win32_print_stderr(const gchar *string)
 {
-	if (win32_debug_fp) {
-		fprintf(win32_debug_fp, "%s", string);
-		fflush(win32_debug_fp);
+	if (win32_debug_log) {
+		win32_log_WriteFile(string);
 	}
 }
 
+GLogWriterOutput win32_log_writer(GLogLevelFlags log_level, const GLogField *fields, gsize n_fields, gpointer user_data)
+{
+	gchar *formatted;
+	gchar *out;
+
+	g_return_val_if_fail(win32_debug_log != NULL, G_LOG_WRITER_UNHANDLED);
+	g_return_val_if_fail(fields != NULL, G_LOG_WRITER_UNHANDLED);
+	g_return_val_if_fail(n_fields > 0, G_LOG_WRITER_UNHANDLED);
+
+	formatted = g_log_writer_format_fields(log_level, fields, n_fields, FALSE);
+	out = g_strdup_printf("%s\n", formatted);
+
+	win32_log_WriteFile(out);
+
+	g_free(formatted);
+	g_free(out);
+
+	return G_LOG_WRITER_HANDLED;
+}
+
 static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data)
 {
-	if (win32_debug_fp) {
+	gchar *out;
+
+	if (win32_debug_log) {
 		const gchar* type;
 
 		switch(log_level & G_LOG_LEVEL_MASK)
@@ -742,11 +778,15 @@ static void win32_log(const gchar *log_domain, GLogLevelFlags log_level, const g
 			default:
 				type="N/A";
 		}
+
 		if (log_domain)
-			fprintf(win32_debug_fp, "%s: %s: %s", log_domain, type, message);
+			out = g_strdup_printf("%s: %s: %s", log_domain, type, message);
 		else
-			fprintf(win32_debug_fp, "%s: %s", type, message);
-		fflush(win32_debug_fp);
+			out = g_strdup_printf("%s: %s", type, message);
+
+		win32_log_WriteFile(out);
+
+		g_free(out);
 	}
 }
 
@@ -759,31 +799,45 @@ static void win32_open_log(void)
 		if (rename_force(logfile, oldlogfile) < 0)
 			FILE_OP_ERROR(logfile, "rename");
 	}
-	win32_debug_fp = claws_fopen(logfile, "w");
+
+	win32_debug_log = CreateFile(logfile,
+		GENERIC_WRITE,
+		FILE_SHARE_READ,
+		NULL,
+		CREATE_NEW,
+		FILE_ATTRIBUTE_NORMAL,
+		NULL);
+
+	if (win32_debug_log == INVALID_HANDLE_VALUE) {
+		win32_debug_log = NULL;
+	}
+
 	g_free(logfile);
 	g_free(oldlogfile);
-	if (win32_debug_fp)
-	{
+
+	if (win32_debug_log) {
 		g_set_print_handler(win32_print_stdout);
 		g_set_printerr_handler(win32_print_stdout);
+
 		win32_log_handler_app_id = g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
                      | G_LOG_FLAG_RECURSION, win32_log, NULL);
 		win32_log_handler_glib_id = g_log_set_handler("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
                      | G_LOG_FLAG_RECURSION, win32_log, NULL);
 		win32_log_handler_gtk_id = g_log_set_handler("Gtk", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
                      | G_LOG_FLAG_RECURSION, win32_log, NULL);
+
+		g_log_set_writer_func(&win32_log_writer, NULL, NULL);
 	}
 }
 
 static void win32_close_log(void)
 {
-	if (win32_debug_fp)
-	{
+	if (win32_debug_log) {
 		g_log_remove_handler("", win32_log_handler_app_id);
 		g_log_remove_handler("GLib", win32_log_handler_glib_id);
 		g_log_remove_handler("Gtk", win32_log_handler_gtk_id);
-		claws_fclose(win32_debug_fp);
-		win32_debug_fp=NULL;
+		CloseHandle(win32_debug_log);
+		win32_debug_log = NULL;
 	}
 }		
 #endif

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list