Repository: mesos Updated Branches: refs/heads/master 6a3273d8e -> 9a3001c0b
Switch [stout] to using compiler intrinsics for unreachable, exit, and abort Use compiler intrinsics for unreachable, exit, and abort Makes the functions not need to pretend to return something while still silencing the compiler warnings. Replaces 25191 (I originally authored the patch, but Patrick was managing it for various reasons). Incorporates the fix suggested by Ben Mahler. Fixes Dominic's build issue. Review: https://reviews.apache.org/r/26100 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fc1101c9 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fc1101c9 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fc1101c9 Branch: refs/heads/master Commit: fc1101c9a598d4537502e3f54b1e791e18448840 Parents: 6a3273d Author: Cody Maloney <[email protected]> Authored: Mon Sep 29 12:02:33 2014 -0700 Committer: Dominic Hamon <[email protected]> Committed: Mon Sep 29 12:02:33 2014 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/abort.hpp | 74 +++++--------------- .../3rdparty/stout/include/stout/exit.hpp | 2 +- .../3rdparty/stout/include/stout/os.hpp | 4 +- .../stout/include/stout/os/sendfile.hpp | 2 +- .../stout/include/stout/unreachable.hpp | 27 ++----- 5 files changed, 25 insertions(+), 84 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/fc1101c9/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp index f20feea..6b5b5d1 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/abort.hpp @@ -25,65 +25,23 @@ #define _STRINGIZE(x) __STRINGIZE(x) #define _ABORT_PREFIX "ABORT: (" __FILE__ ":" _STRINGIZE(__LINE__) "): " -#define ABORT(...) _Abort(_ABORT_PREFIX)(__VA_ARGS__) +#define ABORT(...) _Abort(_ABORT_PREFIX, __VA_ARGS__) -struct _Abort +inline __attribute__((noreturn)) void _Abort( + const char *prefix, + const char *msg) { - _Abort(const char* _prefix) : prefix(_prefix) {} - - void operator () ( - const char* arg0 = NULL, - const char* arg1 = NULL, - const char* arg2 = NULL, - const char* arg3 = NULL, - const char* arg4 = NULL, - const char* arg5 = NULL, - const char* arg6 = NULL, - const char* arg7 = NULL, - const char* arg8 = NULL, - const char* arg9 = NULL) - { - // Write the failure message in an async-signal safe manner, - // assuming strlen is async-signal safe or optimized out. - // In fact, it is highly unlikely that strlen would be - // implemented in an unsafe manner: - // http://austingroupbugs.net/view.php?id=692 - while (write(STDERR_FILENO, prefix, strlen(prefix)) == -1 && - errno == EINTR); - while (arg0 != NULL && - write(STDERR_FILENO, arg0, strlen(arg0)) == -1 && - errno == EINTR); - while (arg1 != NULL && - write(STDERR_FILENO, arg1, strlen(arg1)) == -1 && - errno == EINTR); - while (arg2 != NULL && - write(STDERR_FILENO, arg2, strlen(arg2)) == -1 && - errno == EINTR); - while (arg3 != NULL && - write(STDERR_FILENO, arg3, strlen(arg3)) == -1 && - errno == EINTR); - while (arg4 != NULL && - write(STDERR_FILENO, arg4, strlen(arg4)) == -1 && - errno == EINTR); - while (arg5 != NULL && - write(STDERR_FILENO, arg5, strlen(arg5)) == -1 && - errno == EINTR); - while (arg6 != NULL && - write(STDERR_FILENO, arg6, strlen(arg6)) == -1 && - errno == EINTR); - while (arg7 != NULL && - write(STDERR_FILENO, arg7, strlen(arg7)) == -1 && - errno == EINTR); - while (arg8 != NULL && - write(STDERR_FILENO, arg8, strlen(arg8)) == -1 && - errno == EINTR); - while (arg9 != NULL && - write(STDERR_FILENO, arg9, strlen(arg9)) == -1 && - errno == EINTR); - abort(); - } - - const char* prefix; -}; + // Write the failure message in an async-signal safe manner, + // assuming strlen is async-signal safe or optimized out. + // In fact, it is highly unlikely that strlen would be + // implemented in an unsafe manner: + // http://austingroupbugs.net/view.php?id=692 + while (write(STDERR_FILENO, prefix, strlen(prefix)) == -1 && + errno == EINTR); + while (msg != NULL && + write(STDERR_FILENO, msg, strlen(msg)) == -1 && + errno == EINTR); + abort(); +} #endif // __STOUT_ABORT_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/fc1101c9/3rdparty/libprocess/3rdparty/stout/include/stout/exit.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/exit.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/exit.hpp index aaccbb4..8c16a22 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/exit.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/exit.hpp @@ -32,7 +32,7 @@ struct __Exit { __Exit(int _status) : status(_status) {} - ~__Exit() + __attribute__((noreturn)) ~__Exit() { std::cerr << out.str() << std::endl; exit(status); http://git-wip-us.apache.org/repos/asf/mesos/blob/fc1101c9/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp index 23628a4..ec41fe4 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp @@ -721,7 +721,7 @@ inline Result<uid_t> getuid(const Option<std::string>& user = None()) } } - return Result<uid_t>(UNREACHABLE()); + UNREACHABLE(); } @@ -776,7 +776,7 @@ inline Result<gid_t> getgid(const Option<std::string>& user = None()) } } - return Result<gid_t>(UNREACHABLE()); + UNREACHABLE(); } http://git-wip-us.apache.org/repos/asf/mesos/blob/fc1101c9/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp index 5607896..81d64cc 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sendfile.hpp @@ -44,7 +44,7 @@ inline ssize_t sendfile(int s, int fd, off_t offset, size_t length) // This will set errno to EPIPE if a SIGPIPE occurs. return ::sendfile(s, fd, &offset, length); } - return UNREACHABLE(); + UNREACHABLE(); #elif defined __APPLE__ // On OS X, sendfile does not need to have SIGPIPE suppressed. off_t _length = static_cast<off_t>(length); http://git-wip-us.apache.org/repos/asf/mesos/blob/fc1101c9/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp index 3568886..fed0a7b 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/unreachable.hpp @@ -18,27 +18,10 @@ #define UNREACHABLE() Unreachable(__FILE__, __LINE__) -struct Unreachable -{ - Unreachable(const std::string& _file, int _line) - : file(_file), line(_line) {} - - template <typename T> - operator T () const - { - // TODO(benh): Print stack trace too. - std::cerr << "Reached unreachable statement at " - << file << ":" << line << std::endl; - abort(); - - // Note that dereference a T* since T might not be default - // constructable and can't just 'return T()'. - return *((T*) NULL); - } - -private: - const std::string file; - const int line; -}; +inline __attribute__((noreturn)) void Unreachable(const char *file, int line) { + std::cerr << "Reached unreachable statement at " << file << ':' + << line << std::endl; + abort(); +} #endif // __STOUT_UNREACHABLE_HPP__
