Commit c24b947e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

FOLLY_SAFE_FATAL

Summary: Like `FOLLY_SAFE_CHECK(true, ...)`.

Reviewed By: luciang

Differential Revision: D33801512

fbshipit-source-id: c9023f4b14e0b045c654c15a8f2b9ea0cc384617
parent e03edde8
...@@ -521,8 +521,10 @@ void flushStderr() { ...@@ -521,8 +521,10 @@ void flushStderr() {
auto const& arg = *arg_; auto const& arg = *arg_;
char buf[to_ascii_size_max_decimal<uint64_t>]; char buf[to_ascii_size_max_decimal<uint64_t>];
writeStderr("\n\nAssertion failure: "); if (arg.expr) {
writeStderr(arg.expr + 1, strlen(arg.expr) - 2); writeStderr("\n\nAssertion failure: ");
writeStderr(arg.expr + 1, strlen(arg.expr) - 2);
}
if (*arg.msg_types != safe_assert_msg_type::term) { if (*arg.msg_types != safe_assert_msg_type::term) {
writeStderr("\nMessage: "); writeStderr("\nMessage: ");
auto msg_types = arg.msg_types; auto msg_types = arg.msg_types;
......
...@@ -91,6 +91,35 @@ ...@@ -91,6 +91,35 @@
FOLLY_DETAIL_SAFE_CHECK_IMPL( \ FOLLY_DETAIL_SAFE_CHECK_IMPL( \
0, 1, (expr), FOLLY_PP_STRINGIZE(expr), __VA_ARGS__) 0, 1, (expr), FOLLY_PP_STRINGIZE(expr), __VA_ARGS__)
// FOLLY_SAFE_PCHECK
//
// Equivalent to FOLLY_SAFE_CHECK but includes errno in the context information
// printed to stderr.
//
// multi-thread-safe
// async-signal-safe
#define FOLLY_SAFE_DPCHECK(expr, ...) \
FOLLY_DETAIL_SAFE_CHECK_IMPL( \
1, 1, (expr), FOLLY_PP_STRINGIZE(expr), __VA_ARGS__)
// FOLLY_SAFE_FATAL
//
// Equivalent to FOLLY_SAFE_CHECK(false, ...)
//
// multi-thread-safe
// async-signal-safe
#define FOLLY_SAFE_FATAL(...) \
FOLLY_DETAIL_SAFE_CHECK_IMPL(0, 0, false, nullptr, __VA_ARGS__)
// FOLLY_SAFE_DFATAL
//
// Equivalent to FOLLY_SAFE_DCHECK(false, ...)
//
// multi-thread-safe
// async-signal-safe
#define FOLLY_SAFE_DFATAL(...) \
FOLLY_DETAIL_SAFE_CHECK_IMPL(1, 0, false, nullptr, __VA_ARGS__)
namespace folly { namespace folly {
namespace detail { namespace detail {
......
...@@ -67,3 +67,9 @@ TEST(SafeAssert, AssertionFailureErrno) { ...@@ -67,3 +67,9 @@ TEST(SafeAssert, AssertionFailureErrno) {
([] { FOLLY_SAFE_PCHECK((errno = 999) && false, "hello"); }()), ([] { FOLLY_SAFE_PCHECK((errno = 999) && false, "hello"); }()),
folly::to<std::string>("Error: 999 \\(<unknown>\\)")); folly::to<std::string>("Error: 999 \\(<unknown>\\)"));
} }
TEST(SafeAssert, Fatal) {
EXPECT_DEATH( //
([] { FOLLY_SAFE_FATAL("hello"); })(),
"Message: hello");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment