Browse Source

src: replace ARRAY_SIZE with typesafe arraysize

To prevent `ARRAY_SIZE(&arg)` (i.e., taking the array size of a pointer)
from happening again.

PR-URL: https://github.com/nodejs/node/pull/5969
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
process-exit-stdio-flushing
Ben Noordhuis 9 years ago
parent
commit
a7581d0859
  1. 2
      src/async-wrap-inl.h
  2. 2
      src/async-wrap.cc
  3. 8
      src/cares_wrap.cc
  4. 8
      src/debug-agent.cc
  5. 2
      src/fs_event_wrap.cc
  6. 4
      src/js_stream.cc
  7. 26
      src/node.cc
  8. 2
      src/node_contextify.cc
  9. 2
      src/node_counters.cc
  10. 22
      src/node_crypto.cc
  11. 2
      src/node_dtrace.cc
  12. 8
      src/node_file.cc
  13. 16
      src/node_http_parser.cc
  14. 7
      src/node_internals.h
  15. 2
      src/node_lttng.cc
  16. 2
      src/node_stat_watcher.cc
  17. 2
      src/node_win32_etw_provider-inl.h
  18. 2
      src/node_win32_etw_provider.cc
  19. 4
      src/node_zlib.cc
  20. 6
      src/pipe_wrap.cc
  21. 2
      src/process_wrap.cc
  22. 10
      src/stream_base.cc
  23. 4
      src/tcp_wrap.cc
  24. 6
      src/tls_wrap.cc
  25. 6
      src/udp_wrap.cc

2
src/async-wrap-inl.h

@ -54,7 +54,7 @@ inline AsyncWrap::AsyncWrap(Environment* env,
v8::TryCatch try_catch(env->isolate());
v8::MaybeLocal<v8::Value> ret =
init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv);
init_fn->Call(env->context(), object, arraysize(argv), argv);
if (ret.IsEmpty()) {
ClearFatalExceptionHandlers(env);

2
src/async-wrap.cc

@ -242,7 +242,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
Local<Value> vals[] = { uid, did_throw };
TryCatch try_catch(env()->isolate());
MaybeLocal<Value> ar =
post_fn->Call(env()->context(), context, ARRAY_SIZE(vals), vals);
post_fn->Call(env()->context(), context, arraysize(vals), vals);
if (ar.IsEmpty()) {
ClearFatalExceptionHandlers(env());
FatalException(env()->isolate(), try_catch);

8
src/cares_wrap.cc

@ -310,7 +310,7 @@ class QueryWrap : public AsyncWrap {
Integer::New(env()->isolate(), 0),
answer
};
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
MakeCallback(env()->oncomplete_string(), arraysize(argv), argv);
}
void CallOnComplete(Local<Value> answer, Local<Value> family) {
@ -321,7 +321,7 @@ class QueryWrap : public AsyncWrap {
answer,
family
};
MakeCallback(env()->oncomplete_string(), ARRAY_SIZE(argv), argv);
MakeCallback(env()->oncomplete_string(), arraysize(argv), argv);
}
void ParseError(int status) {
@ -1037,7 +1037,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
uv_freeaddrinfo(res);
// Make the callback into JavaScript
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
delete req_wrap;
}
@ -1068,7 +1068,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
}
// Make the callback into JavaScript
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
delete req_wrap;
}

8
src/debug-agent.cc

@ -22,7 +22,7 @@
#include "debug-agent.h"
#include "node.h"
#include "node_internals.h" // ARRAY_SIZE
#include "node_internals.h" // arraysize
#include "env.h"
#include "env-inl.h"
#include "v8.h"
@ -176,9 +176,9 @@ void Agent::WorkerRun() {
isolate,
&child_loop_,
context,
ARRAY_SIZE(argv),
arraysize(argv),
argv,
ARRAY_SIZE(argv),
arraysize(argv),
argv);
child_env_ = env;
@ -303,7 +303,7 @@ void Agent::ChildSignalCb(uv_async_t* signal) {
MakeCallback(isolate,
api,
"onmessage",
ARRAY_SIZE(argv),
arraysize(argv),
argv);
delete msg;
}

2
src/fs_event_wrap.cc

@ -176,7 +176,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
}
}
wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv);
wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv);
}

4
src/js_stream.cc

