They can be used in spice-server to replace spice_return_if_fail. Currently spice_return_if_fail aborts in spice-server, and it's not always clear whether using a non-aborting g_return_if_fail is acceptable or not. Having a spice_assert_if_fail alternative makes it clearer that this is not going to return, while having a name distinct from assert() so that places which needs reviewing can be spotted more easily. Acked-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> --- common/log.h | 3 +++ tests/test-logging.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/common/log.h b/common/log.h index 0e03f59..b83b0e0 100644 --- a/common/log.h +++ b/common/log.h @@ -95,6 +95,9 @@ void spice_log(const char *log_domain, } \ } G_STMT_END +#define spice_assert_val_if_fail(cond, val) spice_assert(cond) +#define spice_assert_if_fail(cond) spice_assert(cond) + #define spice_assert(x) G_STMT_START { \ if G_LIKELY(x) { } else { \ spice_error("assertion `%s' failed", #x); \ diff --git a/tests/test-logging.c b/tests/test-logging.c index 008ce48..0880fff 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -166,6 +166,17 @@ static void test_spice_non_fatal_g_return_if_fail(void) g_test_trap_assert_passed(); } +/* Checks that spice_assert_if_fail() aborts */ +static void test_spice_fatal_assert_if_fail(void) +{ + if (g_test_subprocess()) { + spice_assert_if_fail(FALSE); + return; + } + g_test_trap_subprocess(NULL, 0, 0); + g_test_trap_assert_failed(); +} + /* Checks that spice_*, g_* and other_* (different log domain as g_*) all * go through g_log() with the correct domain/log level. This then checks * that only logs with level 'message' or higher are shown by default. @@ -401,6 +412,7 @@ int main(int argc, char **argv) g_test_add_func("/spice-common/spice-non-fatal-gcritical", test_spice_non_fatal_g_critical); g_test_add_func("/spice-common/spice-fatal-gcritical", test_spice_fatal_g_critical); g_test_add_func("/spice-common/spice-fatal-return-if-fail", test_spice_fatal_return_if_fail); + g_test_add_func("/spice-common/spice-fatal-assert-if-fail", test_spice_fatal_assert_if_fail); g_test_add_func("/spice-common/spice-non-fatal-greturn-if-fail", test_spice_non_fatal_g_return_if_fail); g_test_add_func("/spice-common/spice-fatal-warning", test_spice_fatal_warning); -- 2.5.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel