Skip to content

Commit f027290

Browse files
committed
src: use struct as arguments to node::Assert
This just makes the code a bit more obvious (subjectively). PR-URL: #25869 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 1f6acbb commit f027290

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/node_errors.cc

+6-12
Original file line numberDiff line numberDiff line change
@@ -166,23 +166,17 @@ void AppendExceptionLine(Environment* env,
166166
ABORT_NO_BACKTRACE();
167167
}
168168

169-
[[noreturn]] void Assert(const char* const (*args)[4]) {
170-
auto filename = (*args)[0];
171-
auto linenum = (*args)[1];
172-
auto message = (*args)[2];
173-
auto function = (*args)[3];
174-
169+
[[noreturn]] void Assert(const AssertionInfo& info) {
175170
char name[1024];
176171
GetHumanReadableProcessName(&name);
177172

178173
fprintf(stderr,
179-
"%s: %s:%s:%s%s Assertion `%s' failed.\n",
174+
"%s: %s:%s%s Assertion `%s' failed.\n",
180175
name,
181-
filename,
182-
linenum,
183-
function,
184-
*function ? ":" : "",
185-
message);
176+
info.file_line,
177+
info.function,
178+
*info.function ? ":" : "",
179+
info.message);
186180
fflush(stderr);
187181

188182
Abort();

src/util.h

+14-6
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ extern bool v8_initialized;
8585
// whether V8 is initialized.
8686
void LowMemoryNotification();
8787

88-
// The slightly odd function signature for Assert() is to ease
89-
// instruction cache pressure in calls from CHECK.
88+
// The reason that Assert() takes a struct argument instead of individual
89+
// const char*s is to ease instruction cache pressure in calls from CHECK.
90+
struct AssertionInfo {
91+
const char* file_line; // filename:line
92+
const char* message;
93+
const char* function;
94+
};
95+
[[noreturn]] void Assert(const AssertionInfo& info);
9096
[[noreturn]] void Abort();
91-
[[noreturn]] void Assert(const char* const (*args)[4]);
9297
void DumpBacktrace(FILE* fp);
9398

9499
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
@@ -120,9 +125,12 @@ void DumpBacktrace(FILE* fp);
120125
#define CHECK(expr) \
121126
do { \
122127
if (UNLIKELY(!(expr))) { \
123-
static const char* const args[] = { __FILE__, STRINGIFY(__LINE__), \
124-
#expr, PRETTY_FUNCTION_NAME }; \
125-
node::Assert(&args); \
128+
/* Make sure that this struct does not end up in inline code, but */ \
129+
/* rather in a read-only data section when modifying this code. */ \
130+
static const node::AssertionInfo args = { \
131+
__FILE__ ":" STRINGIFY(__LINE__), #expr, PRETTY_FUNCTION_NAME \
132+
}; \
133+
node::Assert(args); \
126134
} \
127135
} while (0)
128136

0 commit comments

Comments
 (0)