Skip to content

Commit eb7faf6

Browse files
bnoordhuisaddaleax
authored andcommitted
src: replace ASSERT with CHECK
Builds always have asserts enabled so there is no point distinguishing between debug-only checks and run-time checks. Replace calls to ASSERT and friends with their CHECK counterparts. Fixes: #14461 PR-URL: #14474 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: XadillaX <[email protected]>
1 parent 4ff562f commit eb7faf6

11 files changed

+36
-58
lines changed

node.gyp

+1-10
Original file line numberDiff line numberDiff line change
@@ -638,16 +638,7 @@
638638
'<(OBJ_TRACING_PATH)<(OBJ_SEPARATOR)trace_event.<(OBJ_SUFFIX)',
639639
],
640640

641-
'defines': [
642-
# gtest's ASSERT macros conflict with our own.
643-
'GTEST_DONT_DEFINE_ASSERT_EQ=1',
644-
'GTEST_DONT_DEFINE_ASSERT_GE=1',
645-
'GTEST_DONT_DEFINE_ASSERT_GT=1',
646-
'GTEST_DONT_DEFINE_ASSERT_LE=1',
647-
'GTEST_DONT_DEFINE_ASSERT_LT=1',
648-
'GTEST_DONT_DEFINE_ASSERT_NE=1',
649-
'NODE_WANT_INTERNALS=1',
650-
],
641+
'defines': [ 'NODE_WANT_INTERNALS=1' ],
651642

