From 862ea75e5a2d07a56208f4cd76d1b98451e4cb41 Mon Sep 17 00:00:00 2001 From: ZYSzys <17367077526@163.com> Date: Mon, 4 Feb 2019 15:38:51 +0800 Subject: [PATCH] src: use NULL check macros to check nullptr --- src/async_wrap.cc | 2 +- src/env-inl.h | 2 +- src/inspector/main_thread_interface.cc | 4 ++-- src/inspector_agent.cc | 2 +- src/inspector_socket_server.cc | 2 +- src/node.cc | 2 +- src/node_api.cc | 14 +++++++------- src/node_crypto.cc | 2 +- src/node_http2.cc | 2 +- src/node_http_parser_impl.h | 2 +- src/node_messaging.cc | 6 +++--- src/node_native_module.cc | 2 +- src/node_platform.cc | 4 ++-- src/node_union_bytes.h | 8 ++++---- src/node_worker.cc | 12 ++++++------ src/sharedarraybuffer_metadata.cc | 2 +- 16 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 8f20d4f83705e3..61455b2fccbaab 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -206,7 +206,7 @@ PromiseWrap* PromiseWrap::New(Environment* env, obj->SetInternalField(PromiseWrap::kIsChainedPromiseField, parent_wrap != nullptr ? v8::True(env->isolate()) : v8::False(env->isolate())); - CHECK_EQ(promise->GetAlignedPointerFromInternalField(0), nullptr); + CHECK_NULL(promise->GetAlignedPointerFromInternalField(0)); promise->SetInternalField(0, obj); return new PromiseWrap(env, obj, silent); } diff --git a/src/env-inl.h b/src/env-inl.h index 0a47b7cfcae345..a1807b5a5d8c86 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -659,7 +659,7 @@ inline worker::Worker* Environment::worker_context() const { } inline void Environment::set_worker_context(worker::Worker* context) { - CHECK_EQ(worker_context_, nullptr); // Should be set only once. + CHECK_NULL(worker_context_); // Should be set only once. worker_context_ = context; } diff --git a/src/inspector/main_thread_interface.cc b/src/inspector/main_thread_interface.cc index 15ffb49d74d1d4..1bcf65134fb48a 100644 --- a/src/inspector/main_thread_interface.cc +++ b/src/inspector/main_thread_interface.cc @@ -307,7 +307,7 @@ std::shared_ptr MainThreadInterface::GetHandle() { void MainThreadInterface::AddObject(int id, std::unique_ptr object) { - CHECK_NE(nullptr, object); + CHECK_NOT_NULL(object); managed_objects_[id] = std::move(object); } @@ -319,7 +319,7 @@ Deletable* MainThreadInterface::GetObject(int id) { Deletable* pointer = GetObjectIfExists(id); // This would mean the object is requested after it was disposed, which is // a coding error. - CHECK_NE(nullptr, pointer); + CHECK_NOT_NULL(pointer); return pointer; } diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index fb85a54408e19c..48b06bb7681943 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -682,7 +682,7 @@ bool Agent::Start(const std::string& path, bool is_main) { path_ = path; debug_options_ = options; - CHECK_NE(host_port, nullptr); + CHECK_NOT_NULL(host_port); host_port_ = host_port; client_ = std::make_shared(parent_env_, is_main); diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc index 1621b408b43274..5e77ff5b3f403a 100644 --- a/src/inspector_socket_server.cc +++ b/src/inspector_socket_server.cc @@ -352,7 +352,7 @@ std::string InspectorSocketServer::GetFrontendURL(bool is_compat, } bool InspectorSocketServer::Start() { - CHECK_NE(delegate_, nullptr); + CHECK_NOT_NULL(delegate_); CHECK_EQ(state_, ServerState::kNew); std::unique_ptr delegate_holder; // We will return it if startup is successful diff --git a/src/node.cc b/src/node.cc index e1350ef4f1e7a6..1d610f24ede3ab 100644 --- a/src/node.cc +++ b/src/node.cc @@ -342,7 +342,7 @@ void MarkBootstrapComplete(const FunctionCallbackInfo& args) { MaybeLocal StartExecution(Environment* env, const char* main_script_id) { EscapableHandleScope scope(env->isolate()); - CHECK_NE(main_script_id, nullptr); + CHECK_NOT_NULL(main_script_id); std::vector> parameters = { env->process_string(), diff --git a/src/node_api.cc b/src/node_api.cc index 7d843c08f5a69d..ff2e12f571a0f3 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -1043,8 +1043,8 @@ napi_create_threadsafe_function(napi_env env, napi_status napi_get_threadsafe_function_context(napi_threadsafe_function func, void** result) { - CHECK(func != nullptr); - CHECK(result != nullptr); + CHECK_NOT_NULL(func); + CHECK_NOT_NULL(result); *result = reinterpret_cast(func)->Context(); return napi_ok; @@ -1054,32 +1054,32 @@ napi_status napi_call_threadsafe_function(napi_threadsafe_function func, void* data, napi_threadsafe_function_call_mode is_blocking) { - CHECK(func != nullptr); + CHECK_NOT_NULL(func); return reinterpret_cast(func)->Push(data, is_blocking); } napi_status napi_acquire_threadsafe_function(napi_threadsafe_function func) { - CHECK(func != nullptr); + CHECK_NOT_NULL(func); return reinterpret_cast(func)->Acquire(); } napi_status napi_release_threadsafe_function(napi_threadsafe_function func, napi_threadsafe_function_release_mode mode) { - CHECK(func != nullptr); + CHECK_NOT_NULL(func); return reinterpret_cast(func)->Release(mode); } napi_status napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func) { - CHECK(func != nullptr); + CHECK_NOT_NULL(func); return reinterpret_cast(func)->Unref(); } napi_status napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func) { - CHECK(func != nullptr); + CHECK_NOT_NULL(func); return reinterpret_cast(func)->Ref(); } diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 228dd0d16da122..a291e1a2ad2039 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -5428,7 +5428,7 @@ void CryptoJob::AfterThreadPoolWork(int status) { void CryptoJob::Run(std::unique_ptr job, Local wrap) { CHECK(wrap->IsObject()); - CHECK_EQ(nullptr, job->async_wrap); + CHECK_NULL(job->async_wrap); job->async_wrap.reset(Unwrap(wrap.As())); CHECK_EQ(false, job->async_wrap->persistent().IsWeak()); job->ScheduleWork(); diff --git a/src/node_http2.cc b/src/node_http2.cc index 4e19432efbd3d6..1dd1f37c70275c 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -530,7 +530,7 @@ class Http2Session::MemoryAllocatorInfo { static void H2Free(void* ptr, void* user_data) { if (ptr == nullptr) return; // free(null); happens quite often. void* result = H2Realloc(ptr, 0, user_data); - CHECK_EQ(result, nullptr); + CHECK_NULL(result); } static void* H2Realloc(void* ptr, size_t size, void* user_data) { diff --git a/src/node_http_parser_impl.h b/src/node_http_parser_impl.h index 7a955cc1e9eca6..7d5ea347202c59 100644 --- a/src/node_http_parser_impl.h +++ b/src/node_http_parser_impl.h @@ -744,7 +744,7 @@ class Parser : public AsyncWrap, public StreamListener { Local reason; if (err == HPE_USER) { const char* colon = strchr(errno_reason, ':'); - CHECK_NE(colon, nullptr); + CHECK_NOT_NULL(colon); code = OneByteString(env()->isolate(), errno_reason, colon - errno_reason); reason = OneByteString(env()->isolate(), colon + 1); diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 6e8e3e8ad76e03..5d87c876ddf5f8 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -376,7 +376,7 @@ void Message::MemoryInfo(MemoryTracker* tracker) const { MessagePortData::MessagePortData(MessagePort* owner) : owner_(owner) { } MessagePortData::~MessagePortData() { - CHECK_EQ(owner_, nullptr); + CHECK_NULL(owner_); Disentangle(); } @@ -402,8 +402,8 @@ bool MessagePortData::IsSiblingClosed() const { } void MessagePortData::Entangle(MessagePortData* a, MessagePortData* b) { - CHECK_EQ(a->sibling_, nullptr); - CHECK_EQ(b->sibling_, nullptr); + CHECK_NULL(a->sibling_); + CHECK_NULL(b->sibling_); a->sibling_ = b; b->sibling_ = a; a->sibling_mutex_ = b->sibling_mutex_; diff --git a/src/node_native_module.cc b/src/node_native_module.cc index 662aad31d5d159..2d3769ebf5c949 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -270,7 +270,7 @@ MaybeLocal NativeModuleLoader::LookupAndCompile( // Generate new cache for next compilation std::unique_ptr new_cached_data( ScriptCompiler::CreateCodeCacheForFunction(fun)); - CHECK_NE(new_cached_data, nullptr); + CHECK_NOT_NULL(new_cached_data); // The old entry should've been erased by now so we can just emplace code_cache_.emplace(id, std::move(new_cached_data)); diff --git a/src/node_platform.cc b/src/node_platform.cc index 797d4d9cbb0dac..b930edb156bf80 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -241,14 +241,14 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr task) { } void PerIsolatePlatformData::PostTask(std::unique_ptr task) { - CHECK_NE(flush_tasks_, nullptr); + CHECK_NOT_NULL(flush_tasks_); foreground_tasks_.Push(std::move(task)); uv_async_send(flush_tasks_); } void PerIsolatePlatformData::PostDelayedTask( std::unique_ptr task, double delay_in_seconds) { - CHECK_NE(flush_tasks_, nullptr); + CHECK_NOT_NULL(flush_tasks_); std::unique_ptr delayed(new DelayedTask()); delayed->task = std::move(task); delayed->platform_data = shared_from_this(); diff --git a/src/node_union_bytes.h b/src/node_union_bytes.h index 66d8509beaf188..33fada73039e2c 100644 --- a/src/node_union_bytes.h +++ b/src/node_union_bytes.h @@ -64,22 +64,22 @@ class UnionBytes { bool is_one_byte() const { return is_one_byte_; } const uint16_t* two_bytes_data() const { CHECK(!is_one_byte_); - CHECK_NE(two_bytes_, nullptr); + CHECK_NOT_NULL(two_bytes_); return two_bytes_; } const uint8_t* one_bytes_data() const { CHECK(is_one_byte_); - CHECK_NE(one_bytes_, nullptr); + CHECK_NOT_NULL(one_bytes_); return one_bytes_; } v8::Local ToStringChecked(v8::Isolate* isolate) const { if (is_one_byte_) { - CHECK_NE(one_bytes_, nullptr); + CHECK_NOT_NULL(one_bytes_); NonOwningExternalOneByteResource* source = new NonOwningExternalOneByteResource(one_bytes_, length_); return v8::String::NewExternalOneByte(isolate, source).ToLocalChecked(); } else { - CHECK_NE(two_bytes_, nullptr); + CHECK_NOT_NULL(two_bytes_); NonOwningExternalTwoByteResource* source = new NonOwningExternalTwoByteResource(two_bytes_, length_); return v8::String::NewExternalTwoByte(isolate, source).ToLocalChecked(); diff --git a/src/node_worker.cc b/src/node_worker.cc index d457ab0c3e1ff2..3c54bfb6b80e7a 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -92,7 +92,7 @@ Worker::Worker(Environment* env, CHECK_EQ(uv_loop_init(&loop_), 0); isolate_ = NewIsolate(array_buffer_allocator_.get(), &loop_); - CHECK_NE(isolate_, nullptr); + CHECK_NOT_NULL(isolate_); { // Enter an environment capable of executing code in the child Isolate @@ -115,7 +115,7 @@ Worker::Worker(Environment* env, // TODO(addaleax): Use CreateEnvironment(), or generally another public API. env_.reset(new Environment(isolate_data_.get(), context)); - CHECK_NE(env_, nullptr); + CHECK_NOT_NULL(env_); env_->set_abort_on_uncaught_exception(false); env_->set_worker_context(this); thread_id_ = env_->thread_id(); @@ -153,7 +153,7 @@ void Worker::Run() { "__metadata", "thread_name", "name", TRACE_STR_COPY(name.c_str())); MultiIsolatePlatform* platform = isolate_data_->platform(); - CHECK_NE(platform, nullptr); + CHECK_NOT_NULL(platform); Debug(this, "Starting worker with id %llu", thread_id_); { @@ -339,7 +339,7 @@ void Worker::OnThreadStopped() { CHECK(stopped_); } - CHECK_EQ(child_port_, nullptr); + CHECK_NULL(child_port_); parent_port_ = nullptr; } @@ -369,7 +369,7 @@ Worker::~Worker() { CHECK(stopped_); CHECK(thread_joined_); - CHECK_EQ(child_port_, nullptr); + CHECK_NULL(child_port_); // This has most likely already happened within the worker thread -- this // is just in case Worker creation failed early. @@ -509,7 +509,7 @@ void Worker::Exit(int code) { Debug(this, "Worker %llu called Exit(%d)", thread_id_, code); if (!stopped_) { - CHECK_NE(env_, nullptr); + CHECK_NOT_NULL(env_); stopped_ = true; exit_code_ = code; if (child_port_ != nullptr) diff --git a/src/sharedarraybuffer_metadata.cc b/src/sharedarraybuffer_metadata.cc index 671ad6d6820440..4e6f5a349d1d57 100644 --- a/src/sharedarraybuffer_metadata.cc +++ b/src/sharedarraybuffer_metadata.cc @@ -75,7 +75,7 @@ SharedArrayBufferMetadata::ForSharedArrayBuffer( CHECK(source->IsExternal()); SABLifetimePartner* partner = Unwrap(lifetime_partner.As()); - CHECK_NE(partner, nullptr); + CHECK_NOT_NULL(partner); return partner->reference; }