Skip to content

Commit

Permalink
src: add CHECK_NULL/CHECK_NOT_NULL macros
Browse files Browse the repository at this point in the history
This change introduces CHECK_NULL and CHECK_NOT_NULL macros
similar to their definition in v8 and replaces instances of
CHECK/CHECK_EQ/CHECK_NE with these where it seems appropriate.

PR-URL: #20914
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
tniessen authored and MylesBorins committed May 29, 2018
1 parent 5e69e1a commit 902120a
Show file tree
Hide file tree
Showing 33 changed files with 124 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static void PromiseHook(PromiseHookType type, Local<Promise> promise,
}
}

CHECK_NE(wrap, nullptr);
CHECK_NOT_NULL(wrap);
if (type == PromiseHookType::kBefore) {
env->async_hooks()->push_async_ids(
wrap->get_async_id(), wrap->get_trigger_async_id());
Expand Down
4 changes: 2 additions & 2 deletions src/connection_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <typename WrapType, typename UVType>
void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
int status) {
WrapType* wrap_data = static_cast<WrapType*>(handle->data);
CHECK_NE(wrap_data, nullptr);
CHECK_NOT_NULL(wrap_data);
CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));

Environment* env = wrap_data->env();
Expand Down Expand Up @@ -78,7 +78,7 @@ template <typename WrapType, typename UVType>
void ConnectionWrap<WrapType, UVType>::AfterConnect(uv_connect_t* req,
int status) {
ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data);
CHECK_NE(req_wrap, nullptr);
CHECK_NOT_NULL(req_wrap);
WrapType* wrap = static_cast<WrapType*>(req->handle->data);
CHECK_EQ(req_wrap->env(), wrap->env());
Environment* env = wrap->env();
Expand Down
10 changes: 5 additions & 5 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,22 +473,22 @@ inline double Environment::get_default_trigger_async_id() {
}

inline double* Environment::heap_statistics_buffer() const {
CHECK_NE(heap_statistics_buffer_, nullptr);
CHECK_NOT_NULL(heap_statistics_buffer_);
return heap_statistics_buffer_;
}

inline void Environment::set_heap_statistics_buffer(double* pointer) {
CHECK_EQ(heap_statistics_buffer_, nullptr); // Should be set only once.
CHECK_NULL(heap_statistics_buffer_); // Should be set only once.
heap_statistics_buffer_ = pointer;
}

inline double* Environment::heap_space_statistics_buffer() const {
CHECK_NE(heap_space_statistics_buffer_, nullptr);
CHECK_NOT_NULL(heap_space_statistics_buffer_);
return heap_space_statistics_buffer_;
}

inline void Environment::set_heap_space_statistics_buffer(double* pointer) {
CHECK_EQ(heap_space_statistics_buffer_, nullptr); // Should be set only once.
CHECK_NULL(heap_space_statistics_buffer_); // Should be set only once.
heap_space_statistics_buffer_ = pointer;
}

Expand All @@ -497,7 +497,7 @@ inline char* Environment::http_parser_buffer() const {
}

inline void Environment::set_http_parser_buffer(char* buffer) {
CHECK_EQ(http_parser_buffer_, nullptr); // Should be set only once.
CHECK_NULL(http_parser_buffer_); // Should be set only once.
http_parser_buffer_ = buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ IsolateData::~IsolateData() {
v8::CpuProfiler* IsolateData::GetCpuProfiler() {
if (cpu_profiler_ != nullptr) return cpu_profiler_;
cpu_profiler_ = v8::CpuProfiler::New(isolate());
CHECK_NE(cpu_profiler_, nullptr);
CHECK_NOT_NULL(cpu_profiler_);
return cpu_profiler_;
}

Expand Down
8 changes: 4 additions & 4 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ FSEventWrap::~FSEventWrap() {

void FSEventWrap::GetInitialized(const FunctionCallbackInfo<Value>& args) {
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.This());
CHECK(wrap != nullptr);
CHECK_NOT_NULL(wrap);
args.GetReturnValue().Set(wrap->initialized_);
}

Expand Down Expand Up @@ -133,14 +133,14 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

FSEventWrap* wrap = Unwrap<FSEventWrap>(args.This());
CHECK_NE(wrap, nullptr);
CHECK_NOT_NULL(wrap);
CHECK(!wrap->initialized_);

const int argc = args.Length();
CHECK_GE(argc, 4);

BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr);
CHECK_NOT_NULL(*path);

unsigned int flags = 0;
if (args[2]->IsTrue())
Expand Down Expand Up @@ -233,7 +233,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,

void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());
CHECK_NE(wrap, nullptr);
CHECK_NOT_NULL(wrap);
CHECK(wrap->initialized_);