@ -75,7 +75,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) {
req_wrap->Dispatched();
Local<Value> res =
MakeCallback(env()->onshutdown_string(), ARRAY_SIZE(argv), argv);
MakeCallback(env()->onshutdown_string(), arraysize(argv), argv);
return res->Int32Value();
}
@ -103,7 +103,7 @@ int JSStream::DoWrite(WriteWrap* w,
w->Dispatched();
Local<Value> res =
MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv);
MakeCallback(env()->onwrite_string(), arraysize(argv), argv);
return res->Int32Value();
}

26
src/node.cc

@ -1129,7 +1129,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
Local<Value> args[] = { event, promise, value };
Local<Object> process = env->process_object();
callback->Call(process, ARRAY_SIZE(args), args);
callback->Call(process, arraysize(args), args);
}
void SetupPromises(const FunctionCallbackInfo<Value>& args) {
@ -1213,7 +1213,7 @@ Local<Value> MakeCallback(Environment* env,
{ Undefined(env->isolate()).As<Value>(), did_throw };
TryCatch try_catch(env->isolate());
MaybeLocal<Value> ar =
post_fn->Call(env->context(), object, ARRAY_SIZE(vals), vals);
post_fn->Call(env->context(), object, arraysize(vals), vals);
if (ar.IsEmpty()) {
ClearFatalExceptionHandlers(env);
FatalException(env->isolate(), try_catch);
@ -1691,7 +1691,7 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
if (w->persistent().IsEmpty())
continue;
argv[idx] = w->object();
if (++idx >= ARRAY_SIZE(argv)) {
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
@ -1726,7 +1726,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
if (owner->IsUndefined())
owner = object;
argv[idx] = owner;
if (++idx >= ARRAY_SIZE(argv)) {
if (++idx >= arraysize(argv)) {
fn->Call(ctx, ary, idx, argv).ToLocalChecked();
idx = 0;
}
@ -2564,12 +2564,12 @@ static void EnvGetter(Local<String> property,
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
DWORD result = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(*key),
buffer,
ARRAY_SIZE(buffer));
arraysize(buffer));
// If result >= sizeof buffer the buffer was too small. That should never
// happen. If result == 0 and result != ERROR_SUCCESS the variable was not
// not found.
if ((result > 0 || GetLastError() == ERROR_SUCCESS) &&
result < ARRAY_SIZE(buffer)) {
result < arraysize(buffer)) {
const uint16_t* two_byte_buffer = reinterpret_cast<const uint16_t*>(buffer);
Local<String> rc = String::NewFromTwoByte(isolate, two_byte_buffer);
return info.GetReturnValue().Set(rc);
@ -2670,7 +2670,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
var,
String::kNormalString,
length);
if (++idx >= ARRAY_SIZE(argv)) {
if (++idx >= arraysize(argv)) {
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
idx = 0;
}
@ -2702,7 +2702,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
two_byte_buffer,
String::kNormalString,
two_byte_buffer_len);
if (++idx >= ARRAY_SIZE(argv)) {
if (++idx >= arraysize(argv)) {
fn->Call(ctx, envarr, idx, argv).ToLocalChecked();
idx = 0;
}
@ -3641,7 +3641,7 @@ static void EnableDebug(Environment* env) {
FIXED_ONE_BYTE_STRING(env->isolate(), "internalMessage"),
message
};
MakeCallback(env, env->process_object(), "emit", ARRAY_SIZE(argv), argv);
MakeCallback(env, env->process_object(), "emit", arraysize(argv), argv);
// Enabled debugger, possibly making it wait on a semaphore
env->debugger_agent()->Enable();
@ -3762,7 +3762,7 @@ static int RegisterDebugSignalHandler() {
if (GetDebugSignalHandlerMappingName(pid,
mapping_name,
ARRAY_SIZE(mapping_name)) < 0) {
arraysize(mapping_name)) < 0) {
return -1;
}
@ -3825,7 +3825,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args) {
if (GetDebugSignalHandlerMappingName(pid,
mapping_name,
ARRAY_SIZE(mapping_name)) < 0) {
arraysize(mapping_name)) < 0) {
env->ThrowErrnoException(errno, "sprintf");
goto out;
}
@ -4102,7 +4102,7 @@ void EmitBeforeExit(Environment* env) {
FIXED_ONE_BYTE_STRING(env->isolate(), "beforeExit"),
process_object->Get(exit_code)->ToInteger(env->isolate())
};
MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
MakeCallback(env, process_object, "emit", arraysize(args), args);
}
@ -4121,7 +4121,7 @@ int EmitExit(Environment* env) {
Integer::New(env->isolate(), code)
};
MakeCallback(env, process_object, "emit", ARRAY_SIZE(args), args);
MakeCallback(env, process_object, "emit", arraysize(args), args);
// Reload exit code, it may be changed by `emit('exit')`
return process_object->Get(exitCode)->Int32Value();

2
src/node_contextify.cc

@ -162,7 +162,7 @@ class ContextifyContext {
CHECK(clone_property_method->IsFunction());
}
Local<Value> args[] = { global, key, sandbox_obj };
clone_property_method->Call(global, ARRAY_SIZE(args), args);
clone_property_method->Call(global, arraysize(args), args);
}
}
}

