Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: introduce DCHECK macro and use DCHECK* macros where possible #25207

Merged
merged 2 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,15 @@ class AliasedBuffer {
* Set position index to given value.
*/
inline void SetValue(const size_t index, NativeT value) {
#if defined(DEBUG) && DEBUG
CHECK_LT(index, count_);
#endif
DCHECK_LT(index, count_);
buffer_[index] = value;
}

/**
* Get value at position index
*/
inline const NativeT GetValue(const size_t index) const {
#if defined(DEBUG) && DEBUG
CHECK_LT(index, count_);
#endif
DCHECK_LT(index, count_);
return buffer_[index];
}

Expand All @@ -233,11 +229,9 @@ class AliasedBuffer {
// Should only be used on an owning array, not one created as a sub array of
// an owning `AliasedBuffer`.
void reserve(size_t new_capacity) {
#if defined(DEBUG) && DEBUG
CHECK_GE(new_capacity, count_);
CHECK_EQ(byte_offset_, 0);
CHECK(free_buffer_);
#endif
DCHECK_GE(new_capacity, count_);
DCHECK_EQ(byte_offset_, 0);
DCHECK(free_buffer_);
const v8::HandleScope handle_scope(isolate_);

const size_t old_size_in_bytes = sizeof(NativeT) * count_;
Expand Down
6 changes: 2 additions & 4 deletions src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ void BaseObject::ClearWeak() {
v8::Local<v8::FunctionTemplate>
BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) {
auto constructor = [](const v8::FunctionCallbackInfo<v8::Value>& args) {
#ifdef DEBUG
CHECK(args.IsConstructCall());
CHECK_GT(args.This()->InternalFieldCount(), 0);
#endif
DCHECK(args.IsConstructCall());
DCHECK_GT(args.This()->InternalFieldCount(), 0);
args.This()->SetAlignedPointerInInternalField(0, nullptr);
};

Expand Down
4 changes: 1 addition & 3 deletions src/debug_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ template <typename... Args>
inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
const char* format,
Args&&... args) {
#ifdef DEBUG
CHECK_NOT_NULL(async_wrap);
#endif
DCHECK_NOT_NULL(async_wrap);
DebugCategory cat =
static_cast<DebugCategory>(async_wrap->provider_type());
if (!UNLIKELY(async_wrap->env()->debug_enabled(cat)))
Expand Down
4 changes: 0 additions & 4 deletions src/inspector/node_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,4 @@ extern size_t kNotFound;
} // namespace inspector
} // namespace node

#ifndef DCHECK
#define DCHECK CHECK
#define DCHECK_LT CHECK_LT
#endif // DCHECK
#endif // SRC_INSPECTOR_NODE_STRING_H_
14 changes: 4 additions & 10 deletions src/string_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ MaybeLocal<String> MakeString(Isolate* isolate,
isolate->ThrowException(error);
}

#ifdef DEBUG
CHECK(ret.IsEmpty() || ret.ToLocalChecked()->IsString());
#endif
DCHECK(ret.IsEmpty() || ret.ToLocalChecked()->IsString());
return ret.FromMaybe(Local<Value>()).As<String>();
}

Expand Down Expand Up @@ -123,11 +121,9 @@ MaybeLocal<String> StringDecoder::DecodeData(Isolate* isolate,
body = !prepend.IsEmpty() ? prepend : String::Empty(isolate);
prepend = Local<String>();
} else {
#ifdef DEBUG
// If not, that means is no character left to finish at this point.
CHECK_EQ(MissingBytes(), 0);
CHECK_EQ(BufferedBytes(), 0);
#endif
DCHECK_EQ(MissingBytes(), 0);
DCHECK_EQ(BufferedBytes(), 0);

// See whether there is a character that we may have to cut off and
// finish when receiving the next chunk.
Expand All @@ -136,9 +132,7 @@ MaybeLocal<String> StringDecoder::DecodeData(Isolate* isolate,
// This means we'll need to figure out where the character to which
// the byte belongs begins.
for (size_t i = nread - 1; ; --i) {
#ifdef DEBUG
CHECK_LT(i, nread);
#endif
DCHECK_LT(i, nread);
state_[kBufferedBytes]++;
if ((data[i] & 0xC0) == 0x80) {
// This byte does not start a character (a "trailing" byte).
Expand Down
4 changes: 1 addition & 3 deletions src/string_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class Vector {

// Access individual vector elements - checks bounds in debug mode.
T& operator[](size_t index) const {
#ifdef DEBUG
CHECK(index < length_);
#endif
DCHECK_LT(index, length_);
return start_[is_forward_ ? index : (length_ - index - 1)];
}

Expand Down
2 changes: 2 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void DumpBacktrace(FILE* fp);
#define CHECK_IMPLIES(a, b) CHECK(!(a) || (b))

#ifdef DEBUG
#define DCHECK(expr) CHECK(expr)
#define DCHECK_EQ(a, b) CHECK((a) == (b))
#define DCHECK_GE(a, b) CHECK((a) >= (b))
#define DCHECK_GT(a, b) CHECK((a) > (b))
Expand All @@ -140,6 +141,7 @@ void DumpBacktrace(FILE* fp);
#define DCHECK_NOT_NULL(val) CHECK((val) != nullptr)
#define DCHECK_IMPLIES(a, b) CHECK(!(a) || (b))
#else
#define DCHECK(expr)
#define DCHECK_EQ(a, b)
#define DCHECK_GE(a, b)
#define DCHECK_GT(a, b)
Expand Down