From c63d48f49659200900201237dce42737ba52d0ad Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 31 Mar 2016 12:47:06 +0200 Subject: [PATCH] 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 Reviewed-By: James M Snell --- src/async-wrap-inl.h | 2 +- src/cares_wrap.cc | 8 ++++---- src/debug-agent.cc | 8 ++++---- src/fs_event_wrap.cc | 2 +- src/js_stream.cc | 4 ++-- src/node.cc | 16 ++++++++-------- src/node_contextify.cc | 2 +- src/node_counters.cc | 2 +- src/node_crypto.cc | 22 +++++++++++----------- src/node_dtrace.cc | 2 +- src/node_file.cc | 4 ++-- src/node_http_parser.cc | 14 +++++++------- src/node_internals.h | 7 +++++-- src/node_lttng.cc | 2 +- src/node_stat_watcher.cc | 2 +- src/node_win32_etw_provider-inl.h | 2 +- src/node_win32_etw_provider.cc | 2 +- src/node_zlib.cc | 4 ++-- src/pipe_wrap.cc | 6 +++--- src/process_wrap.cc | 2 +- src/stream_base.cc | 10 +++++----- src/tcp_wrap.cc | 4 ++-- src/tls_wrap.cc | 6 +++--- src/udp_wrap.cc | 4 ++-- 24 files changed, 70 insertions(+), 67 deletions(-) diff --git a/src/async-wrap-inl.h b/src/async-wrap-inl.h index 1d9ebe27e45bef..f2d2c3ecf1c7b4 100644 --- a/src/async-wrap-inl.h +++ b/src/async-wrap-inl.h @@ -49,7 +49,7 @@ inline AsyncWrap::AsyncWrap(Environment* env, argv[2] = parent->object(); v8::MaybeLocal ret = - init_fn->Call(env->context(), object, ARRAY_SIZE(argv), argv); + init_fn->Call(env->context(), object, arraysize(argv), argv); if (ret.IsEmpty()) FatalError("node::AsyncWrap::AsyncWrap", "init hook threw"); diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 66d5d08fe656fe..41b545468f55a8 100644 --- a/src/cares_wrap.cc +++ b/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 answer, Local 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) { @@ -994,7 +994,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; } @@ -1025,7 +1025,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; } diff --git a/src/debug-agent.cc b/src/debug-agent.cc index 93d2ce71f11a38..df6e75d07ff38c 100644 --- a/src/debug-agent.cc +++ b/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" @@ -175,9 +175,9 @@ void Agent::WorkerRun() { isolate, &child_loop_, context, - ARRAY_SIZE(argv), + arraysize(argv), argv, - ARRAY_SIZE(argv), + arraysize(argv), argv); child_env_ = env; @@ -301,7 +301,7 @@ void Agent::ChildSignalCb(uv_async_t* signal) { MakeCallback(isolate, api, "onmessage", - ARRAY_SIZE(argv), + arraysize(argv), argv); delete msg; } diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 7768f94459c16a..a9f96389121c9e 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -159,7 +159,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, argv[2] = OneByteString(env->isolate(), filename); } - wrap->MakeCallback(env->onchange_string(), ARRAY_SIZE(argv), argv); + wrap->MakeCallback(env->onchange_string(), arraysize(argv), argv); } diff --git a/src/js_stream.cc b/src/js_stream.cc index 25938f111ba6ac..e81709a8056965 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -75,7 +75,7 @@ int JSStream::DoShutdown(ShutdownWrap* req_wrap) { req_wrap->Dispatched(); Local 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 res = - MakeCallback(env()->onwrite_string(), ARRAY_SIZE(argv), argv); + MakeCallback(env()->onwrite_string(), arraysize(argv), argv); return res->Int32Value(); } diff --git a/src/node.cc b/src/node.cc index 267eaea4efbad4..8264bfe8bba8a3 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1101,7 +1101,7 @@ void PromiseRejectCallback(PromiseRejectMessage message) { Local args[] = { event, promise, value }; Local process = env->process_object(); - callback->Call(process, ARRAY_SIZE(args), args); + callback->Call(process, arraysize(args), args); } void SetupPromises(const FunctionCallbackInfo& args) { @@ -2457,12 +2457,12 @@ static void EnvGetter(Local property, WCHAR buffer[32767]; // The maximum size allowed for environment variables. DWORD result = GetEnvironmentVariableW(reinterpret_cast(*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(buffer); Local rc = String::NewFromTwoByte(isolate, two_byte_buffer); return info.GetReturnValue().Set(rc); @@ -3461,7 +3461,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(); @@ -3582,7 +3582,7 @@ static int RegisterDebugSignalHandler() { if (GetDebugSignalHandlerMappingName(pid, mapping_name, - ARRAY_SIZE(mapping_name)) < 0) { + arraysize(mapping_name)) < 0) { return -1; } @@ -3645,7 +3645,7 @@ static void DebugProcess(const FunctionCallbackInfo& args) { if (GetDebugSignalHandlerMappingName(pid, mapping_name, - ARRAY_SIZE(mapping_name)) < 0) { + arraysize(mapping_name)) < 0) { env->ThrowErrnoException(errno, "sprintf"); goto out; } @@ -3922,7 +3922,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); } @@ -3941,7 +3941,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(); diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 8235dcd49e093c..18bbc580054349 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -161,7 +161,7 @@ class ContextifyContext { CHECK(clone_property_method->IsFunction()); } Local args[] = { global, key, sandbox_obj }; - clone_property_method->Call(global, ARRAY_SIZE(args), args); + clone_property_method->Call(global, arraysize(args), args); } } } diff --git a/src/node_counters.cc b/src/node_counters.cc index ca05e253199af5..9853784e557136 100644 --- a/src/node_counters.cc +++ b/src/node_counters.cc @@ -98,7 +98,7 @@ void InitPerfCounters(Environment* env, Local target) { #undef NODE_PROBE }; - for (int i = 0; i < ARRAY_SIZE(tab); i++) { + for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); target->Set(key, val); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 382a42f22727f8..21e4d33cab9316 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -760,7 +760,7 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo& 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; @@ -1092,7 +1092,7 @@ int SecureContext::TicketKeyCallback(SSL* ssl, Local ret = node::MakeCallback(env, sc->object(), env->ticketkeycallback_string(), - ARRAY_SIZE(argv), + arraysize(argv), argv); Local arr = ret.As(); @@ -1284,7 +1284,7 @@ int SSLWrap::NewSessionCallback(SSL* s, SSL_SESSION* sess) { sess->session_id_length).ToLocalChecked(); Local 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; } @@ -1318,7 +1318,7 @@ void SSLWrap::OnClientHello(void* arg, Boolean::New(env->isolate(), hello.ocsp_request())); Local argv[] = { hello_obj }; - w->MakeCallback(env->onclienthello_string(), ARRAY_SIZE(argv), argv); + w->MakeCallback(env->onclienthello_string(), arraysize(argv), argv); } @@ -1393,8 +1393,8 @@ static Local X509ToObject(Environment* env, X509* cert) { int nids[] = { NID_subject_alt_name, NID_info_access }; Local 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; @@ -2128,7 +2128,7 @@ int SSLWrap::SSLCertCallback(SSL* s, void* arg) { info->Set(env->ocsp_request_string(), Boolean::New(env->isolate(), ocsp)); Local 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; @@ -2491,7 +2491,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); @@ -4229,7 +4229,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) @@ -4883,7 +4883,7 @@ void EIO_PBKDF2After(uv_work_t* work_req, int status) { Context::Scope context_scope(env->context()); Local 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; } @@ -5124,7 +5124,7 @@ void RandomBytesAfter(uv_work_t* work_req, int status) { Context::Scope context_scope(env->context()); Local argv[2]; RandomBytesCheck(req, argv); - req->MakeCallback(env->ondone_string(), ARRAY_SIZE(argv), argv); + req->MakeCallback(env->ondone_string(), arraysize(argv), argv); delete req; } diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index 568972bab3f90f..b92a0dd411b981 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -257,7 +257,7 @@ void InitDTrace(Environment* env, Local target) { #undef NODE_PROBE }; - for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { + for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); target->Set(key, val); diff --git a/src/node_file.cc b/src/node_file.cc index b6ef7d5b78f70e..b31435ecc0a77c 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -429,7 +429,7 @@ Local BuildStatsObject(Environment* env, const uv_stat_t* s) { // Call out to JavaScript to create the stats object. Local stats = - env->fs_stats_constructor_function()->NewInstance(ARRAY_SIZE(argv), argv); + env->fs_stats_constructor_function()->NewInstance(arraysize(argv), argv); if (stats.IsEmpty()) return handle_scope.Escape(Local()); @@ -932,7 +932,7 @@ static void WriteBuffers(const FunctionCallbackInfo& 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; diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 9225915e12f7fd..2550ca313a2c72 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -189,7 +189,7 @@ class Parser : public BaseObject { if (num_fields_ == num_values_) { // start of new field name num_fields_++; - if (num_fields_ == ARRAY_SIZE(fields_)) { + if (num_fields_ == static_cast(arraysize(fields_))) { // ran out of space - flush to javascript land Flush(); num_fields_ = 1; @@ -198,7 +198,7 @@ class Parser : public BaseObject { fields_[num_fields_ - 1].Reset(); } - CHECK_LT(num_fields_, static_cast(ARRAY_SIZE(fields_))); + CHECK_LT(num_fields_, static_cast(arraysize(fields_))); CHECK_EQ(num_fields_, num_values_ + 1); fields_[num_fields_ - 1].Update(at, length); @@ -214,7 +214,7 @@ class Parser : public BaseObject { values_[num_values_ - 1].Reset(); } - CHECK_LT(num_values_, static_cast(ARRAY_SIZE(values_))); + CHECK_LT(num_values_, static_cast(arraysize(values_))); CHECK_EQ(num_values_, num_fields_); values_[num_values_ - 1].Update(at, length); @@ -248,7 +248,7 @@ class Parser : public BaseObject { return 0; Local 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_) { @@ -287,7 +287,7 @@ class Parser : public BaseObject { argv[A_UPGRADE] = Boolean::New(env()->isolate(), parser_.upgrade); Local head_response = - cb.As()->Call(obj, ARRAY_SIZE(argv), argv); + cb.As()->Call(obj, arraysize(argv), argv); if (head_response.IsEmpty()) { got_exception_ = true; @@ -322,7 +322,7 @@ class Parser : public BaseObject { Integer::NewFromUnsigned(env()->isolate(), length) }; - Local r = cb.As()->Call(obj, ARRAY_SIZE(argv), argv); + Local r = cb.As()->Call(obj, arraysize(argv), argv); if (r.IsEmpty()) { got_exception_ = true; @@ -659,7 +659,7 @@ class Parser : public BaseObject { url_.ToString(env()) }; - Local r = cb.As()->Call(obj, ARRAY_SIZE(argv), argv); + Local r = cb.As()->Call(obj, arraysize(argv), argv); if (r.IsEmpty()) got_exception_ = true; diff --git a/src/node_internals.h b/src/node_internals.h index 5ff6b63d21ab15..3df7676d2a9d51 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -109,8 +109,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 +constexpr size_t arraysize(const T(&)[N]) { return N; } #endif #ifndef ROUND_UP diff --git a/src/node_lttng.cc b/src/node_lttng.cc index 876bcda92f82fa..41ccdf33411563 100644 --- a/src/node_lttng.cc +++ b/src/node_lttng.cc @@ -250,7 +250,7 @@ void InitLTTNG(Environment* env, Local target) { #undef NODE_PROBE }; - for (unsigned int i = 0; i < ARRAY_SIZE(tab); i++) { + for (size_t i = 0; i < arraysize(tab); i++) { Local key = OneByteString(env->isolate(), tab[i].name); Local val = env->NewFunctionTemplate(tab[i].func)->GetFunction(); target->Set(key, val); diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index bd1cb73248e99c..4fa01794f6c6da 100644 --- a/src/node_stat_watcher.cc +++ b/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); } diff --git a/src/node_win32_etw_provider-inl.h b/src/node_win32_etw_provider-inl.h index 3fef20cc1488c1..04cd31cee3c2f6 100644 --- a/src/node_win32_etw_provider-inl.h +++ b/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, diff --git a/src/node_win32_etw_provider.cc b/src/node_win32_etw_provider.cc index c6bfbeaaf6c989..6877f1977dae8b 100644 --- a/src/node_win32_etw_provider.cc +++ b/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) { diff --git a/src/node_zlib.cc b/src/node_zlib.cc index da60d4430f3042..29649e32c7dbbc 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -313,7 +313,7 @@ class ZCtx : public AsyncWrap { // call the write() cb Local 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_) @@ -335,7 +335,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_) diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 84164723e95b99..e3377d402f5ab1 100644 --- a/src/pipe_wrap.cc +++ b/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; } diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 3456d2be8fbab8..420c71d7ea4052 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -254,7 +254,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_; diff --git a/src/stream_base.cc b/src/stream_base.cc index 27ae0fee7b1309..f9fed08d134c50 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -83,7 +83,7 @@ void StreamBase::AfterShutdown(ShutdownWrap* req_wrap, int status) { }; if (req_wrap->object()->Has(env->oncomplete_string())) - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); delete req_wrap; } @@ -130,7 +130,7 @@ int StreamBase::Writev(const FunctionCallbackInfo& 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, @@ -388,7 +388,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) { } if (req_wrap->object()->Has(env->oncomplete_string())) - req_wrap->MakeCallback(env->oncomplete_string(), ARRAY_SIZE(argv), argv); + req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv); req_wrap->Dispose(); } @@ -416,10 +416,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); } } diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 3f3e6a0ad4a752..0214be100228c4 100644 --- a/src/tcp_wrap.cc +++ b/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; } diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 85730b34936b55..48ec8a54a98c79 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -283,8 +283,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); @@ -295,7 +295,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); diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index cb678f14fb3826..8c460ebac6ff22 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -380,14 +380,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(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); }