unix: add UNREACHABLE() macro
Asserts and aborts when program flow reaches a place it shouldn't.
This commit is contained in:
parent
3de0411591
commit
cdb44df86d
@ -86,7 +86,5 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
||||
case ETIMEDOUT: return UV_ETIMEDOUT;
|
||||
default: return UV_UNKNOWN;
|
||||
}
|
||||
|
||||
assert(0 && "unreachable");
|
||||
return -1;
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
@ -25,6 +25,8 @@
|
||||
#include "uv-common.h"
|
||||
#include "uv-eio.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> /* abort */
|
||||
#include <stddef.h> /* offsetof */
|
||||
|
||||
#if __STRICT_ANSI__
|
||||
@ -133,13 +135,20 @@ inline static int sys_accept4(int fd,
|
||||
#define container_of(ptr, type, member) \
|
||||
((type *) ((char *) (ptr) - offsetof(type, member)))
|
||||
|
||||
#define SAVE_ERRNO(block) \
|
||||
do { \
|
||||
int _saved_errno = errno; \
|
||||
do { block; } while (0); \
|
||||
errno = _saved_errno; \
|
||||
} \
|
||||
while (0);
|
||||
#define UNREACHABLE() \
|
||||
do { \
|
||||
assert(0 && "unreachable code"); \
|
||||
abort(); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define SAVE_ERRNO(block) \
|
||||
do { \
|
||||
int _saved_errno = errno; \
|
||||
do { block; } while (0); \
|
||||
errno = _saved_errno; \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* flags */
|
||||
enum {
|
||||
|
||||
@ -141,13 +141,13 @@ int uv_fs_event_init(uv_loop_t* loop,
|
||||
|
||||
|
||||
void uv__fs_event_destroy(uv_fs_event_t* handle) {
|
||||
assert(0 && "unreachable");
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
|
||||
/* Called by libev, don't touch. */
|
||||
void uv__kqueue_hack(EV_P_ int fflags, ev_io *w) {
|
||||
assert(0 && "unreachable");
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
#endif /* HAVE_KQUEUE */
|
||||
|
||||
@ -679,8 +679,7 @@ int uv_fs_event_init(uv_loop_t* loop,
|
||||
|
||||
|
||||
void uv__fs_event_destroy(uv_fs_event_t* handle) {
|
||||
assert(0 && "unreachable");
|
||||
abort();
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
#endif /* HAVE_INOTIFY_INIT || HAVE_INOTIFY_INIT1 */
|
||||
|
||||
@ -214,7 +214,7 @@ int uv_fs_event_init(uv_loop_t* loop,
|
||||
|
||||
|
||||
void uv__fs_event_destroy(uv_fs_event_t* handle) {
|
||||
assert(0 && "unreachable"); /* should never be called */
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
#endif /* HAVE_PORTS_FS */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user