Skip to content

Commit 2d82cdf

Browse files
committed
src: replace NULL with nullptr
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`.
1 parent b2b59fe commit 2d82cdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+655
-647
lines changed

src/async-wrap-inl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
100100
v8::Local<v8::Function> enter =
101101
domain->Get(env()->enter_string()).As<v8::Function>();
102102
if (enter->IsFunction()) {
103-
enter->Call(domain, 0, NULL);
103+
enter->Call(domain, 0, nullptr);
104104
if (try_catch.HasCaught())
105105
return Undefined(env()->isolate());
106106
}
@@ -116,7 +116,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
116116
v8::Local<v8::Function> exit =
117117
domain->Get(env()->exit_string()).As<v8::Function>();
118118
if (exit->IsFunction()) {
119-
exit->Call(domain, 0, NULL);
119+
exit->Call(domain, 0, nullptr);
120120
if (try_catch.HasCaught())
121121
return Undefined(env()->isolate());
122122
}
@@ -147,7 +147,7 @@ inline v8::Handle<v8::Value> AsyncWrap::MakeDomainCallback(
147147

148148
tick_info->set_in_tick(true);
149149

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

152152
tick_info->set_in_tick(false);
153153

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

215215
tick_info->set_in_tick(true);
216216

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

219219
tick_info->set_in_tick(false);
220220

src/cares_wrap.cc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ static void ares_poll_close_cb(uv_handle_t* watcher) {
121121
static ares_task_t* ares_task_create(Environment* env, ares_socket_t sock) {
122122
ares_task_t* task = static_cast<ares_task_t*>(malloc(sizeof(*task)));
123123

124-
if (task == NULL) {
124+
if (task == nullptr) {
125125
/* Out of memory. */
126-
return NULL;
126+
return nullptr;
127127
}
128128

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

138138
return task;
@@ -163,7 +163,7 @@ static void ares_sockstate_cb(void* data,
163163
}
164164

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

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

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

376376
struct hostent* host;
377377

378-
int status = ares_parse_a_reply(buf, len, &host, NULL, NULL);
378+
int status = ares_parse_a_reply(buf, len, &host, nullptr, nullptr);
379379
if (status != ARES_SUCCESS) {
380380
ParseError(status);
381381
return;
@@ -412,7 +412,7 @@ class QueryAaaaWrap: public QueryWrap {
412412

413413
struct hostent* host;
414414

415-
int status = ares_parse_aaaa_reply(buf, len, &host, NULL, NULL);
415+
int status = ares_parse_aaaa_reply(buf, len, &host, nullptr, nullptr);
416416
if (status != ARES_SUCCESS) {
417417
ParseError(status);
418418
return;
@@ -448,7 +448,7 @@ class QueryCnameWrap: public QueryWrap {
448448
Context::Scope context_scope(env()->context());
449449
struct hostent* host;
450450

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

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

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

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

698698
ares_naptr_reply* current = naptr_start;
699-
for (uint32_t i = 0; current != NULL; ++i, current = current->next) {
699+
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
700700
Local<Object> naptr_record = Object::New(env()->isolate());
701701
naptr_record->Set(flags_symbol,
702702
OneByteString(env()->isolate(), current->flags));
@@ -1044,7 +1044,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
10441044
&req_wrap->req_,
10451045
AfterGetAddrInfo,
10461046
*hostname,
1047-
NULL,
1047+
nullptr,
10481048
&hints);
10491049
req_wrap->Dispatched();
10501050
if (err)
@@ -1098,7 +1098,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
10981098

10991099
ares_addr_node* cur = servers;
11001100

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

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

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

11321132
ares_addr_node* servers = new ares_addr_node[len];
1133-
ares_addr_node* last = NULL;
1133+
ares_addr_node* last = nullptr;
11341134

11351135
int err;
11361136

@@ -1164,9 +1164,9 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
11641164
if (err)
11651165
break;
11661166

1167-
cur->next = NULL;
1167+
cur->next = nullptr;
11681168

1169-
if (last != NULL)
1169+
if (last != nullptr)
11701170
last->next = cur;
11711171

11721172
last = cur;
@@ -1230,7 +1230,7 @@ static void Initialize(Handle<Object> target,
12301230
env->RegisterHandleCleanup(
12311231
reinterpret_cast<uv_handle_t*>(env->cares_timer_handle()),
12321232
CaresTimerClose,
1233-
NULL);
1233+
nullptr);
12341234

12351235
env->SetMethod(target, "queryA", Query<QueryAWrap>);
12361236
env->SetMethod(target, "queryAaaa", Query<QueryAaaaWrap>);

src/env-inl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ inline Environment::IsolateData* Environment::IsolateData::Get(
7676
inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
7777
v8::Isolate* isolate, uv_loop_t* loop) {
7878
IsolateData* isolate_data = Get(isolate);
79-
if (isolate_data == NULL) {
79+
if (isolate_data == nullptr) {
8080
isolate_data = new IsolateData(isolate, loop);
8181
isolate->SetData(kIsolateSlot, isolate_data);
8282
}
@@ -86,7 +86,7 @@ inline Environment::IsolateData* Environment::IsolateData::GetOrCreate(
8686

8787
inline void Environment::IsolateData::Put() {
8888
if (--ref_count_ == 0) {
89-
isolate()->SetData(kIsolateSlot, NULL);
89+
isolate()->SetData(kIsolateSlot, nullptr);
9090
delete this;
9191
}
9292
}
@@ -246,7 +246,8 @@ inline Environment::Environment(v8::Local<v8::Context> context,
246246
inline Environment::~Environment() {
247247
v8::HandleScope handle_scope(isolate());
248248

249-
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, NULL);
249+
context()->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex,
250+
nullptr);
250251
#define V(PropertyName, TypeName) PropertyName ## _.Reset();
251252
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
252253
#undef V

src/env.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,13 @@ class Environment {
442442
inline void ThrowTypeError(const char* errmsg);
443443
inline void ThrowRangeError(const char* errmsg);
444444
inline void ThrowErrnoException(int errorno,
445-
const char* syscall = NULL,
446-
const char* message = NULL,
447-
const char* path = NULL);
445+
const char* syscall = nullptr,
446+
const char* message = nullptr,
447+
const char* path = nullptr);
448448
inline void ThrowUVException(int errorno,
449-
const char* syscall = NULL,
450-
const char* message = NULL,
451-
const char* path = NULL);
449+
const char* syscall = nullptr,
450+
const char* message = nullptr,
451+
const char* path = nullptr);
452452

453453
// Convenience methods for contextify
454454
inline static void ThrowError(v8::Isolate* isolate, const char* errmsg);

src/fs_event_wrap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
175175
Null(env->isolate())
176176
};
177177

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

@@ -186,7 +186,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
186186
void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
187187
FSEventWrap* wrap = Unwrap<FSEventWrap>(args.Holder());
188188

189-
if (wrap == NULL || wrap->initialized_ == false)
189+
if (wrap == nullptr || wrap->initialized_ == false)
190190
return;
191191
wrap->initialized_ = false;
192192

src/handle_wrap.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ using v8::Value;
4343
void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) {
4444
HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder());
4545

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

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

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

7272
CHECK_EQ(false, wrap->persistent().IsEmpty());
7373
uv_close(wrap->handle__, OnClose);
74-
wrap->handle__ = NULL;
74+
wrap->handle__ = nullptr;
7575

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

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

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

118118
if (wrap->flags_ & kCloseCallback) {
119-
wrap->MakeCallback(env->close_string(), 0, NULL);
119+
wrap->MakeCallback(env->close_string(), 0, nullptr);
120120
}
121121

122-
object->SetAlignedPointerInInternalField(0, NULL);
122+
object->SetAlignedPointerInInternalField(0, nullptr);
123123
wrap->persistent().Reset();
124124
delete wrap;
125125
}

0 commit comments

Comments
 (0)