Skip to content

Commit 9d52222

Browse files
committed
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 <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f98db78 commit 9d52222

22 files changed

+118
-154
lines changed

node.gyp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@
222222
'src/node_buffer.h',
223223
'src/node_constants.h',
224224
'src/node_debug_options.h',
225-
'src/node_file.h',
226-
'src/node_http_parser.h',
227225
'src/node_internals.h',
228226
'src/node_javascript.h',
229227
'src/node_mutex.h',

src/cares_wrap.cc

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ using v8::Object;
6767
using v8::String;
6868
using v8::Value;
6969

70+
namespace {
7071

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

116117

117-
static void NewGetAddrInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
118+
void NewGetAddrInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
118119
CHECK(args.IsConstructCall());
119120
}
120121

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

135136

136-
static void NewGetNameInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
137+
void NewGetNameInfoReqWrap(const FunctionCallbackInfo<Value>& args) {
137138
CHECK(args.IsConstructCall());
138139
}
139140

140141

141-
static void NewQueryReqWrap(const FunctionCallbackInfo<Value>& args) {
142+
void NewQueryReqWrap(const FunctionCallbackInfo<Value>& args) {
142143
CHECK(args.IsConstructCall());
143144
}
144145

145146

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

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

167168

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

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

188189

189-
static void ares_poll_close_cb(uv_handle_t* watcher) {
190+
void ares_poll_close_cb(uv_handle_t* watcher) {
190191
node_ares_task* task = ContainerOf(&node_ares_task::poll_watcher,
191192
reinterpret_cast<uv_poll_t*>(watcher));
192193
free(task);
193194
}
194195

195196

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

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

217218

218219
/* Callback from ares when socket operation is started */
219-
static void ares_sockstate_cb(void* data,
220-
ares_socket_t sock,
221-
int read,
222-
int write) {
220+
void ares_sockstate_cb(void* data,
221+
ares_socket_t sock,
222+
int read,
223+
int write) {
223224
Environment* env = static_cast<Environment*>(data);
224225
node_ares_task* task;
225226

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

275276

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

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

290291

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

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

11071108

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

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

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

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

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

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

1143-
static void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
1144+
void GetAddrInfo(const FunctionCallbackInfo<Value>& args) {
11441145
Environment* env = Environment::GetCurrent(args);
11451146

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

11901191

1191-
static void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
1192+
void GetNameInfo(const FunctionCallbackInfo<Value>& args) {
11921193
Environment* env = Environment::GetCurrent(args);
11931194

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

12191220

1220-
static void GetServers(const FunctionCallbackInfo<Value>& args) {
1221+
void GetServers(const FunctionCallbackInfo<Value>& args) {
12211222
Environment* env = Environment::GetCurrent(args);
12221223

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

12481249

1249-
static void SetServers(const FunctionCallbackInfo<Value>& args) {
1250+
void SetServers(const FunctionCallbackInfo<Value>& args) {
12501251
Environment* env = Environment::GetCurrent(args);
12511252

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

13151316

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

13221323

1323-
static void CaresTimerCloseCb(uv_handle_t* handle) {
1324+
void CaresTimerCloseCb(uv_handle_t* handle) {
13241325
Environment* env = Environment::from_cares_timer_handle(
13251326
reinterpret_cast<uv_timer_t*>(handle));
13261327
env->FinishHandleCleanup(handle);
13271328
}
13281329

13291330

1330-
static void CaresTimerClose(Environment* env,
1331+
void CaresTimerClose(Environment* env,
13311332
uv_handle_t* handle,
13321333
void* arg) {
13331334
uv_close(handle, CaresTimerCloseCb);
13341335
}
13351336

13361337

1337-
static void Initialize(Local<Object> target,
1338-
Local<Value> unused,
1339-
Local<Context> context) {
1338+
void Initialize(Local<Object> target,
1339+
Local<Value> unused,
1340+
Local<Context> context) {
13401341
Environment* env = Environment::GetCurrent(context);
13411342

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

1428+
} // anonymous namespace
14271429
} // namespace cares_wrap
14281430
} // namespace node
14291431

src/fs_event_wrap.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ using v8::Object;
4343
using v8::String;
4444
using v8::Value;
4545

46+
namespace {
47+
4648
class FSEventWrap: public HandleWrap {
4749
public:
4850
static void Initialize(Local<Object> target,
@@ -214,6 +216,7 @@ void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
214216
HandleWrap::Close(args);
215217
}
216218

219+
} // anonymous namespace
217220
} // namespace node
218221

219222
NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs_event_wrap, node::FSEventWrap::Initialize)

src/node.cc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "node.h"
2323
#include "node_buffer.h"
2424
#include "node_constants.h"
25-
#include "node_file.h"
26-
#include "node_http_parser.h"
2725
#include "node_javascript.h"
2826
#include "node_version.h"
2927
#include "node_internals.h"
@@ -1049,8 +1047,10 @@ void* ArrayBufferAllocator::Allocate(size_t size) {
10491047
return node::UncheckedMalloc(size);
10501048
}
10511049

1052-
static bool DomainHasErrorHandler(const Environment* env,
1053-
const Local<Object>& domain) {
1050+
namespace {
1051+
1052+
bool DomainHasErrorHandler(const Environment* env,
1053+
const Local<Object>& domain) {
10541054
HandleScope scope(env->isolate());
10551055

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

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

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

10981098

1099-
static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
1099+
bool ShouldAbortOnUncaughtException(Isolate* isolate) {
11001100
HandleScope scope(isolate);
11011101

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

1229+
} // anonymous namespace
1230+
12291231

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

22762278

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

22932295

2294-
void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
2296+
static void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
22952297
Environment* env = Environment::GetCurrent(args);
22962298

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

23212323

2322-
void Kill(const FunctionCallbackInfo<Value>& args) {
2324+
static void Kill(const FunctionCallbackInfo<Value>& args) {
23232325
Environment* env = Environment::GetCurrent(args);
23242326

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

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

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

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

26042606

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

3015+
namespace {
30133016

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

30233026

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

3083+
} // anonymous namespace
30803084

30813085
void SetupProcessObject(Environment* env,
30823086
int argc,

0 commit comments

Comments
 (0)