src: use struct as arguments to node::Assert
This just makes the code a bit more obvious (subjectively). PR-URL: https://github.com/nodejs/node/pull/25869 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
d0bce9a82d
commit
30545a5b21
@ -166,23 +166,17 @@ void AppendExceptionLine(Environment* env,
|
|||||||
ABORT_NO_BACKTRACE();
|
ABORT_NO_BACKTRACE();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void Assert(const char* const (*args)[4]) {
|
[[noreturn]] void Assert(const AssertionInfo& info) {
|
||||||
auto filename = (*args)[0];
|
|
||||||
auto linenum = (*args)[1];
|
|
||||||
auto message = (*args)[2];
|
|
||||||
auto function = (*args)[3];
|
|
||||||
|
|
||||||
char name[1024];
|
char name[1024];
|
||||||
GetHumanReadableProcessName(&name);
|
GetHumanReadableProcessName(&name);
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: %s:%s:%s%s Assertion `%s' failed.\n",
|
"%s: %s:%s%s Assertion `%s' failed.\n",
|
||||||
name,
|
name,
|
||||||
filename,
|
info.file_line,
|
||||||
linenum,
|
info.function,
|
||||||
function,
|
*info.function ? ":" : "",
|
||||||
*function ? ":" : "",
|
info.message);
|
||||||
message);
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
Abort();
|
Abort();
|
||||||
|
20
src/util.h
20
src/util.h
@ -85,10 +85,15 @@ extern bool v8_initialized;
|
|||||||
// whether V8 is initialized.
|
// whether V8 is initialized.
|
||||||
void LowMemoryNotification();
|
void LowMemoryNotification();
|
||||||
|
|
||||||
// The slightly odd function signature for Assert() is to ease
|
// The reason that Assert() takes a struct argument instead of individual
|
||||||
// instruction cache pressure in calls from CHECK.
|
// const char*s is to ease instruction cache pressure in calls from CHECK.
|
||||||
|
struct AssertionInfo {
|
||||||
|
const char* file_line; // filename:line
|
||||||
|
const char* message;
|
||||||
|
const char* function;
|
||||||
|
};
|
||||||
|
[[noreturn]] void Assert(const AssertionInfo& info);
|
||||||
[[noreturn]] void Abort();
|
[[noreturn]] void Abort();
|
||||||
[[noreturn]] void Assert(const char* const (*args)[4]);
|
|
||||||
void DumpBacktrace(FILE* fp);
|
void DumpBacktrace(FILE* fp);
|
||||||
|
|
||||||
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
|
||||||
@ -120,9 +125,12 @@ void DumpBacktrace(FILE* fp);
|
|||||||
#define CHECK(expr) \
|
#define CHECK(expr) \
|
||||||
do { \
|
do { \
|
||||||
if (UNLIKELY(!(expr))) { \
|
if (UNLIKELY(!(expr))) { \
|
||||||
static const char* const args[] = { __FILE__, STRINGIFY(__LINE__), \
|
/* Make sure that this struct does not end up in inline code, but */ \
|
||||||
#expr, PRETTY_FUNCTION_NAME }; \
|
/* rather in a read-only data section when modifying this code. */ \
|
||||||
node::Assert(&args); \
|
static const node::AssertionInfo args = { \
|
||||||
|
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
|
||||||
|
}; \
|
||||||
|
node::Assert(args); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user