652643
'sources': [
653644
'test/cctest/test_base64.cc',

src/env-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,14 @@ inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) {
272272

273273
inline Environment* Environment::GetCurrent(
274274
const v8::FunctionCallbackInfo<v8::Value>& info) {
275-
ASSERT(info.Data()->IsExternal());
275+
CHECK(info.Data()->IsExternal());
276276
return static_cast<Environment*>(info.Data().As<v8::External>()->Value());
277277
}
278278

279279
template <typename T>
280280
inline Environment* Environment::GetCurrent(
281281
const v8::PropertyCallbackInfo<T>& info) {
282-
ASSERT(info.Data()->IsExternal());
282+
CHECK(info.Data()->IsExternal());
283283
// XXX(bnoordhuis) Work around a g++ 4.9.2 template type inferrer bug
284284
// when the expression is written as info.Data().As<v8::External>().
285285
v8::Local<v8::Value> data = info.Data();

src/inspector_socket.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static std::vector<char> encode_frame_hybi17(const char* message,
157157
}
158158
frame.insert(frame.end(), extended_payload_length,
159159
extended_payload_length + 8);
160-
ASSERT_EQ(0, remaining);
160+
CHECK_EQ(0, remaining);
161161
}
162162
frame.insert(frame.end(), message, message + data_length);
163163
return frame;
@@ -361,8 +361,8 @@ static void websockets_data_cb(uv_stream_t* stream, ssize_t nread,
361361

362362
int inspector_read_start(InspectorSocket* inspector,
363363
uv_alloc_cb alloc_cb, uv_read_cb read_cb) {
364-
ASSERT(inspector->ws_mode);
365-
ASSERT(!inspector->shutting_down || read_cb == nullptr);
364+
CHECK(inspector->ws_mode);
365+
CHECK(!inspector->shutting_down || read_cb == nullptr);
366366
inspector->ws_state->close_sent = false;
367367
inspector->ws_state->alloc_cb = alloc_cb;
368368
inspector->ws_state->read_cb = read_cb;
@@ -561,7 +561,7 @@ static void init_handshake(InspectorSocket* socket) {
561561

562562
int inspector_accept(uv_stream_t* server, InspectorSocket* socket,
563563
handshake_cb callback) {
564-
ASSERT_NE(callback, nullptr);
564+
CHECK_NE(callback, nullptr);
565565
CHECK_EQ(socket->http_parsing_state, nullptr);
566566

567567
socket->http_parsing_state = new http_parsing_state_s();
@@ -597,8 +597,8 @@ void inspector_close(InspectorSocket* inspector,
597597
inspector_cb callback) {
598598
// libuv throws assertions when closing stream that's already closed - we
599599
// need to do the same.
600-
ASSERT(!uv_is_closing(reinterpret_cast<uv_handle_t*>(&inspector->tcp)));
601-
ASSERT(!inspector->shutting_down);
600+
CHECK(!uv_is_closing(reinterpret_cast<uv_handle_t*>(&inspector->tcp)));
601+
CHECK(!inspector->shutting_down);
602602
inspector->shutting_down = true;
603603
inspector->ws_state->close_cb = callback;
604604
if (inspector->connection_eof) {

src/node_buffer.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,9 @@ int64_t IndexOfOffset(size_t length,
953953
}
954954

955955
void IndexOfString(const FunctionCallbackInfo<Value>& args) {
956-
ASSERT(args[1]->IsString());
957-
ASSERT(args[2]->IsNumber());
958-
ASSERT(args[4]->IsBoolean());
956+
CHECK(args[1]->IsString());
957+
CHECK(args[2]->IsNumber());
958+
CHECK(args[4]->IsBoolean());
959959

960960
enum encoding enc = ParseEncoding(args.GetIsolate(),
961961
args[3],
@@ -1069,9 +1069,9 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
10691069
}
10701070

10711071
void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
1072-
ASSERT(args[1]->IsObject());
1073-
ASSERT(args[2]->IsNumber());
1074-
ASSERT(args[4]->IsBoolean());
1072+
CHECK(args[1]->IsObject());
1073+
CHECK(args[2]->IsNumber());
1074+
CHECK(args[4]->IsBoolean());
10751075

10761076
enum encoding enc = ParseEncoding(args.GetIsolate(),
10771077
args[3],
@@ -1143,9 +1143,9 @@ void IndexOfBuffer(const FunctionCallbackInfo<Value>& args) {
11431143
}
11441144

11451145
void IndexOfNumber(const FunctionCallbackInfo<Value>& args) {
1146-
ASSERT(args[1]->IsNumber());
1147-
ASSERT(args[2]->IsNumber());
1148-
ASSERT(args[3]->IsBoolean());
1146+
CHECK(args[1]->IsNumber());
1147+
CHECK(args[2]->IsNumber());
1148+
CHECK(args[3]->IsBoolean());
11491149

11501150
THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]);
11511151
SPREAD_BUFFER_ARG(args[0], ts_obj);

src/node_crypto.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5193,7 +5193,7 @@ void ECDH::SetPublicKey(const FunctionCallbackInfo<Value>& args) {
51935193

51945194

51955195
bool ECDH::IsKeyValidForCurve(const BIGNUM* private_key) {
5196-
ASSERT_NE(group_, nullptr);
5196+
CHECK_NE(group_, nullptr);
51975197
CHECK_NE(private_key, nullptr);
51985198
// Private keys must be in the range [1, n-1].
51995199
// Ref: Section 3.2.1 - http://www.secg.org/sec1-v2.pdf

src/node_crypto.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class ECDH : public BaseObject {
718718
key_(key),
719719
group_(EC_KEY_get0_group(key_)) {
720720
MakeWeak<ECDH>(this);
721-
ASSERT_NE(group_, nullptr);
721+
CHECK_NE(group_, nullptr);
722722
}
723723

724724
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);

src/string_bytes.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ size_t StringBytes::WriteUCS2(char* buf,
321321

322322
uint16_t* aligned_dst =
323323
reinterpret_cast<uint16_t*>(buf + sizeof(*dst) - alignment);
324-
ASSERT_EQ(reinterpret_cast<uintptr_t>(aligned_dst) % sizeof(*dst), 0);
324+
CHECK_EQ(reinterpret_cast<uintptr_t>(aligned_dst) % sizeof(*dst), 0);
325325

326326
// Write all but the last char
327327
nchars = str->Write(aligned_dst, 0, max_chars - 1, flags);

src/string_search.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Vector {
2828
public:
2929
Vector(T* data, size_t length, bool isForward)
3030
: start_(data), length_(length), is_forward_(isForward) {
31-
ASSERT(length > 0 && data != nullptr);
31+
CHECK(length > 0 && data != nullptr);
3232
}
3333

3434
// Returns the start of the memory range.
@@ -44,7 +44,7 @@ class Vector {
4444

4545
// Access individual vector elements - checks bounds in debug mode.
4646
T& operator[](size_t index) const {
47-
ASSERT(index < length_);
47+
CHECK(index < length_);
4848
return start_[is_forward_ ? index : (length_ - index - 1)];
4949
}
5050

@@ -342,7 +342,7 @@ size_t StringSearch<Char>::LinearSearch(
342342
i = FindFirstCharacter(pattern, subject, i);
343343
if (i == subject.length())
344344
return subject.length();
345-
ASSERT_LE(i, n);
345+
CHECK_LE(i, n);
346346

347347
bool matches = true;
348348
for (size_t j = 1; j < pattern_length; j++) {
@@ -591,7 +591,7 @@ size_t StringSearch<Char>::InitialSearch(
591591
i = FindFirstCharacter(pattern, subject, i);
592592
if (i == subject.length())
593593
return subject.length();
594-
ASSERT_LE(i, n);
594+
CHECK_LE(i, n);
595595
size_t j = 1;
596596
do {
597597
if (pattern[j] != subject[i + j]) {
@@ -644,7 +644,7 @@ size_t SearchString(const Char* haystack,
644644
needle, needle_length, is_forward);
645645
Vector<const Char> v_haystack = Vector<const Char>(
646646
haystack, haystack_length, is_forward);
647-
ASSERT(haystack_length >= needle_length);
647+
CHECK(haystack_length >= needle_length);
648648
size_t diff = haystack_length - needle_length;
649649
size_t relative_start_index;
650650
if (is_forward) {

src/util.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void LowMemoryNotification();
7777
#endif
7878

7979
// The slightly odd function signature for Assert() is to ease
80-
// instruction cache pressure in calls from ASSERT and CHECK.
80+
// instruction cache pressure in calls from CHECK.
8181
NO_RETURN void Abort();
8282
NO_RETURN void Assert(const char* const (*args)[4]);
8383
void DumpBacktrace(FILE* fp);
@@ -124,19 +124,6 @@ template <typename T> using remove_reference = std::remove_reference<T>;
124124
} \
125125
} while (0)
126126

127-
#ifdef NDEBUG
128-
#define ASSERT(expr)
129-
#else
130-
#define ASSERT(expr) CHECK(expr)
131-
#endif
132-
133-
#define ASSERT_EQ(a, b) ASSERT((a) == (b))
134-
#define ASSERT_GE(a, b) ASSERT((a) >= (b))
135-
#define ASSERT_GT(a, b) ASSERT((a) > (b))
136-
#define ASSERT_LE(a, b) ASSERT((a) <= (b))
137-
#define ASSERT_LT(a, b) ASSERT((a) < (b))
138-
#define ASSERT_NE(a, b) ASSERT((a) != (b))
139-
140127
#define CHECK_EQ(a, b) CHECK((a) == (b))
141128
#define CHECK_GE(a, b) CHECK((a) >= (b))
142129
#define CHECK_GT(a, b) CHECK((a) > (b))

test/cctest/test_inspector_socket.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void check_data_cb(read_expects* expectation, ssize_t nread,
140140
EXPECT_TRUE(nread >= 0 && nread != UV_EOF);
141141
ssize_t i;
142142
char c, actual;
143-
ASSERT_GT(expectation->expected_len, 0);
143+
CHECK_GT(expectation->expected_len, 0);
144144
for (i = 0; i < nread && expectation->pos <= expectation->expected_len; i++) {
145145
c = expectation->expected[expectation->pos++];
146146
actual = buf->base[i];

test/cctest/test_inspector_socket_server.cc

+8-8
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ class TestInspectorServerDelegate : public SocketServerDelegate {
108108
}
109109

110110
void MessageReceived(int session_id, const std::string& message) override {
111-
ASSERT_EQ(session_id_, session_id);
111+
CHECK_EQ(session_id_, session_id);
112112
buffer_.insert(buffer_.end(), message.begin(), message.end());
113113
}
114114

115115
void EndSession(int session_id) override {
116-
ASSERT_EQ(session_id_, session_id);
116+
CHECK_EQ(session_id_, session_id);
117117
disconnected++;
118118
}
119119

@@ -178,9 +178,9 @@ class SocketWrapper {
178178
} else {
179179
err = uv_ip4_addr(host.c_str(), port, &addr.v4);
180180
}
181-
ASSERT_EQ(0, err);
181+
CHECK_EQ(0, err);
182182
err = uv_tcp_connect(&connect_, &socket_, &addr.generic, Connected_);
183-
ASSERT_EQ(0, err);
183+
CHECK_EQ(0, err);
184184
SPIN_WHILE(!connected_)
185185
uv_read_start(reinterpret_cast<uv_stream_t*>(&socket_), AllocCallback,
186186
ReadCallback);
@@ -195,11 +195,11 @@ class SocketWrapper {
195195
uv_tcp_init(loop_, &socket_);
196196
sockaddr_in addr;
197197
int err = uv_ip4_addr(host.c_str(), port, &addr);
198-
ASSERT_EQ(0, err);
198+
CHECK_EQ(0, err);
199199
err = uv_tcp_connect(&connect_, &socket_,
200200
reinterpret_cast<const sockaddr*>(&addr),
201201
ConnectionMustFail_);
202-
ASSERT_EQ(0, err);
202+
CHECK_EQ(0, err);
203203
SPIN_WHILE(!connection_failed_)
204204
uv_read_start(reinterpret_cast<uv_stream_t*>(&socket_), AllocCallback,
205205
ReadCallback);
@@ -244,7 +244,7 @@ class SocketWrapper {
244244
sending_ = true;
245245
int err = uv_write(&write_, reinterpret_cast<uv_stream_t*>(&socket_),
246246
buf, 1, WriteDone_);
247-
ASSERT_EQ(err, 0);
247+
CHECK_EQ(err, 0);
248248
SPIN_WHILE(sending_);
249249
}
250250

@@ -289,7 +289,7 @@ class SocketWrapper {
289289
delete[] buf->base;
290290
}
291291
static void WriteDone_(uv_write_t* req, int err) {
292-
ASSERT_EQ(0, err);
292+
CHECK_EQ(0, err);
293293
SocketWrapper* wrapper =
294294
node::ContainerOf(&SocketWrapper::write_, req);
295295
ASSERT_TRUE(wrapper->sending_);

0 commit comments

Comments
 (0)