From 1b7372f2fb55f704b885e1097e2ec0381068c855 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 25 Jul 2017 12:20:40 +0200 Subject: src: replace ASSERT with CHECK MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/issues/14461 PR-URL: https://github.com/nodejs/node/pull/14474 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Nikolai Vavilov Reviewed-By: XadillaX --- src/env-inl.h | 4 ++-- src/inspector_socket.cc | 12 ++++++------ src/node_buffer.cc | 18 +++++++++--------- src/node_crypto.cc | 2 +- src/node_crypto.h | 2 +- src/string_bytes.cc | 2 +- src/string_search.h | 10 +++++----- src/util.h | 15 +-------------- 8 files changed, 26 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/env-inl.h b/src/env-inl.h index cf7304c98d..e160fe27d8 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -272,14 +272,14 @@ inline Environment* Environment::GetCurrent(v8::Local context) { inline Environment* Environment::GetCurrent( const v8::FunctionCallbackInfo& info) { - ASSERT(info.Data()->IsExternal()); + CHECK(info.Data()->IsExternal()); return static_cast(info.Data().As()->Value()); } template inline Environment* Environment::GetCurrent( const v8::PropertyCallbackInfo& info) { - ASSERT(info.Data()->IsExternal()); + CHECK(info.Data()->IsExternal()); // XXX(bnoordhuis) Work around a g++ 4.9.2 template type inferrer bug // when the expression is written as info.Data().As(). v8::Local data = info.Data(); diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index 85984b7fa1..2d5054bb80 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -157,7 +157,7 @@ static std::vector encode_frame_hybi17(const char* message, } frame.insert(frame.end(), extended_payload_length, extended_payload_length + 8); - ASSERT_EQ(0, remaining); + CHECK_EQ(0, remaining); } frame.insert(frame.end(), message, message + data_length); return frame; @@ -361,8 +361,8 @@ static void websockets_data_cb(uv_stream_t* stream, ssize_t nread, int inspector_read_start(InspectorSocket* inspector, uv_alloc_cb alloc_cb, uv_read_cb read_cb) { - ASSERT(inspector->ws_mode); - ASSERT(!inspector->shutting_down || read_cb == nullptr); + CHECK(inspector->ws_mode); + CHECK(!inspector->shutting_down || read_cb == nullptr); inspector->ws_state->close_sent = false; inspector->ws_state->alloc_cb = alloc_cb; inspector->ws_state->read_cb = read_cb; @@ -561,7 +561,7 @@ static void init_handshake(InspectorSocket* socket) { int inspector_accept(uv_stream_t* server, InspectorSocket* socket, handshake_cb callback) { - ASSERT_NE(callback, nullptr); + CHECK_NE(callback, nullptr); CHECK_EQ(socket->http_parsing_state, nullptr); socket->http_parsing_state = new http_parsing_state_s(); @@ -597,8 +597,8 @@ void inspector_close(InspectorSocket* inspector, inspector_cb callback) { // libuv throws assertions when closing stream that's already closed - we // need to do the same. - ASSERT(!uv_is_closing(reinterpret_cast(&inspector->tcp))); - ASSERT(!inspector->shutting_down); + CHECK(!uv_is_closing(reinterpret_cast(&inspector->tcp))); + CHECK(!inspector->shutting_down); inspector->shutting_down = true; inspector->ws_state->close_cb = callback; if (inspector->connection_eof) { diff --git a/src/node_buffer.cc b/src/node_buffer.cc index b3f5793f89..dc67844553 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -953,9 +953,9 @@ int64_t IndexOfOffset(size_t length, } void IndexOfString(const FunctionCallbackInfo& args) { - ASSERT(args[1]->IsString()); - ASSERT(args[2]->IsNumber()); - ASSERT(args[4]->IsBoolean()); + CHECK(args[1]->IsString()); + CHECK(args[2]->IsNumber()); + CHECK(args[4]->IsBoolean()); enum encoding enc = ParseEncoding(args.GetIsolate(), args[3], @@ -1069,9 +1069,9 @@ void IndexOfString(const FunctionCallbackInfo& args) { } void IndexOfBuffer(const FunctionCallbackInfo& args) { - ASSERT(args[1]->IsObject()); - ASSERT(args[2]->IsNumber()); - ASSERT(args[4]->IsBoolean()); + CHECK(args[1]->IsObject()); + CHECK(args[2]->IsNumber()); + CHECK(args[4]->IsBoolean()); enum encoding enc = ParseEncoding(args.GetIsolate(), args[3], @@ -1143,9 +1143,9 @@ void IndexOfBuffer(const FunctionCallbackInfo& args) { } void IndexOfNumber(const FunctionCallbackInfo& args) { - ASSERT(args[1]->IsNumber()); - ASSERT(args[2]->IsNumber()); - ASSERT(args[3]->IsBoolean()); + CHECK(args[1]->IsNumber()); + CHECK(args[2]->IsNumber()); + CHECK(args[3]->IsBoolean()); THROW_AND_RETURN_UNLESS_BUFFER(Environment::GetCurrent(args), args[0]); SPREAD_BUFFER_ARG(args[0], ts_obj); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 84f006b00f..d03d8ad2f2 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5193,7 +5193,7 @@ void ECDH::SetPublicKey(const FunctionCallbackInfo& args) { bool ECDH::IsKeyValidForCurve(const BIGNUM* private_key) { - ASSERT_NE(group_, nullptr); + CHECK_NE(group_, nullptr); CHECK_NE(private_key, nullptr); // Private keys must be in the range [1, n-1]. // Ref: Section 3.2.1 - http://www.secg.org/sec1-v2.pdf diff --git a/src/node_crypto.h b/src/node_crypto.h index 1d823bcb35..b406fb8aa6 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -718,7 +718,7 @@ class ECDH : public BaseObject { key_(key), group_(EC_KEY_get0_group(key_)) { MakeWeak(this); - ASSERT_NE(group_, nullptr); + CHECK_NE(group_, nullptr); } static void New(const v8::FunctionCallbackInfo& args); diff --git a/src/string_bytes.cc b/src/string_bytes.cc index cbf30afc7a..5aa3b8ca77 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -321,7 +321,7 @@ size_t StringBytes::WriteUCS2(char* buf, uint16_t* aligned_dst = reinterpret_cast(buf + sizeof(*dst) - alignment); - ASSERT_EQ(reinterpret_cast(aligned_dst) % sizeof(*dst), 0); + CHECK_EQ(reinterpret_cast(aligned_dst) % sizeof(*dst), 0); // Write all but the last char nchars = str->Write(aligned_dst, 0, max_chars - 1, flags); diff --git a/src/string_search.h b/src/string_search.h index 6040888110..dfdb8e9a16 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -28,7 +28,7 @@ class Vector { public: Vector(T* data, size_t length, bool isForward) : start_(data), length_(length), is_forward_(isForward) { - ASSERT(length > 0 && data != nullptr); + CHECK(length > 0 && data != nullptr); } // Returns the start of the memory range. @@ -44,7 +44,7 @@ class Vector { // Access individual vector elements - checks bounds in debug mode. T& operator[](size_t index) const { - ASSERT(index < length_); + CHECK(index < length_); return start_[is_forward_ ? index : (length_ - index - 1)]; } @@ -342,7 +342,7 @@ size_t StringSearch::LinearSearch( i = FindFirstCharacter(pattern, subject, i); if (i == subject.length()) return subject.length(); - ASSERT_LE(i, n); + CHECK_LE(i, n); bool matches = true; for (size_t j = 1; j < pattern_length; j++) { @@ -591,7 +591,7 @@ size_t StringSearch::InitialSearch( i = FindFirstCharacter(pattern, subject, i); if (i == subject.length()) return subject.length(); - ASSERT_LE(i, n); + CHECK_LE(i, n); size_t j = 1; do { if (pattern[j] != subject[i + j]) { @@ -644,7 +644,7 @@ size_t SearchString(const Char* haystack, needle, needle_length, is_forward); Vector v_haystack = Vector( haystack, haystack_length, is_forward); - ASSERT(haystack_length >= needle_length); + CHECK(haystack_length >= needle_length); size_t diff = haystack_length - needle_length; size_t relative_start_index; if (is_forward) { diff --git a/src/util.h b/src/util.h index 175db0c82c..1272de1893 100644 --- a/src/util.h +++ b/src/util.h @@ -77,7 +77,7 @@ void LowMemoryNotification(); #endif // The slightly odd function signature for Assert() is to ease -// instruction cache pressure in calls from ASSERT and CHECK. +// instruction cache pressure in calls from CHECK. NO_RETURN void Abort(); NO_RETURN void Assert(const char* const (*args)[4]); void DumpBacktrace(FILE* fp); @@ -124,19 +124,6 @@ template using remove_reference = std::remove_reference; } \ } while (0) -#ifdef NDEBUG -#define ASSERT(expr) -#else -#define ASSERT(expr) CHECK(expr) -#endif - -#define ASSERT_EQ(a, b) ASSERT((a) == (b)) -#define ASSERT_GE(a, b) ASSERT((a) >= (b)) -#define ASSERT_GT(a, b) ASSERT((a) > (b)) -#define ASSERT_LE(a, b) ASSERT((a) <= (b)) -#define ASSERT_LT(a, b) ASSERT((a) < (b)) -#define ASSERT_NE(a, b) ASSERT((a) != (b)) - #define CHECK_EQ(a, b) CHECK((a) == (b)) #define CHECK_GE(a, b) CHECK((a) >= (b)) #define CHECK_GT(a, b) CHECK((a) > (b)) -- cgit v1.2.3