Skip to content
Permalink
Browse files

src: reduce number of exported symbols

Use `static` definitions and anonymous namespaces to reduce the
number of symbols that are exported from the `node` binary.

PR-URL: #12366
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
addaleax committed Apr 12, 2017
1 parent f98db78 commit 9d522225e7907b6cf631975b34f586984f698e33
@@ -222,8 +222,6 @@
'src/node_buffer.h',
'src/node_constants.h',
'src/node_debug_options.h',
'src/node_file.h',
'src/node_http_parser.h',
'src/node_internals.h',
'src/node_javascript.h',
'src/node_mutex.h',
@@ -67,6 +67,7 @@ using v8::Object;
using v8::String;
using v8::Value;

namespace {

inline const char* ToErrorCodeString(int status) {
switch (status) {
@@ -114,7 +115,7 @@ GetAddrInfoReqWrap::GetAddrInfoReqWrap(Environment* env,
}


static void NewGetAddrInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
void NewGetAddrInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
CHECK(args.IsConstructCall());
}

@@ -133,17 +134,17 @@ GetNameInfoReqWrap::GetNameInfoReqWrap(Environment* env,
}


static void NewGetNameInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
void NewGetNameInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
CHECK(args.IsConstructCall());
}


static void NewQueryReqWrap(const FunctionCallbackInfo<Value>& args) {
void NewQueryReqWrap(const FunctionCallbackInfo<Value>& args) {
CHECK(args.IsConstructCall());
}


static int cmp_ares_tasks(const node_ares_task* a, const node_ares_task* b) {
int cmp_ares_tasks(const node_ares_task* a, const node_ares_task* b) {
if (a->sock < b->sock)
return -1;
if (a->sock > b->sock)
@@ -158,14 +159,14 @@ RB_GENERATE_STATIC(node_ares_task_list, node_ares_task, node, cmp_ares_tasks)

/* This is called once per second by loop->timer. It is used to constantly */
/* call back into c-ares for possibly processing timeouts. */
static void ares_timeout(uv_timer_t* handle) {
void ares_timeout(uv_timer_t* handle) {
Environment* env = Environment::from_cares_timer_handle(handle);
CHECK_EQ(false, RB_EMPTY(env->cares_task_list()));
ares_process_fd(env->cares_channel(), ARES_SOCKET_BAD, ARES_SOCKET_BAD);
}


static void ares_poll_cb(uv_poll_t* watcher, int status, int events) {
void ares_poll_cb(uv_poll_t* watcher, int status, int events) {
node_ares_task* task = ContainerOf(&node_ares_task::poll_watcher, watcher);
Environment* env = task->env;

@@ -186,15 +187,15 @@ static void ares_poll_cb(uv_poll_t* watcher, int status, int events) {
}


static void ares_poll_close_cb(uv_handle_t* watcher) {
void ares_poll_close_cb(uv_handle_t* watcher) {
node_ares_task* task = ContainerOf(&node_ares_task::poll_watcher,
reinterpret_cast<uv_poll_t*>(watcher));
free(task);
}


/* Allocates and returns a new node_ares_task */
static node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) {
node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) {
auto task = node::UncheckedMalloc<node_ares_task>(1);

if (task == nullptr) {
@@ -216,10 +217,10 @@ static node_ares_task* ares_task_create(Environment* env, ares_socket_t sock) {


/* Callback from ares when socket operation is started */
static void ares_sockstate_cb(void* data,
ares_socket_t sock,
int read,
int write) {
void ares_sockstate_cb(void* data,
ares_socket_t sock,
int read,
int write) {
Environment* env = static_cast<Environment*>(data);
node_ares_task* task;

@@ -273,7 +274,7 @@ static void ares_sockstate_cb(void* data,
}


static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) {
Local<Array> HostentToAddresses(Environment* env, struct hostent* host) {
EscapableHandleScope scope(env->isolate());
Local<Array> addresses = Array::New(env->isolate());

@@ -288,7 +289,7 @@ static Local<Array> HostentToAddresses(Environment* env, struct hostent* host) {
}


static Local<Array> HostentToNames(Environment* env, struct hostent* host) {
Local<Array> HostentToNames(Environment* env, struct hostent* host) {
EscapableHandleScope scope(env->isolate());
Local<Array> names = Array::New(env->isolate());

@@ -1105,7 +1106,7 @@ void AfterGetNameInfo(uv_getnameinfo_t* req,
}


static void IsIP(const FunctionCallbackInfo<Value>& args) {
void IsIP(const FunctionCallbackInfo<Value>& args) {
node::Utf8Value ip(args.GetIsolate(), args[0]);
char address_buffer[sizeof(struct in6_addr)];

@@ -1118,7 +1119,7 @@ static void IsIP(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(rc);
}

static void IsIPv4(const FunctionCallbackInfo<Value>& args) {
void IsIPv4(const FunctionCallbackInfo<Value>& args) {
node::Utf8Value ip(args.GetIsolate(), args[0]);
char address_buffer[sizeof(struct in_addr)];

@@ -1129,7 +1130,7 @@ static void IsIPv4(const FunctionCallbackInfo<Value>& args) {
}
}

static void IsIPv6(const FunctionCallbackInfo<Value>& args) {
void IsIPv6(const FunctionCallbackInfo<Value>& args) {
node::Utf8Value ip(args.GetIsolate(), args[0]);
char address_buffer[sizeof(struct in6_addr)];

@@ -1140,7 +1141,7 @@ static void IsIPv6(const FunctionCallbackInfo<Value>& args) {
}
}

static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK(args[0]->IsObject());
@@ -1188,7 +1189,7 @@ static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
}


static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK(args[0]->IsObject());
@@ -1217,7 +1218,7 @@ static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
}


static void GetServers(const FunctionCallbackInfo<Value>& args) {
void GetServers(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Local<Array> server_array = Array::New(env->isolate());
@@ -1246,7 +1247,7 @@ static void GetServers(const FunctionCallbackInfo<Value>& args) {
}


static void SetServers(const FunctionCallbackInfo<Value>& args) {
void SetServers(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK(args[0]->IsArray());
@@ -1313,30 +1314,30 @@ static void SetServers(const FunctionCallbackInfo<Value>& args) {
}


static void StrError(const FunctionCallbackInfo<Value>& args) {
void StrError(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
const char* errmsg = ares_strerror(args[0]->Int32Value());
args.GetReturnValue().Set(OneByteString(env->isolate(), errmsg));
}


static void CaresTimerCloseCb(uv_handle_t* handle) {
void CaresTimerCloseCb(uv_handle_t* handle) {
Environment* env = Environment::from_cares_timer_handle(
reinterpret_cast<uv_timer_t*>(handle));
env->FinishHandleCleanup(handle);
}


static void CaresTimerClose(Environment* env,
void CaresTimerClose(Environment* env,
uv_handle_t* handle,
void* arg) {
uv_close(handle, CaresTimerCloseCb);
}


static void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);

int r = ares_library_init(ARES_LIB_INIT_ALL);
@@ -1424,6 +1425,7 @@ static void Initialize(Local<Object> target,
qrw->GetFunction());
}

} // anonymous namespace
} // namespace cares_wrap
} // namespace node

@@ -43,6 +43,8 @@ using v8::Object;
using v8::String;
using v8::Value;

namespace {

class FSEventWrap: public HandleWrap {
public:
static void Initialize(Local<Object> target,
@@ -214,6 +216,7 @@ void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
HandleWrap::Close(args);
}

} // anonymous namespace
} // namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs_event_wrap, node::FSEventWrap::Initialize)
@@ -22,8 +22,6 @@
#include "node.h"
#include "node_buffer.h"
#include "node_constants.h"
#include "node_file.h"
#include "node_http_parser.h"
#include "node_javascript.h"
#include "node_version.h"
#include "node_internals.h"
@@ -1049,8 +1047,10 @@ void* ArrayBufferAllocator::Allocate(size_t size) {
return node::UncheckedMalloc(size);
}

static bool DomainHasErrorHandler(const Environment* env,
const Local<Object>& domain) {
namespace {

bool DomainHasErrorHandler(const Environment* env,
const Local<Object>& domain) {
HandleScope scope(env->isolate());

Local<Value> domain_event_listeners_v = domain->Get(env->events_string());
@@ -1071,7 +1071,7 @@ static bool DomainHasErrorHandler(const Environment* env,
return false;
}

static bool DomainsStackHasErrorHandler(const Environment* env) {
bool DomainsStackHasErrorHandler(const Environment* env) {
HandleScope scope(env->isolate());

if (!env->using_domains())
@@ -1096,7 +1096,7 @@ static bool DomainsStackHasErrorHandler(const Environment* env) {
}


static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
bool ShouldAbortOnUncaughtException(Isolate* isolate) {
HandleScope scope(isolate);

Environment* env = Environment::GetCurrent(isolate);
@@ -1226,6 +1226,8 @@ void SetupPromises(const FunctionCallbackInfo<Value>& args) {
FIXED_ONE_BYTE_STRING(args.GetIsolate(), "_setupPromises")).FromJust();
}

} // anonymous namespace


Local<Value> MakeCallback(Environment* env,
Local<Value> recv,
@@ -2274,7 +2276,7 @@ static void WaitForInspectorDisconnect(Environment* env) {
}


void Exit(const FunctionCallbackInfo<Value>& args) {
static void Exit(const FunctionCallbackInfo<Value>& args) {
WaitForInspectorDisconnect(Environment::GetCurrent(args));
exit(args[0]->Int32Value());
}
@@ -2291,7 +2293,7 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
}


void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

size_t rss;
@@ -2319,7 +2321,7 @@ void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
}


void Kill(const FunctionCallbackInfo<Value>& args) {
static void Kill(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

if (args.Length() != 2) {
@@ -2343,7 +2345,7 @@ void Kill(const FunctionCallbackInfo<Value>& args) {
// broken into the upper/lower 32 bits to be converted back in JS,
// because there is no Uint64Array in JS.
// The third entry contains the remaining nanosecond part of the value.
void Hrtime(const FunctionCallbackInfo<Value>& args) {
static void Hrtime(const FunctionCallbackInfo<Value>& args) {
uint64_t t = uv_hrtime();

Local<ArrayBuffer> ab = args[0].As<Uint32Array>()->Buffer();
@@ -2362,7 +2364,7 @@ void Hrtime(const FunctionCallbackInfo<Value>& args) {
// which are uv_timeval_t structs (long tv_sec, long tv_usec).
// Returns those values as Float64 microseconds in the elements of the array
// passed to the function.
void CPUUsage(const FunctionCallbackInfo<Value>& args) {
static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
uv_rusage_t rusage;

// Call libuv to get the values we'll return.
@@ -2433,7 +2435,7 @@ struct node_module* get_linked_module(const char* name) {
// FIXME(bnoordhuis) Not multi-context ready. TBD how to resolve the conflict
// when two contexts try to load the same shared object. Maybe have a shadow
// cache that's a plain C list or hash table that's shared across contexts?
void DLOpen(const FunctionCallbackInfo<Value>& args) {
static void DLOpen(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
uv_lib_t lib;

@@ -2602,7 +2604,7 @@ void FatalException(Isolate* isolate, const TryCatch& try_catch) {
}


void OnMessage(Local<Message> message, Local<Value> error) {
static void OnMessage(Local<Message> message, Local<Value> error) {
// The current version of V8 sends messages for errors only
// (thus `error` is always set).
FatalException(Isolate::GetCurrent(), error, message);
@@ -3010,6 +3012,7 @@ static void DebugProcess(const FunctionCallbackInfo<Value>& args);
static void DebugPause(const FunctionCallbackInfo<Value>& args);
static void DebugEnd(const FunctionCallbackInfo<Value>& args);

namespace {

void NeedImmediateCallbackGetter(Local<Name> property,
const PropertyCallbackInfo<Value>& info) {
@@ -3021,7 +3024,7 @@ void NeedImmediateCallbackGetter(Local<Name> property,
}


static void NeedImmediateCallbackSetter(
void NeedImmediateCallbackSetter(
Local<Name> property,
Local<Value> value,
const PropertyCallbackInfo<void>& info) {
@@ -3077,6 +3080,7 @@ void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
.FromJust(); \
} while (0)

} // anonymous namespace

void SetupProcessObject(Environment* env,
int argc,

0 comments on commit 9d52222

Please sign in to comment.
You can’t perform that action at this time.