diff --git a/src/unix/error.c b/src/unix/error.c index 80d3270d..3d9c4072 100644 --- a/src/unix/error.c +++ b/src/unix/error.c @@ -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(); } diff --git a/src/unix/internal.h b/src/unix/internal.h index a962073c..2bdd35cd 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -25,6 +25,8 @@ #include "uv-common.h" #include "uv-eio.h" +#include +#include /* abort */ #include /* 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 { diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index cea58335..68d064da 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -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 */ diff --git a/src/unix/linux.c b/src/unix/linux.c index 12473596..2f04cb8d 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -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 */ diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 49d372b4..a87a2343 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -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 */