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 <psychon@znc.in>
This commit is contained in:
parent
3cfb577387
commit
01e61079c3
|
@ -319,6 +319,12 @@ void _fatal(int, const char *, const char *, ...)
|
||||||
void _warn(int, const char *, const char *, ...)
|
void _warn(int, const char *, const char *, ...)
|
||||||
__attribute__ ((format(printf, 3, 4)));
|
__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);
|
const char *a_current_time_str(void);
|
||||||
|
|
||||||
void a_exec(const char *);
|
void a_exec(const char *);
|
||||||
|
|
|
@ -1078,7 +1078,7 @@ client_ban(client_t *c)
|
||||||
void
|
void
|
||||||
client_ignore_enterleave_events(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);
|
globalconf.pending_enter_leave_begin = xcb_grab_server(globalconf.connection);
|
||||||
/* If the connection is broken, we get a request with sequence number 0
|
/* If the connection is broken, we get a request with sequence number 0
|
||||||
* which would then trigger an assertion in
|
* which would then trigger an assertion in
|
||||||
|
@ -1087,7 +1087,7 @@ client_ignore_enterleave_events(void)
|
||||||
if(xcb_connection_has_error(globalconf.connection))
|
if(xcb_connection_has_error(globalconf.connection))
|
||||||
fatal("X server connection broke (error %d)",
|
fatal("X server connection broke (error %d)",
|
||||||
xcb_connection_has_error(globalconf.connection));
|
xcb_connection_has_error(globalconf.connection));
|
||||||
assert(globalconf.pending_enter_leave_begin.sequence != 0);
|
check(globalconf.pending_enter_leave_begin.sequence != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1095,7 +1095,7 @@ client_restore_enterleave_events(void)
|
||||||
{
|
{
|
||||||
sequence_pair_t pair;
|
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.begin = globalconf.pending_enter_leave_begin;
|
||||||
pair.end = xcb_no_operation(globalconf.connection);
|
pair.end = xcb_no_operation(globalconf.connection);
|
||||||
xcb_ungrab_server(globalconf.connection);
|
xcb_ungrab_server(globalconf.connection);
|
||||||
|
|
|
@ -566,7 +566,7 @@ screen_scan(void)
|
||||||
screen_scan_xinerama(L, &globalconf.screens);
|
screen_scan_xinerama(L, &globalconf.screens);
|
||||||
if (globalconf.screens.len == 0)
|
if (globalconf.screens.len == 0)
|
||||||
screen_scan_x11(L, &globalconf.screens);
|
screen_scan_x11(L, &globalconf.screens);
|
||||||
assert(globalconf.screens.len > 0);
|
check(globalconf.screens.len > 0);
|
||||||
|
|
||||||
screen_deduplicate(L, &globalconf.screens);
|
screen_deduplicate(L, &globalconf.screens);
|
||||||
|
|
||||||
|
|
2
spawn.c
2
spawn.c
|
@ -351,7 +351,7 @@ child_exit_callback(GPid pid, gint status, gpointer user_data)
|
||||||
lua_pushliteral(L, "exit");
|
lua_pushliteral(L, "exit");
|
||||||
lua_pushinteger(L, WEXITSTATUS(status));
|
lua_pushinteger(L, WEXITSTATUS(status));
|
||||||
} else {
|
} else {
|
||||||
assert(WIFSIGNALED(status));
|
check(WIFSIGNALED(status));
|
||||||
lua_pushliteral(L, "signal");
|
lua_pushliteral(L, "signal");
|
||||||
lua_pushinteger(L, WTERMSIG(status));
|
lua_pushinteger(L, WTERMSIG(status));
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +308,7 @@ xwindow_get_shape(xcb_window_t win, enum xcb_shape_sk_t kind)
|
||||||
height = extents->bounding_shape_extents_height;
|
height = extents->bounding_shape_extents_height;
|
||||||
shaped = extents->bounding_shaped;
|
shaped = extents->bounding_shaped;
|
||||||
} else {
|
} else {
|
||||||
assert(kind == XCB_SHAPE_SK_CLIP);
|
check(kind == XCB_SHAPE_SK_CLIP);
|
||||||
x = extents->clip_shape_extents_x;
|
x = extents->clip_shape_extents_x;
|
||||||
y = extents->clip_shape_extents_y;
|
y = extents->clip_shape_extents_y;
|
||||||
width = extents->clip_shape_extents_width;
|
width = extents->clip_shape_extents_width;
|
||||||
|
|
Loading…
Reference in New Issue