2
src/node_counters.cc

@ -96,7 +96,7 @@ void InitPerfCounters(Environment* env, Local<Object> target) {
#undef NODE_PROBE
};
for (int i = 0; i < ARRAY_SIZE(tab); i++) {
for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
target->Set(key, val);

22
src/node_crypto.cc

@ -764,7 +764,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
if (!root_cert_store) {
root_cert_store = X509_STORE_new();
for (size_t i = 0; i < ARRAY_SIZE(root_certs); i++) {
for (size_t i = 0; i < arraysize(root_certs); i++) {
BIO* bp = NodeBIO::NewFixed(root_certs[i], strlen(root_certs[i]));
if (bp == nullptr) {
return;
@ -1110,7 +1110,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl,
Local<Value> ret = node::MakeCallback(env,
sc->object(),
env->ticketkeycallback_string(),
ARRAY_SIZE(argv),
arraysize(argv),
argv);
Local<Array> arr = ret.As<Array>();
@ -1307,7 +1307,7 @@ int SSLWrap<Base>::NewSessionCallback(SSL* s, SSL_SESSION* sess) {
sess->session_id_length).ToLocalChecked();
Local<Value> argv[] = { session, buff };
w->new_session_wait_ = true;
w->MakeCallback(env->onnewsession_string(), ARRAY_SIZE(argv), argv);
w->MakeCallback(env->onnewsession_string(), arraysize(argv), argv);
return 0;
}
@ -1341,7 +1341,7 @@ void SSLWrap<Base>::OnClientHello(void* arg,
Boolean::New(env->isolate(), hello.ocsp_request()));
Local<Value> argv[] = { hello_obj };
w->MakeCallback(env->onclienthello_string(), ARRAY_SIZE(argv), argv);
w->MakeCallback(env->onclienthello_string(), arraysize(argv), argv);
}
@ -1416,8 +1416,8 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
int nids[] = { NID_subject_alt_name, NID_info_access };
Local<String> keys[] = { env->subjectaltname_string(),
env->infoaccess_string() };
CHECK_EQ(ARRAY_SIZE(nids), ARRAY_SIZE(keys));
for (unsigned int i = 0; i < ARRAY_SIZE(nids); i++) {
CHECK_EQ(arraysize(nids), arraysize(keys));
for (size_t i = 0; i < arraysize(nids); i++) {
int index = X509_get_ext_by_NID(cert, nids[i], -1);
if (index < 0)
continue;
@ -2326,7 +2326,7 @@ int SSLWrap<Base>::SSLCertCallback(SSL* s, void* arg) {
info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp));
Local<Value> argv[] = { info };
w->MakeCallback(env->oncertcb_string(), ARRAY_SIZE(argv), argv);
w->MakeCallback(env->oncertcb_string(), arraysize(argv), argv);
if (!w->cert_cb_running_)
return 1;
@ -2689,7 +2689,7 @@ inline CheckResult CheckWhitelistedServerCert(X509_STORE_CTX* ctx) {
CHECK(ret);
void* result = bsearch(hash, WhitelistedCNNICHashes,
ARRAY_SIZE(WhitelistedCNNICHashes),
arraysize(WhitelistedCNNICHashes),
CNNIC_WHITELIST_HASH_LEN, compar);
if (result == nullptr) {
sk_X509_pop_free(chain, X509_free);
@ -4438,7 +4438,7 @@ void DiffieHellman::DiffieHellmanGroup(
bool initialized = false;
const node::Utf8Value group_name(env->isolate(), args[0]);
for (unsigned int i = 0; i < ARRAY_SIZE(modp_groups); ++i) {
for (size_t i = 0; i < arraysize(modp_groups); ++i) {
const modp_group* it = modp_groups + i;
if (strcasecmp(*group_name, it->name) != 0)
@ -5141,7 +5141,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) {
Context::Scope context_scope(env->context());
Local<Value> argv[2];
EIO_PBKDF2After(req, argv);
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
req->MakeCallback(env->ondone_string(), arraysize(argv), argv);
delete req;
}
@ -5382,7 +5382,7 @@ void RandomBytesAfter(uv_work_t* work_req, int status) {
Context::Scope context_scope(env->context());
Local<Value> argv[2];
RandomBytesCheck(req, argv);
req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv);
req->MakeCallback(env->ondone_string(), arraysize(argv), argv);
delete req;
}

2
src/node_dtrace.cc

@ -255,7 +255,7 @@ void InitDTrace(Environment* env, Local<Object> target) {
#undef NODE_PROBE
};
for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) {
for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
target->Set(key, val);

8
src/node_file.cc

@ -282,7 +282,7 @@ static void After(uv_fs_t *req) {
}
name_argv[name_idx++] = filename;
if (name_idx >= ARRAY_SIZE(name_argv)) {
if (name_idx >= arraysize(name_argv)) {
fn->Call(env->context(), names, name_idx, name_argv)
.ToLocalChecked();
name_idx = 0;
@ -491,7 +491,7 @@ Local<Value> BuildStatsObject(Environment* env, const uv_stat_t* s) {
Local<Value> stats =
env->fs_stats_constructor_function()->NewInstance(
env->context(),
ARRAY_SIZE(argv),
arraysize(argv),
argv).FromMaybe(Local<Value>());
if (stats.IsEmpty())
@ -913,7 +913,7 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
name_v[name_idx++] = filename;
if (name_idx >= ARRAY_SIZE(name_v)) {
if (name_idx >= arraysize(name_v)) {
fn->Call(env->context(), names, name_idx, name_v)
.ToLocalChecked();
name_idx = 0;
@ -1030,7 +1030,7 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
uv_buf_t s_iovs[1024]; // use stack allocation when possible
uv_buf_t* iovs;
if (chunkCount > ARRAY_SIZE(s_iovs))
if (chunkCount > arraysize(s_iovs))
iovs = new uv_buf_t[chunkCount];
else
iovs = s_iovs;

16
src/node_http_parser.cc

@ -193,7 +193,7 @@ class Parser : public AsyncWrap {
if (num_fields_ == num_values_) {
// start of new field name
num_fields_++;
if (num_fields_ == ARRAY_SIZE(fields_)) {
if (num_fields_ == static_cast<int>(arraysize(fields_))) {
// ran out of space - flush to javascript land
Flush();
num_fields_ = 1;
@ -202,7 +202,7 @@ class Parser : public AsyncWrap {
fields_[num_fields_ - 1].Reset();
}
CHECK_LT(num_fields_, static_cast<int>(ARRAY_SIZE(fields_)));
CHECK_LT(num_fields_, static_cast<int>(arraysize(fields_)));
CHECK_EQ(num_fields_, num_values_ + 1);
fields_[num_fields_ - 1].Update(at, length);
@ -218,7 +218,7 @@ class Parser : public AsyncWrap {
values_[num_values_ - 1].Reset();
}
CHECK_LT(num_values_, static_cast<int>(ARRAY_SIZE(values_)));
CHECK_LT(num_values_, static_cast<int>(arraysize(values_)));
CHECK_EQ(num_values_, num_fields_);
values_[num_values_ - 1].Update(at, length);
@ -252,7 +252,7 @@ class Parser : public AsyncWrap {
return 0;
Local<Value> undefined = Undefined(env()->isolate());
for (size_t i = 0; i < ARRAY_SIZE(argv); i++)
for (size_t i = 0; i < arraysize(argv); i++)
argv[i] = undefined;
if (have_flushed_) {
@ -293,7 +293,7 @@ class Parser : public AsyncWrap {
Environment::AsyncCallbackScope callback_scope(env());
Local<Value> head_response =
MakeCallback(cb.As<Function>(), ARRAY_SIZE(argv), argv);
MakeCallback(cb.As<Function>(), arraysize(argv), argv);
if (head_response.IsEmpty()) {
got_exception_ = true;
@ -328,7 +328,7 @@ class Parser : public AsyncWrap {
Integer::NewFromUnsigned(env()->isolate(), length)
};
Local<Value> r = MakeCallback(cb.As<Function>(), ARRAY_SIZE(argv), argv);
Local<Value> r = MakeCallback(cb.As<Function>(), arraysize(argv), argv);
if (r.IsEmpty()) {
got_exception_ = true;
@ -646,7 +646,7 @@ class Parser : public AsyncWrap {
do {
size_t j = 0;
while (i < num_values_ && j < ARRAY_SIZE(argv) / 2) {
while (i < num_values_ && j < arraysize(argv) / 2) {
argv[j * 2] = fields_[i].ToString(env());
argv[j * 2 + 1] = values_[i].ToString(env());
i++;
@ -676,7 +676,7 @@ class Parser : public AsyncWrap {
url_.ToString(env())
};
Local<Value> r = MakeCallback(cb.As<Function>(), ARRAY_SIZE(argv), argv);
Local<Value> r = MakeCallback(cb.As<Function>(), arraysize(argv), argv);
if (r.IsEmpty())
got_exception_ = true;

7
src/node_internals.h

@ -107,8 +107,11 @@ inline static int snprintf(char *buffer, size_t n, const char *format, ...) {
#endif
#endif
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#if defined(_MSC_VER) && _MSC_VER < 1900
#define arraysize(a) (sizeof(a) / sizeof(*a)) // Workaround for VS 2013.
#else
template <typename T, size_t N>
constexpr size_t arraysize(const T(&)[N]) { return N; }
#endif
#ifndef ROUND_UP

2
src/node_lttng.cc

@ -248,7 +248,7 @@ void InitLTTNG(Environment* env, Local<Object> target) {
#undef NODE_PROBE
};
for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) {
for (size_t i = 0; i < arraysize(tab); i++) {
Local<String> key = OneByteString(env->isolate(), tab[i].name);
Local<Value> val = env->NewFunctionTemplate(tab[i].func)->GetFunction();
target->Set(key, val);

2
src/node_stat_watcher.cc

@ -70,7 +70,7 @@ void StatWatcher::Callback(uv_fs_poll_t* handle,
BuildStatsObject(env, prev),
Integer::New(env->isolate(), status)
};
wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv);
wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv);
}

2
src/node_win32_etw_provider-inl.h

@ -202,7 +202,7 @@ void NODE_V8SYMBOL_RESET() {
#define SETSYMBUF(s) \
wcscpy(symbuf, s); \
symbol_len = ARRAY_SIZE(s) - 1;
symbol_len = arraysize(s) - 1;
void NODE_V8SYMBOL_ADD(LPCSTR symbol,
int symbol_len,

2
src/node_win32_etw_provider.cc

@ -56,7 +56,7 @@ struct v8tags trace_codes[] = {
// If prefix is not in filtered list return -1,
// else return length of prefix and marker.
int FilterCodeEvents(const char* name, size_t len) {
for (int i = 0; i < ARRAY_SIZE(trace_codes); i++) {
for (size_t i = 0; i < arraysize(trace_codes); i++) {
size_t prelen = trace_codes[i].prelen;
if (prelen < len) {
if (strncmp(name, trace_codes[i].prefix, prelen) == 0) {

4
src/node_zlib.cc

@ -332,7 +332,7 @@ class ZCtx : public AsyncWrap {
// call the write() cb
Local<Value> args[2] = { avail_in, avail_out };
ctx->MakeCallback(env->callback_string(), ARRAY_SIZE(args), args);
ctx->MakeCallback(env->callback_string(), arraysize(args), args);
ctx->Unref();
if (ctx->pending_close_)
@ -354,7 +354,7 @@ class ZCtx : public AsyncWrap {
OneByteString(env->isolate(), message),
Number::New(env->isolate(), ctx->err_)
};
ctx->MakeCallback(env->onerror_string(), ARRAY_SIZE(args), args);
ctx->MakeCallback(env->onerror_string(), arraysize(args), args);
// no hope of rescue.
if (ctx->write_in_progress_)

6
src/pipe_wrap.cc

@ -183,7 +183,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
};
if (status != 0) {
pipe_wrap->MakeCallback(env->onconnection_string(), ARRAY_SIZE(argv), argv);
pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
return;
}
@ -198,7 +198,7 @@ void PipeWrap::OnConnection(uv_stream_t* handle, int status) {
// Successful accept. Call the onconnection callback in JavaScript land.
argv[1] = client_obj;
pipe_wrap->MakeCallback(env->onconnection_string(), ARRAY_SIZE(argv), argv);
pipe_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
}
// TODO(bnoordhuis) Maybe share this with TCPWrap?
@ -233,7 +233,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
Boolean::New(env->isolate(), writable)
};
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
delete req_wrap;
}

2
src/process_wrap.cc

@ -252,7 +252,7 @@ class ProcessWrap : public HandleWrap {
OneByteString(env->isolate(), signo_string(term_signal))
};
wrap->MakeCallback(env->onexit_string(), ARRAY_SIZE(argv), argv);
wrap->MakeCallback(env->onexit_string(), arraysize(argv), argv);
}
uv_process_t process_;

10
src/stream_base.cc

@ -84,7 +84,7 @@ void StreamBase::AfterShutdown(ShutdownWrap* req_wrap, int status) {
if (req_wrap->object()->Has(env->context(),
env->oncomplete_string()).FromJust()) {
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
}
delete req_wrap;
@ -132,7 +132,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
if (storage_size > INT_MAX)
return UV_ENOBUFS;
if (ARRAY_SIZE(bufs_) < count)
if (arraysize(bufs_) < count)
bufs = new uv_buf_t[count];
WriteWrap* req_wrap = WriteWrap::New(env,
@ -391,7 +391,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {
if (req_wrap->object()->Has(env->context(),
env->oncomplete_string()).FromJust()) {
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
}
req_wrap->Dispose();
@ -420,10 +420,10 @@ void StreamBase::EmitData(ssize_t nread,
node::MakeCallback(env,
GetObject(),
env->onread_string(),
ARRAY_SIZE(argv),
arraysize(argv),
argv);
} else {
async->MakeCallback(env->onread_string(), ARRAY_SIZE(argv), argv);
async->MakeCallback(env->onread_string(), arraysize(argv), argv);
}
}

4
src/tcp_wrap.cc

@ -269,7 +269,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
argv[1] = client_obj;
}
tcp_wrap->MakeCallback(env->onconnection_string(), ARRAY_SIZE(argv), argv);
tcp_wrap->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
}
@ -295,7 +295,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
v8::True(env->isolate())
};
req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv);
req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
delete req_wrap;
}

6
src/tls_wrap.cc

@ -284,8 +284,8 @@ void TLSWrap::EncOut() {
}
char* data[kSimultaneousBufferCount];
size_t size[ARRAY_SIZE(data)];
size_t count = ARRAY_SIZE(data);
size_t size[arraysize(data)];
size_t count = arraysize(data);
write_size_ = NodeBIO::FromBIO(enc_out_)->PeekMultiple(data, size, &count);
CHECK(write_size_ != 0 && count != 0);
@ -297,7 +297,7 @@ void TLSWrap::EncOut() {
this,
EncOutCb);
uv_buf_t buf[ARRAY_SIZE(data)];
uv_buf_t buf[arraysize(data)];
for (size_t i = 0; i < count; i++)
buf[i] = uv_buf_init(data[i], size[i]);
int err = stream_->DoWrite(write_req, buf, count, nullptr);

6
src/udp_wrap.cc

@ -270,7 +270,7 @@ void UDPWrap::DoSend(const FunctionCallbackInfo<Value>& args, int family) {
uv_buf_t bufs_[16];
uv_buf_t* bufs = bufs_;
if (ARRAY_SIZE(bufs_) < count)
if (arraysize(bufs_) < count)
bufs = new uv_buf_t[count];
// construct uv_buf_t array
@ -406,14 +406,14 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
if (nread < 0) {
if (buf->base != nullptr)
free(buf->base);
wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv);
wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv);
return;
}
char* base = static_cast<char*>(realloc(buf->base, nread));
argv[2] = Buffer::New(env, base, nread).ToLocalChecked();
argv[3] = AddressToJS(env, addr);
wrap->MakeCallback(env->onmessage_string(), ARRAY_SIZE(argv), argv);
wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv);
}

Loading…
Cancel
Save