From 01e61079c3bdf048ec10cab0c9e73aaac6ba6982 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 13 May 2017 23:22:15 +0200 Subject: [PATCH] Add & use a non-fatal kind of assert() (#1779) Aborting the process is sometimes a bit harsh for a failed assertion. This adds a non-fatal assert() macro called "check()" and uses it in some places where we might be able to survive the error. Signed-off-by: Uli Schlachter --- common/util.h | 6 ++++++ objects/client.c | 6 +++--- objects/screen.c | 2 +- spawn.c | 2 +- xwindow.c | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/common/util.h b/common/util.h index eaa9a58de..bd91947ae 100644 --- a/common/util.h +++ b/common/util.h @@ -319,6 +319,12 @@ void _fatal(int, const char *, const char *, ...) void _warn(int, const char *, const char *, ...) __attribute__ ((format(printf, 3, 4))); +#define check(condition) do { \ + if (!(condition)) \ + _warn(__LINE__, __FUNCTION__, \ + "Checking assertion failed: " #condition); \ + } while (0) + const char *a_current_time_str(void); void a_exec(const char *); diff --git a/objects/client.c b/objects/client.c index 3e871fe2c..1b4d9f6ab 100644 --- a/objects/client.c +++ b/objects/client.c @@ -1078,7 +1078,7 @@ client_ban(client_t *c) void client_ignore_enterleave_events(void) { - assert(globalconf.pending_enter_leave_begin.sequence == 0); + check(globalconf.pending_enter_leave_begin.sequence == 0); globalconf.pending_enter_leave_begin = xcb_grab_server(globalconf.connection); /* If the connection is broken, we get a request with sequence number 0 * which would then trigger an assertion in @@ -1087,7 +1087,7 @@ client_ignore_enterleave_events(void) if(xcb_connection_has_error(globalconf.connection)) fatal("X server connection broke (error %d)", xcb_connection_has_error(globalconf.connection)); - assert(globalconf.pending_enter_leave_begin.sequence != 0); + check(globalconf.pending_enter_leave_begin.sequence != 0); } void @@ -1095,7 +1095,7 @@ client_restore_enterleave_events(void) { sequence_pair_t pair; - assert(globalconf.pending_enter_leave_begin.sequence != 0); + check(globalconf.pending_enter_leave_begin.sequence != 0); pair.begin = globalconf.pending_enter_leave_begin; pair.end = xcb_no_operation(globalconf.connection); xcb_ungrab_server(globalconf.connection); diff --git a/objects/screen.c b/objects/screen.c index f81073f89..4e50199b1 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -566,7 +566,7 @@ screen_scan(void) screen_scan_xinerama(L, &globalconf.screens); if (globalconf.screens.len == 0) screen_scan_x11(L, &globalconf.screens); - assert(globalconf.screens.len > 0); + check(globalconf.screens.len > 0); screen_deduplicate(L, &globalconf.screens); diff --git a/spawn.c b/spawn.c index 57b369dd1..eb9e8a28a 100644 --- a/spawn.c +++ b/spawn.c @@ -351,7 +351,7 @@ child_exit_callback(GPid pid, gint status, gpointer user_data) lua_pushliteral(L, "exit"); lua_pushinteger(L, WEXITSTATUS(status)); } else { - assert(WIFSIGNALED(status)); + check(WIFSIGNALED(status)); lua_pushliteral(L, "signal"); lua_pushinteger(L, WTERMSIG(status)); } diff --git a/xwindow.c b/xwindow.c index 2de670115..c5ff9e722 100644 --- a/xwindow.c +++ b/xwindow.c @@ -308,7 +308,7 @@ xwindow_get_shape(xcb_window_t win, enum xcb_shape_sk_t kind) height = extents->bounding_shape_extents_height; shaped = extents->bounding_shaped; } else { - assert(kind == XCB_SHAPE_SK_CLIP); + check(kind == XCB_SHAPE_SK_CLIP); x = extents->clip_shape_extents_x; y = extents->clip_shape_extents_y; width = extents->clip_shape_extents_width;