From e10fd321e44804b98f77d2eaedb9b47e7635fb41 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 7 Dec 2011 18:03:18 -0800 Subject: [PATCH] move global vars from platfrom, node_signal_watcher to struct --- src/node_crypto.cc | 3 +-- src/node_signal_watcher.cc | 21 +++++++++++---------- src/node_vars.h | 12 ++++++++++++ src/platform_darwin.cc | 3 ++- src/platform_freebsd.cc | 4 +++- src/platform_linux.cc | 34 ++++++++++++++++------------------ src/platform_win32.cc | 4 +++- 7 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 23f663b3d6..6caab97a60 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -82,6 +82,7 @@ static const int X509_NAME_FLAGS = ASN1_STRFLGS_ESC_CTRL #define version_symbol NODE_VAR(version_symbol) #define ext_key_usage_symbol NODE_VAR(ext_key_usage_symbol) #define secure_context_constructor NODE_VAR(secure_context_constructor) +#define locks NODE_VAR(locks) namespace node { @@ -98,8 +99,6 @@ static unsigned long crypto_id_cb(void) { #endif /* !_WIN32 */ } -static uv_rwlock_t* locks; - static void crypto_lock_init(void) { int i, n; diff --git a/src/node_signal_watcher.cc b/src/node_signal_watcher.cc index 1027b3efd1..d87b3c3326 100644 --- a/src/node_signal_watcher.cc +++ b/src/node_signal_watcher.cc @@ -22,26 +22,27 @@ #include #include +#include +#define callback_symbol NODE_VAR(callback_symbol) +#define signal_watcher_constructor_template NODE_VAR(signal_watcher_constructor_template) + namespace node { using namespace v8; -Persistent SignalWatcher::constructor_template; -static Persistent callback_symbol; - void SignalWatcher::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(SignalWatcher::New); - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("SignalWatcher")); + signal_watcher_constructor_template = Persistent::New(t); + signal_watcher_constructor_template->InstanceTemplate()->SetInternalFieldCount(1); + signal_watcher_constructor_template->SetClassName(String::NewSymbol("SignalWatcher")); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "start", SignalWatcher::Start); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "stop", SignalWatcher::Stop); + NODE_SET_PROTOTYPE_METHOD(signal_watcher_constructor_template, "start", SignalWatcher::Start); + NODE_SET_PROTOTYPE_METHOD(signal_watcher_constructor_template, "stop", SignalWatcher::Stop); target->Set(String::NewSymbol("SignalWatcher"), - constructor_template->GetFunction()); + signal_watcher_constructor_template->GetFunction()); callback_symbol = NODE_PSYMBOL("callback"); } @@ -73,7 +74,7 @@ void SignalWatcher::Callback(EV_P_ ev_signal *watcher, int revents) { Handle SignalWatcher::New(const Arguments& args) { if (!args.IsConstructCall()) { - return FromConstructorTemplate(constructor_template, args); + return FromConstructorTemplate(signal_watcher_constructor_template, args); } HandleScope scope; diff --git a/src/node_vars.h b/src/node_vars.h index bae0b08751..d6caac100b 100644 --- a/src/node_vars.h +++ b/src/node_vars.h @@ -149,6 +149,7 @@ struct globals { v8::Persistent callback_sym; // node_crypto.cc + uv_rwlock_t* locks; v8::Persistent subject_symbol; v8::Persistent subjectaltname_symbol; v8::Persistent modulus_symbol; @@ -167,6 +168,17 @@ struct globals { v8::Persistent chars_written_sym; v8::Persistent write_sym; v8::Persistent buffer_constructor_template; + + // platform*.cc + char* process_title; + struct { + char *str; + size_t len; + } linux_process_title; + + // node_signal_watcher.cc + v8::Persistent callback_symbol; + v8::Persistent signal_watcher_constructor_template; }; struct globals* globals_get(); diff --git a/src/platform_darwin.cc b/src/platform_darwin.cc index a196669eb7..391762cd5d 100644 --- a/src/platform_darwin.cc +++ b/src/platform_darwin.cc @@ -39,13 +39,14 @@ #include #include +#include +#define process_title NODE_VAR(process_title) namespace node { using namespace v8; -static char *process_title; double Platform::prog_start_time = Platform::GetUptime(); char** Platform::SetupArgs(int argc, char *argv[]) { diff --git a/src/platform_freebsd.cc b/src/platform_freebsd.cc index 5b0e01e88e..77934274ac 100644 --- a/src/platform_freebsd.cc +++ b/src/platform_freebsd.cc @@ -37,12 +37,14 @@ #include #include +#include +#define process_title NODE_VAR(process_title) + namespace node { using namespace v8; -static char *process_title; double Platform::prog_start_time = Platform::GetUptime(); char** Platform::SetupArgs(int argc, char *argv[]) { diff --git a/src/platform_linux.cc b/src/platform_linux.cc index 287ed3e306..a64251e9fb 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -48,20 +48,18 @@ # include #endif +#include +#define linux_process_title NODE_VAR(linux_process_title) +#define getbuf NODE_VAR(getbuf) + extern char **environ; namespace node { using namespace v8; -static char buf[MAXPATHLEN + 1]; double Platform::prog_start_time = Platform::GetUptime(); -static struct { - char *str; - size_t len; -} process_title; - char** Platform::SetupArgs(int argc, char *argv[]) { char **new_argv; @@ -75,23 +73,23 @@ char** Platform::SetupArgs(int argc, char *argv[]) { s = envc ? environ[envc - 1] : argv[argc - 1]; - process_title.str = argv[0]; - process_title.len = s + strlen(s) + 1 - argv[0]; + linux_process_title.str = argv[0]; + linux_process_title.len = s + strlen(s) + 1 - argv[0]; - size = process_title.len; + size = linux_process_title.len; size += (argc + 1) * sizeof(char **); size += (envc + 1) * sizeof(char **); if ((s = (char *) malloc(size)) == NULL) { - process_title.str = NULL; - process_title.len = 0; + linux_process_title.str = NULL; + linux_process_title.len = 0; return argv; } new_argv = (char **) s; new_env = new_argv + argc + 1; s = (char *) (new_env + envc + 1); - memcpy(s, process_title.str, process_title.len); + memcpy(s, linux_process_title.str, linux_process_title.len); for (i = 0; i < argc; i++) new_argv[i] = s + (argv[i] - argv[0]); @@ -110,15 +108,15 @@ char** Platform::SetupArgs(int argc, char *argv[]) { void Platform::SetProcessTitle(char *title) { /* No need to terminate, last char is always '\0'. */ - if (process_title.len) - strncpy(process_title.str, title, process_title.len - 1); + if (linux_process_title.len) + strncpy(linux_process_title.str, title, linux_process_title.len - 1); } const char* Platform::GetProcessTitle(int *len) { - if (process_title.str) { - *len = strlen(process_title.str); - return process_title.str; + if (linux_process_title.str) { + *len = strlen(linux_process_title.str); + return linux_process_title.str; } else { *len = 0; @@ -140,7 +138,7 @@ int Platform::GetMemory(size_t *rss) { /* PID */ if (fscanf(f, "%d ", &itmp) == 0) goto error; /* coverity[secure_coding] */ /* Exec file */ - cbuf = buf; + cbuf = getbuf; foundExeEnd = false; if (fscanf (f, "%c", cbuf++) == 0) goto error; // ( while (1) { diff --git a/src/platform_win32.cc b/src/platform_win32.cc index 197b1ac31a..11fe6dfb01 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -35,11 +35,13 @@ #include #include +#include +#define process_title NODE_VAR(process_title) + namespace node { using namespace v8; -static char *process_title = NULL; double Platform::prog_start_time = Platform::GetUptime();