From f027290542138f84c827df6bdf0b7b17bea994dc Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 1 Feb 2019 15:38:28 +0100 Subject: [PATCH] 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 Reviewed-By: Refael Ackermann Reviewed-By: Ben Noordhuis --- src/node_errors.cc | 18 ++++++------------ src/util.h | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 23a65bd2251d62..c5e0f4a3269370 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -166,23 +166,17 @@ void AppendExceptionLine(Environment* env, ABORT_NO_BACKTRACE(); } -[[noreturn]] void Assert(const char* const (*args)[4]) { - auto filename = (*args)[0]; - auto linenum = (*args)[1]; - auto message = (*args)[2]; - auto function = (*args)[3]; - +[[noreturn]] void Assert(const AssertionInfo& info) { char name[1024]; GetHumanReadableProcessName(&name); fprintf(stderr, - "%s: %s:%s:%s%s Assertion `%s' failed.\n", + "%s: %s:%s%s Assertion `%s' failed.\n", name, - filename, - linenum, - function, - *function ? ":" : "", - message); + info.file_line, + info.function, + *info.function ? ":" : "", + info.message); fflush(stderr); Abort(); diff --git a/src/util.h b/src/util.h index fcb543fcacfaab..b199476aa246bf 100644 --- a/src/util.h +++ b/src/util.h @@ -85,10 +85,15 @@ extern bool v8_initialized; // whether V8 is initialized. void LowMemoryNotification(); -// The slightly odd function signature for Assert() is to ease -// instruction cache pressure in calls from CHECK. +// The reason that Assert() takes a struct argument instead of individual +// 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 Assert(const char* const (*args)[4]); void DumpBacktrace(FILE* fp); #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ @@ -120,9 +125,12 @@ void DumpBacktrace(FILE* fp); #define CHECK(expr) \ do { \ if (UNLIKELY(!(expr))) { \ - static const char* const args[] = { __FILE__, STRINGIFY(__LINE__), \ - #expr, PRETTY_FUNCTION_NAME }; \ - node::Assert(&args); \ + /* Make sure that this struct does not end up in inline code, but */ \ + /* rather in a read-only data section when modifying this code. */ \ + static const node::AssertionInfo args = { \ + __FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \ + }; \ + node::Assert(args); \ } \ } while (0)