[Spice-commits] 2 commits - common/log.c common/log.h tests/test-logging.c

Frediano Ziglio fziglio at kemper.freedesktop.org
Wed Jul 5 08:54:25 UTC 2017


 common/log.c         |   17 +++++++++--------
 common/log.h         |   25 ++++++++++++-------------
 tests/test-logging.c |    7 +++----
 3 files changed, 24 insertions(+), 25 deletions(-)

New commits:
commit eeab433539d9fac198deebd0037cd52cc8d29689
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Jun 19 09:03:36 2017 +0100

    log: Force format in log macro to be a string
    
    Make sure format is a string and not a pointer.
    This prevents usages like:
    
      spice_debug(NULL);
    
    This forbids computed format strings, but on the other hand, forcing
    the use of string constants allows the compiler to always check
    argument types against the format string. Moreover, there is no
    occurrences of computed format strings in the current codebase.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.h b/common/log.h
index 9f5fcbb..06d48d2 100644
--- a/common/log.h
+++ b/common/log.h
@@ -62,23 +62,23 @@ void spice_log(GLogLevelFlags log_level,
 } G_STMT_END
 
 #define spice_info(format, ...) G_STMT_START {                         \
-    spice_log(G_LOG_LEVEL_INFO, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_INFO, SPICE_STRLOC, __FUNCTION__, "" format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_debug(format, ...) G_STMT_START {                         \
-    spice_log(G_LOG_LEVEL_DEBUG, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_DEBUG, SPICE_STRLOC, __FUNCTION__, "" format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_warning(format, ...) G_STMT_START {                       \
-    spice_log(G_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, "" format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_critical(format, ...) G_STMT_START {                          \
-    spice_log(G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, "" format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_error(format, ...) G_STMT_START {                         \
-    spice_log(G_LOG_LEVEL_ERROR, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_ERROR, SPICE_STRLOC, __FUNCTION__, "" format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_warn_if_fail(x) G_STMT_START {            \
commit 518c57db20d31c19973eb9d80852ea6b032cf176
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Jun 16 09:59:45 2017 +0100

    log: Forbid the usage of obsolete SPICE_LOG_DOMAIN
    
    As we decided to not use multiple GLib domains, the SPICE_LOG_DOMAIN
    macro is not really useful. This commit removes it.
    Will be replaced by some different categorization.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/common/log.c b/common/log.c
index 92f5bc0..9b4757b 100644
--- a/common/log.c
+++ b/common/log.c
@@ -41,6 +41,8 @@ static int abort_mask = 0;
 #endif
 #endif
 
+#define G_LOG_DOMAIN "Spice"
+
 typedef enum {
     SPICE_LOG_LEVEL_ERROR,
     SPICE_LOG_LEVEL_CRITICAL,
@@ -91,10 +93,10 @@ static void spice_log_set_debug_level(void)
              */
             debug_env = (char *)g_getenv("G_MESSAGES_DEBUG");
             if (debug_env == NULL) {
-                g_setenv("G_MESSAGES_DEBUG", SPICE_LOG_DOMAIN, FALSE);
+                g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, FALSE);
             } else {
-                debug_env = g_strconcat(debug_env, " ", SPICE_LOG_DOMAIN, NULL);
-                g_setenv("G_MESSAGES_DEBUG", SPICE_LOG_DOMAIN, FALSE);
+                debug_env = g_strconcat(debug_env, " ", G_LOG_DOMAIN, NULL);
+                g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, FALSE);
                 g_free(debug_env);
             }
         }
@@ -117,7 +119,7 @@ static void spice_log_set_abort_level(void)
                 glib_abort_level >>= 1;
             }
             abort_mask = fatal_mask;
-            g_log_set_fatal_mask(SPICE_LOG_DOMAIN, fatal_mask);
+            g_log_set_fatal_mask(G_LOG_DOMAIN, fatal_mask);
         } else {
             abort_mask = SPICE_ABORT_MASK_DEFAULT;
         }
@@ -140,7 +142,7 @@ SPICE_CONSTRUCTOR_FUNC(spice_log_init)
 
     spice_log_set_debug_level();
     spice_log_set_abort_level();
-    g_log_set_handler(SPICE_LOG_DOMAIN,
+    g_log_set_handler(G_LOG_DOMAIN,
                       G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
                       spice_logger, NULL);
     /* Threading is always enabled from 2.31.0 onwards */
@@ -182,8 +184,7 @@ static void spice_logv(const char *log_domain,
     }
 }
 
-void spice_log(const char *log_domain,
-               GLogLevelFlags log_level,
+void spice_log(GLogLevelFlags log_level,
                const char *strloc,
                const char *function,
                const char *format,
@@ -192,6 +193,6 @@ void spice_log(const char *log_domain,
     va_list args;
 
     va_start (args, format);
-    spice_logv (log_domain, log_level, strloc, function, format, args);
+    spice_logv (G_LOG_DOMAIN, log_level, strloc, function, format, args);
     va_end (args);
 }
diff --git a/common/log.h b/common/log.h
index a4d296d..9f5fcbb 100644
--- a/common/log.h
+++ b/common/log.h
@@ -27,35 +27,34 @@
 
 SPICE_BEGIN_DECLS
 
-#ifndef SPICE_LOG_DOMAIN
-#define SPICE_LOG_DOMAIN "Spice"
+#ifdef SPICE_LOG_DOMAIN
+#error Do not use obsolete SPICE_LOG_DOMAIN macro, is currently unused
 #endif
 
 #define SPICE_STRLOC  __FILE__ ":" G_STRINGIFY (__LINE__)
 
-void spice_log(const char *log_domain,
-               GLogLevelFlags log_level,
+void spice_log(GLogLevelFlags log_level,
                const char *strloc,
                const char *function,
                const char *format,
-               ...) SPICE_ATTR_PRINTF(5, 6);
+               ...) SPICE_ATTR_PRINTF(4, 5);
 
 #define spice_return_if_fail(x) G_STMT_START {                          \
     if G_LIKELY(x) { } else {                                           \
-        spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, G_STRFUNC, "condition `%s' failed", #x); \
+        spice_log(G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, G_STRFUNC, "condition `%s' failed", #x); \
         return;                                                         \
     }                                                                   \
 } G_STMT_END
 
 #define spice_return_val_if_fail(x, val) G_STMT_START {                 \
     if G_LIKELY(x) { } else {                                           \
-        spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, "condition `%s' failed", #x); \
+        spice_log(G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, "condition `%s' failed", #x); \
         return (val);                                                   \
     }                                                                   \
 } G_STMT_END
 
 #define spice_warn_if_reached() G_STMT_START {                          \
-    spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, "should not be reached"); \
+    spice_log(G_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, "should not be reached"); \
 } G_STMT_END
 
 #define spice_printerr(format, ...) G_STMT_START {                      \
@@ -63,23 +62,23 @@ void spice_log(const char *log_domain,
 } G_STMT_END
 
 #define spice_info(format, ...) G_STMT_START {                         \
-    spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_INFO, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_INFO, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_debug(format, ...) G_STMT_START {                         \
-    spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_DEBUG, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_warning(format, ...) G_STMT_START {                       \
-    spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_critical(format, ...) G_STMT_START {                          \
-    spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_error(format, ...) G_STMT_START {                         \
-    spice_log(SPICE_LOG_DOMAIN, G_LOG_LEVEL_ERROR, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
+    spice_log(G_LOG_LEVEL_ERROR, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \
 } G_STMT_END
 
 #define spice_warn_if_fail(x) G_STMT_START {            \
diff --git a/tests/test-logging.c b/tests/test-logging.c
index f1ad1b6..9852b13 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -19,7 +19,6 @@
 #endif
 
 #define G_LOG_DOMAIN "Spice"
-#define SPICE_LOG_DOMAIN G_LOG_DOMAIN
 
 #include <glib.h>
 #include <stdlib.h>
@@ -168,15 +167,15 @@ static void test_spice_non_fatal_g_return_if_fail(void)
 static void test_log_levels(void)
 {
     if (g_test_subprocess()) {
-        g_test_expect_message(SPICE_LOG_DOMAIN,
+        g_test_expect_message(G_LOG_DOMAIN,
                               G_LOG_LEVEL_WARNING,
                               "*spice_warning");
         spice_warning("spice_warning");
-        g_test_expect_message(SPICE_LOG_DOMAIN,
+        g_test_expect_message(G_LOG_DOMAIN,
                               G_LOG_LEVEL_INFO,
                               "*spice_info");
         spice_info("spice_info");
-        g_test_expect_message(SPICE_LOG_DOMAIN,
+        g_test_expect_message(G_LOG_DOMAIN,
                               G_LOG_LEVEL_DEBUG,
                               "*spice_debug");
         spice_debug("spice_debug");


More information about the Spice-commits mailing list