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

use to_ascii_decimal in FOLLY_SAFE_CHECK

Summary: Use `folly::to_ascii_decimal` in `FOLLY_SAFE_CHECK` and related facility implementations. This facility is intentionally async-signal-safe on its own and is light on its dependencies. Specifically, avoid the dependency on `folly/Conv.h` which is heavier.

Reviewed By: luciang

Differential Revision: D26597237

fbshipit-source-id: e3cf0b3a3046cdbd3da89cc8a2e0627edb5a5a85
parent 32d05841
......@@ -18,8 +18,8 @@
#include <algorithm>
#include <folly/Conv.h>
#include <folly/detail/FileUtilDetail.h>
#include <folly/lang/ToAscii.h>
#include <folly/portability/Unistd.h>
namespace folly {
......@@ -461,6 +461,8 @@ void assertionFailure(
unsigned int line,
const char* function,
int error) {
char buf[to_ascii_size_max_decimal<uint64_t>()];
writeStderr("\n\nAssertion failure: ");
writeStderr(expr + 1, strlen(expr) - 2);
writeStderr("\nMessage: ");
......@@ -468,9 +470,7 @@ void assertionFailure(
writeStderr("\nFile: ");
writeStderr(file);
writeStderr("\nLine: ");
char buf[20];
uint32_t n = uint64ToBufferUnsafe(line, buf);
writeStderr(buf, n);
writeStderr(buf, to_ascii_decimal(buf, line));
writeStderr("\nFunction: ");
writeStderr(function);
if (error) {
......@@ -478,8 +478,7 @@ void assertionFailure(
// the symbolic constant is necessary since actual numbers may vary
// for simplicity, do not attempt to mimic strerror printing descriptions
writeStderr("\nError: ");
n = uint64ToBufferUnsafe(error, buf);
writeStderr(buf, n);
writeStderr(buf, to_ascii_decimal(buf, error));
writeStderr(" (");
// the list is not required to be sorted; but the program is about to die
auto const pred = [=](auto const e) { return e.first == error; };
......
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