[Spice-devel] [PATCH] log: add not fatal spice_return function

Frediano Ziglio fziglio at redhat.com
Thu Nov 19 06:41:52 PST 2015


Due to implementation details spice_return is by default fatal (program
is aborting). This is quite confusing but changing the current macros
would possibly break existing code.
Add not fatal (at least by default) macros. They use warning level
instead of critical.
This is also compatible with Glib macros.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 common/log.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/common/log.h b/common/log.h
index d9e6023..bb5035b 100644
--- a/common/log.h
+++ b/common/log.h
@@ -73,6 +73,24 @@ void spice_log(const char *log_domain,
 } SPICE_STMT_END
 #endif
 
+#ifndef spice_return_if_fail_warning
+#define spice_return_if_fail_warning(x) SPICE_STMT_START {                      \
+    if SPICE_LIKELY(x) { } else {                                       \
+        spice_warning("condition `%s' failed", #x); \
+        return;                                                         \
+    }                                                                   \
+} SPICE_STMT_END
+#endif
+
+#ifndef spice_return_val_if_fail_warning
+#define spice_return_val_if_fail_warning(x, val) SPICE_STMT_START {             \
+    if SPICE_LIKELY(x) { } else {                                       \
+        spice_warning("condition `%s' failed", #x); \
+        return (val);                                                   \
+    }                                                                   \
+} SPICE_STMT_END
+#endif
+
 #ifndef spice_warn_if_reached
 #define spice_warn_if_reached() SPICE_STMT_START {                      \
     spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_WARNING, SPICE_STRLOC, __FUNCTION__, "should not be reached"); \
-- 
2.4.3



More information about the Spice-devel mailing list