From 7564e4fda9d51fb5580418db742e6b7f56bf0557 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 1 Feb 2019 15:38:28 +0100 Subject: [PATCH 1/3] src: use struct as arguments to node::Assert This just makes the code a bit more obvious (subjectively). --- src/node_errors.cc | 19 +++++++------------ src/util.h | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 5a9f08839ceb52..993393da93a87c 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -166,23 +166,18 @@ 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:%u:%s%s Assertion `%s' failed.\n", name, - filename, - linenum, - function, - *function ? ":" : "", - message); + info.filename, + info.linenum, + info.function, + *info.function ? ":" : "", + info.message); fflush(stderr); Abort(); diff --git a/src/util.h b/src/util.h index fcb543fcacfaab..d02057bfe4fd84 100644 --- a/src/util.h +++ b/src/util.h @@ -85,10 +85,16 @@ 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* filename; + unsigned int linenum; + 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 +126,10 @@ 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); \ + static const node::AssertionInfo args = { \ + __FILE__, __LINE__, #expr, PRETTY_FUNCTION_NAME \ + }; \ + node::Assert(args); \ } \ } while (0) From b60184f25524aa865014df6c2468604192ea5339 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 1 Feb 2019 20:12:46 +0100 Subject: [PATCH 2/3] fixup! src: use struct as arguments to node::Assert --- src/util.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util.h b/src/util.h index d02057bfe4fd84..64b8cb602b4d44 100644 --- a/src/util.h +++ b/src/util.h @@ -126,6 +126,8 @@ void DumpBacktrace(FILE* fp); #define CHECK(expr) \ do { \ if (UNLIKELY(!(expr))) { \ + /* 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__, __LINE__, #expr, PRETTY_FUNCTION_NAME \ }; \ From 9d404ba51f972fb9dc62c86bfdbd33604e070b41 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 2 Feb 2019 14:22:31 +0100 Subject: [PATCH 3/3] fixup! src: use struct as arguments to node::Assert --- src/node_errors.cc | 5 ++--- src/util.h | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 993393da93a87c..ab608f96dd0bc1 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -171,10 +171,9 @@ void AppendExceptionLine(Environment* env, GetHumanReadableProcessName(&name); fprintf(stderr, - "%s: %s:%u:%s%s Assertion `%s' failed.\n", + "%s: %s:%s%s Assertion `%s' failed.\n", name, - info.filename, - info.linenum, + info.file_line, info.function, *info.function ? ":" : "", info.message); diff --git a/src/util.h b/src/util.h index 64b8cb602b4d44..b199476aa246bf 100644 --- a/src/util.h +++ b/src/util.h @@ -88,8 +88,7 @@ void LowMemoryNotification(); // 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* filename; - unsigned int linenum; + const char* file_line; // filename:line const char* message; const char* function; }; @@ -129,7 +128,7 @@ void DumpBacktrace(FILE* fp); /* 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__, __LINE__, #expr, PRETTY_FUNCTION_NAME \ + __FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \ }; \ node::Assert(args); \ } \