wrap->initialized_ = false;
Expand Down
6 changes: 3 additions & 3 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class InspectorTimerHandle {
InspectorTimerHandle(const InspectorTimerHandle&) = delete;

~InspectorTimerHandle() {
CHECK_NE(timer_, nullptr);
CHECK_NOT_NULL(timer_);
timer_->Stop();
timer_ = nullptr;
}
Expand Down Expand Up @@ -562,7 +562,7 @@ bool Agent::StartIoThread(bool wait_for_connect) {
if (io_ != nullptr)
return true;

CHECK_NE(client_, nullptr);
CHECK_NOT_NULL(client_);

io_ = std::unique_ptr<InspectorIo>(
new InspectorIo(parent_env_, platform_, path_, debug_options_,
Expand Down Expand Up @@ -613,7 +613,7 @@ std::unique_ptr<InspectorSession> Agent::Connect(
}

void Agent::WaitForDisconnect() {
CHECK_NE(client_, nullptr);
CHECK_NOT_NULL(client_);
// TODO(addaleax): Maybe this should use an at-exit hook for the Environment
// or something similar?
client_->contextDestroyed(parent_env_->context());
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_io.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ std::string ScriptPath(uv_loop_t* loop, const std::string& script_name) {
uv_fs_t req;
req.ptr = nullptr;
if (0 == uv_fs_realpath(loop, &req, script_name.c_str(), nullptr)) {
CHECK_NE(req.ptr, nullptr);
CHECK_NOT_NULL(req.ptr);
script_path = std::string(static_cast<char*>(req.ptr));
}
uv_fs_req_cleanup(&req);
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ class HttpHandler : public ProtocolHandler {
ProtocolHandler::ProtocolHandler(InspectorSocket* inspector,
TcpHolder::Pointer tcp)
: inspector_(inspector), tcp_(std::move(tcp)) {
CHECK_NE(nullptr, tcp_);
CHECK_NOT_NULL(tcp_);
tcp_->SetHandler(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int JSStream::DoWrite(WriteWrap* w,
uv_buf_t* bufs,
size_t count,
uv_stream_t* send_handle) {
CHECK_EQ(send_handle, nullptr);
CHECK_NULL(send_handle);

HandleScope scope(env()->isolate());
Context::Scope context_scope(env()->context());
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
ContextifyContext* sandbox =
ContextifyContext::ContextFromContextifiedSandbox(
env, args[2].As<Object>());
CHECK_NE(sandbox, nullptr);
CHECK_NOT_NULL(sandbox);
context = sandbox->context();
}

Expand Down
10 changes: 5 additions & 5 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1978,7 +1978,7 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
auto context = env->context();

CHECK_EQ(modpending, nullptr);
CHECK_NULL(modpending);

if (args.Length() < 2) {
env->ThrowError("process.dlopen needs at least 2 arguments.");
Expand Down Expand Up @@ -2245,8 +2245,8 @@ static Local<Object> InitModule(Environment* env,
Local<String> module) {
Local<Object> exports = Object::New(env->isolate());
// Internal bindings don't have a "module" object, only exports.
CHECK_EQ(mod->nm_register_func, nullptr);
CHECK_NE(mod->nm_context_register_func, nullptr);
CHECK_NULL(mod->nm_register_func);
CHECK_NOT_NULL(mod->nm_context_register_func);
Local<Value> unused = Undefined(env->isolate());
mod->nm_context_register_func(exports,
unused,
Expand Down Expand Up @@ -4093,7 +4093,7 @@ void AtExit(void (*cb)(void* arg), void* arg) {


void AtExit(Environment* env, void (*cb)(void* arg), void* arg) {
CHECK_NE(env, nullptr);
CHECK_NOT_NULL(env);
env->AtExit(cb, arg);
}

Expand Down Expand Up @@ -4354,7 +4354,7 @@ inline int Start(uv_loop_t* event_loop,

{
Mutex::ScopedLock scoped_lock(node_isolate_mutex);
CHECK_EQ(node_isolate, nullptr);
CHECK_NULL(node_isolate);
node_isolate = isolate;
}

Expand Down
6 changes: 3 additions & 3 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ CallbackInfo::CallbackInfo(Isolate* isolate,
ArrayBuffer::Contents obj_c = object->GetContents();
CHECK_EQ(data_, static_cast<char*>(obj_c.Data()));
if (object->ByteLength() != 0)
CHECK_NE(data_, nullptr);
CHECK_NOT_NULL(data_);

persistent_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
persistent_.SetWrapperClassId(BUFFER_ID);
Expand Down Expand Up @@ -329,7 +329,7 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {

void* new_data;
if (length > 0) {
CHECK_NE(data, nullptr);
CHECK_NOT_NULL(data);
new_data = node::UncheckedMalloc(length);
if (new_data == nullptr)
return Local<Object>();
Expand Down Expand Up @@ -408,7 +408,7 @@ MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) {

MaybeLocal<Object> New(Environment* env, char* data, size_t length) {
if (length > 0) {
CHECK_NE(data, nullptr);
CHECK_NOT_NULL(data);
CHECK(length <= kMaxLength);
}

Expand Down
4 changes: 2 additions & 2 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class ContextifyScript : public BaseObject {
ContextifyContext* sandbox =
ContextifyContext::ContextFromContextifiedSandbox(
env, args[6].As<Object>());
CHECK_NE(sandbox, nullptr);
CHECK_NOT_NULL(sandbox);
parsing_context = sandbox->context();
}
} else {
Expand Down Expand Up @@ -784,7 +784,7 @@ class ContextifyScript : public BaseObject {
// Get the context from the sandbox
ContextifyContext* contextify_context =
ContextifyContext::ContextFromContextifiedSandbox(env, sandbox);
CHECK_NE(contextify_context, nullptr);
CHECK_NOT_NULL(contextify_context);

if (contextify_context->context().IsEmpty())
return;
Expand Down
16 changes: 8 additions & 8 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ static X509_STORE* NewRootCertStore() {
BIO_free(bp);

// Parse errors from the built-in roots are fatal.
CHECK_NE(x509, nullptr);
CHECK_NOT_NULL(x509);

root_certs_vector.push_back(x509);
}
Expand Down Expand Up @@ -1578,7 +1578,7 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
int rv;

ext = X509_get_ext(cert, index);
CHECK_NE(ext, nullptr);
CHECK_NOT_NULL(ext);

if (!SafeX509ExtPrint(bio.get(), ext)) {
rv = X509V3_EXT_print(bio.get(), ext, 0, 0);
Expand Down Expand Up @@ -3383,7 +3383,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {


SignBase::Error SignBase::Init(const char* sign_type) {
CHECK_EQ(mdctx_, nullptr);
CHECK_NULL(mdctx_);
// Historically, "dss1" and "DSS1" were DSA aliases for SHA-1
// exposed through the public API.
if (strcmp(sign_type, "dss1") == 0 ||
Expand Down Expand Up @@ -4238,7 +4238,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<Value>& args,
BIGNUM* num =
BN_bin2bn(reinterpret_cast<unsigned char*>(Buffer::Data(args[0])),
Buffer::Length(args[0]), nullptr);
CHECK_NE(num, nullptr);
CHECK_NOT_NULL(num);
CHECK_EQ(1, set_field(dh->dh_.get(), num));
}

Expand Down Expand Up @@ -4496,7 +4496,7 @@ void ECDH::SetPrivateKey(const FunctionCallbackInfo<Value>& args) {
USE(&mark_pop_error_on_return);

const BIGNUM* priv_key = EC_KEY_get0_private_key(ecdh->key_.get());
CHECK_NE(priv_key, nullptr);
CHECK_NOT_NULL(priv_key);

ECPointPointer pub(EC_POINT_new(ecdh->group_));
CHECK(pub);
Expand Down Expand Up @@ -5007,7 +5007,7 @@ void VerifySpkac(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().Set(verify_result);

char* data = Buffer::Data(args[0]);
CHECK_NE(data, nullptr);
CHECK_NOT_NULL(data);

verify_result = VerifySpkac(data, length);

Expand Down Expand Up @@ -5052,7 +5052,7 @@ void ExportPublicKey(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().SetEmptyString();

char* data = Buffer::Data(args[0]);
CHECK_NE(data, nullptr);
CHECK_NOT_NULL(data);

size_t pkey_size;
char* pkey = ExportPublicKey(data, length, &pkey_size);
Expand Down Expand Up @@ -5084,7 +5084,7 @@ void ExportChallenge(const FunctionCallbackInfo<Value>& args) {
return args.GetReturnValue().SetEmptyString();

char* data = Buffer::Data(args[0]);
CHECK_NE(data, nullptr);
CHECK_NOT_NULL(data);

OpenSSLBuffer cert = ExportChallenge(data, len);
if (!cert)
Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class ECDH : public BaseObject {
key_(std::move(key)),
group_(EC_KEY_get0_group(key_.get())) {
MakeWeak();
CHECK_NE(group_, nullptr);
CHECK_NOT_NULL(group_);
}

static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto_bio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ NodeBIO::~NodeBIO() {


NodeBIO* NodeBIO::FromBIO(BIO* bio) {
CHECK_NE(BIO_get_data(bio), nullptr);
CHECK_NOT_NULL(BIO_get_data(bio));
return static_cast<NodeBIO*>(BIO_get_data(bio));
}

Expand Down
2 changes: 1 addition & 1 deletion src/node_crypto_clienthello-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void ClientHelloParser::Start(ClientHelloParser::OnHelloCb onhello_cb,
return;
Reset();

CHECK_NE(onhello_cb, nullptr);
CHECK_NOT_NULL(onhello_cb);

state_ = kWaiting;
onhello_cb_ = onhello_cb;
Expand Down
Loading

0 comments on commit 902120a

Please sign in to comment.