Skip to content

Commit

Permalink
src: replace NULL with nullptr
Browse files Browse the repository at this point in the history
Now that we are building with C++11 features enabled, replace use
of NULL with nullptr.

The benefit of using nullptr is that it can never be confused for
an integral type because it does not support implicit conversions
to integral types except boolean - unlike NULL, which is defined
as a literal `0`.
  • Loading branch information
bnoordhuis committed Oct 23, 2014
1 parent b2b59fe commit 2d82cdf
Show file tree
Hide file tree
Showing 48 changed files with 655 additions and 647 deletions.
8 changes: 4 additions & 4 deletions src/async-wrap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
v8::Local<v8::Function> enter =
domain->Get(env()->enter_string()).As<v8::Function>();
if (enter->IsFunction()) {
enter->Call(domain, 0, NULL);
enter->Call(domain, 0, nullptr);
if (try_catch.HasCaught())
return Undefined(env()->isolate());
}
Expand All @@ -116,7 +116,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
v8::Local<v8::Function> exit =
domain->Get(env()->exit_string()).As<v8::Function>();
if (exit->IsFunction()) {
exit->Call(domain, 0, NULL);
exit->Call(domain, 0, nullptr);
if (try_catch.HasCaught())
return Undefined(env()->isolate());
}
Expand Down Expand Up @@ -147,7 +147,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(

tick_info->set_in_tick(true);

env()->tick_callback_function()->Call(process, 0, NULL);
env()->tick_callback_function()->Call(process, 0, nullptr);

tick_info->set_in_tick(false);

Expand Down Expand Up @@ -214,7 +214,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeCallback(

tick_info->set_in_tick(true);

env()->tick_callback_function()->Call(process, 0, NULL);
env()->tick_callback_function()->Call(process, 0, nullptr);

tick_info->set_in_tick(false);

Expand Down
40 changes: 20 additions & 20 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ static void ares_poll_close_cb(uv_handle_t* watcher) {
static ares_task_t* ares_task_create(Environment* env, ares_socket_t sock) {
ares_task_t* task = static_cast<ares_task_t*>(malloc(sizeof(*task)));

if (task == NULL) {
if (task == nullptr) {
/* Out of memory. */
return NULL;
return nullptr;
}

task->env = env;
Expand All @@ -132,7 +132,7 @@ static ares_task_t* ares_task_create(Environment* env, ares_socket_t sock) {
if (uv_poll_init_socket(env->event_loop(), &task->poll_watcher, sock) < 0) {
/* This should never happen. */
free(task);
return NULL;
return nullptr;
}

return task;
Expand Down Expand Up @@ -163,7 +163,7 @@ static void ares_sockstate_cb(void* data,
}

task = ares_task_create(env, sock);
if (task == NULL) {
if (task == nullptr) {
/* This should never happen unless we're out of memory or something */
/* is seriously wrong. The socket won't be polled, but the the query */
/* will eventually time out. */
Expand Down Expand Up @@ -202,7 +202,7 @@ static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) {
Local<Array> addresses = Array::New(env->isolate());

char ip[INET6_ADDRSTRLEN];
for (uint32_t i = 0; host->h_addr_list[i] != NULL; ++i) {
for (uint32_t i = 0; host->h_addr_list[i] != nullptr; ++i) {
uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip));
Local<String> address = OneByteString(env->isolate(), ip);
addresses->Set(i, address);
Expand All @@ -216,7 +216,7 @@ static Local<Array> HostentToNames(Environment* env, struct hostent* host) {
EscapableHandleScope scope(env->isolate());
Local<Array> names = Array::New(env->isolate());

for (uint32_t i = 0; host->h_aliases[i] != NULL; ++i) {
for (uint32_t i = 0; host->h_aliases[i] != nullptr; ++i) {
Local<String> address = OneByteString(env->isolate(), host->h_aliases[i]);
names->Set(i, address);
}
Expand Down Expand Up @@ -375,7 +375,7 @@ class QueryAWrap: public QueryWrap {

struct hostent* host;

int status = ares_parse_a_reply(buf, len, &host, NULL, NULL);
int status = ares_parse_a_reply(buf, len, &host, nullptr, nullptr);
if (status != ARES_SUCCESS) {
ParseError(status);
return;
Expand Down Expand Up @@ -412,7 +412,7 @@ class QueryAaaaWrap: public QueryWrap {

struct hostent* host;

int status = ares_parse_aaaa_reply(buf, len, &host, NULL, NULL);
int status = ares_parse_aaaa_reply(buf, len, &host, nullptr, nullptr);
if (status != ARES_SUCCESS) {
ParseError(status);
return;
Expand Down Expand Up @@ -448,7 +448,7 @@ class QueryCnameWrap: public QueryWrap {
Context::Scope context_scope(env()->context());
struct hostent* host;

int status = ares_parse_a_reply(buf, len, &host, NULL, NULL);
int status = ares_parse_a_reply(buf, len, &host, nullptr, nullptr);
if (status != ARES_SUCCESS) {
ParseError(status);
return;
Expand Down Expand Up @@ -498,7 +498,7 @@ class QueryMxWrap: public QueryWrap {
Local<String> priority_symbol = env()->priority_string();

ares_mx_reply* current = mx_start;
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
Local<Object> mx_record = Object::New(env()->isolate());
mx_record->Set(exchange_symbol,
OneByteString(env()->isolate(), current->host));
Expand Down Expand Up @@ -583,7 +583,7 @@ class QueryTxtWrap: public QueryWrap {

ares_txt_reply* current = txt_out;
uint32_t i = 0;
for (uint32_t j = 0; current != NULL; current = current->next) {
for (uint32_t j = 0; current != nullptr; current = current->next) {
Local<String> txt = OneByteString(env()->isolate(), current->txt);
// New record found - write out the current chunk
if (current->record_start) {
Expand Down Expand Up @@ -639,7 +639,7 @@ class QuerySrvWrap: public QueryWrap {
Local<String> weight_symbol = env()->weight_string();

ares_srv_reply* current = srv_start;
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
Local<Object> srv_record = Object::New(env()->isolate());
srv_record->Set(name_symbol,
OneByteString(env()->isolate(), current->host));
Expand Down Expand Up @@ -696,7 +696,7 @@ class QueryNaptrWrap: public QueryWrap {
Local<String> preference_symbol = env()->preference_string();

ares_naptr_reply* current = naptr_start;
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
Local<Object> naptr_record = Object::New(env()->isolate());
naptr_record->Set(flags_symbol,
OneByteString(env()->isolate(), current->flags));
Expand Down Expand Up @@ -1044,7 +1044,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
&req_wrap->req_,
AfterGetAddrInfo,
*hostname,
NULL,
nullptr,
&hints);
req_wrap->Dispatched();
if (err)
Expand Down Expand Up @@ -1098,7 +1098,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {

ares_addr_node* cur = servers;

for (uint32_t i = 0; cur != NULL; ++i, cur = cur->next) {
for (uint32_t i = 0; cur != nullptr; ++i, cur = cur->next) {
char ip[INET6_ADDRSTRLEN];

const void* caddr = static_cast<const void*>(&cur->addr);
Expand All @@ -1125,12 +1125,12 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
uint32_t len = arr->Length();

if (len == 0) {
int rv = ares_set_servers(env->cares_channel(), NULL);
int rv = ares_set_servers(env->cares_channel(), nullptr);
return args.GetReturnValue().Set(rv);
}

ares_addr_node* servers = new ares_addr_node[len];
ares_addr_node* last = NULL;
ares_addr_node* last = nullptr;

int err;

Expand Down Expand Up @@ -1164,9 +1164,9 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
if (err)
break;

cur->next = NULL;
cur->next = nullptr;

if (last != NULL)
if (last != nullptr)
last->next = cur;

last = cur;
Expand Down Expand Up @@ -1230,7 +1230,7 @@ static void Initialize(Handle<Object> target,
env->RegisterHandleCleanup(
reinterpret_cast<uv_handle_t*>(env->cares_timer_handle()),
CaresTimerClose,
NULL);
nullptr);

env->SetMethod(target, "queryA", Query<QueryAWrap>);
env->SetMethod(target, "queryAaaa", Query<QueryAaaaWrap>);
Expand Down
7 changes: 4 additions & 3 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ inline Environment::IsolateData* Environment::IsolateData::Get(
inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
v8::Isolate* isolate, uv_loop_t* loop) {
IsolateData* isolate_data = Get(isolate);
if (isolate_data == NULL) {
if (isolate_data == nullptr) {
isolate_data = new IsolateData(isolate, loop);
isolate->SetData(kIsolateSlot, isolate_data);
}
Expand All @@ -86,7 +86,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(

inline void Environment::IsolateData::Put() {
if (--ref_count_ == 0) {
isolate()->SetData(kIsolateSlot, NULL);
isolate()->SetData(kIsolateSlot, nullptr);
delete this;
}
}
Expand Down Expand Up @@ -246,7 +246,8 @@ inline Environment::Environment(v8::Local<v8::Context> context,
inline Environment::~Environment() {
v8::HandleScope handle_scope(isolate());

context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL);
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
nullptr);
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
#undef V
Expand Down
12 changes: 6 additions & 6 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ class Environment {
inline void ThrowTypeError(const char* errmsg);
inline void ThrowRangeError(const char* errmsg);
inline void ThrowErrnoException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL);
const char* syscall = nullptr,
const char* message = nullptr,
const char* path = nullptr);
inline void ThrowUVException(int errorno,
const char* syscall = NULL,
const char* message = NULL,
const char* path = NULL);
const char* syscall = nullptr,
const char* message = nullptr,
const char* path = nullptr);

// Convenience methods for contextify
inline static void ThrowError(v8::Isolate* isolate, const char* errmsg);
Expand Down
4 changes: 2 additions & 2 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
Null(env->isolate())
};

if (filename != NULL) {
if (filename != nullptr) {
argv[2] = OneByteString(env->isolate(), filename);
}

Expand All @@ -186,7 +186,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());

if (wrap == NULL || wrap->initialized_ == false)
if (wrap == nullptr || wrap->initialized_ == false)
return;
wrap->initialized_ = false;

Expand Down
14 changes: 7 additions & 7 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using v8::Value;
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());

if (wrap != NULL && wrap->handle__ != NULL) {
if (wrap != nullptr && wrap->handle__ != nullptr) {
uv_ref(wrap->handle__);
wrap->flags_ &= ~kUnref;
}
Expand All @@ -53,7 +53,7 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) {
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());

if (wrap != NULL && wrap->handle__ != NULL) {
if (wrap != nullptr && wrap->handle__ != nullptr) {
uv_unref(wrap->handle__);
wrap->flags_ |= kUnref;
}
Expand All @@ -66,12 +66,12 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) {
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());

// guard against uninitialized handle or double close
if (wrap == NULL || wrap->handle__ == NULL)
if (wrap == nullptr || wrap->handle__ == nullptr)
return;

CHECK_EQ(false, wrap->persistent().IsEmpty());
uv_close(wrap->handle__, OnClose);
wrap->handle__ = NULL;
wrap->handle__ = nullptr;

if (args[0]->IsFunction()) {
wrap->object()->Set(env->close_string(), args[0]);
Expand Down Expand Up @@ -109,17 +109,17 @@ void HandleWrap::OnClose(uv_handle_t* handle) {
CHECK_EQ(wrap->persistent().IsEmpty(), false);

// But the handle pointer should be gone.
CHECK_EQ(wrap->handle__, NULL);
CHECK_EQ(wrap->handle__, nullptr);

HandleScope handle_scope(env->isolate());
Context::Scope context_scope(env->context());
Local<Object> object = wrap->object();

if (wrap->flags_ & kCloseCallback) {
wrap->MakeCallback(env->close_string(), 0, NULL);
wrap->MakeCallback(env->close_string(), 0, nullptr);
}

object->SetAlignedPointerInInternalField(0, NULL);
object->SetAlignedPointerInInternalField(0, nullptr);
wrap->persistent().Reset();
delete wrap;
}
Expand Down
Loading

0 comments on commit 2d82cdf

Please sign in to comment.