Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
move global vars from platfrom, node_signal_watcher to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Dec 8, 2011
1 parent 59055b2 commit e10fd32
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/node_crypto.cc
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
21 changes: 11 additions & 10 deletions src/node_signal_watcher.cc
Expand Up @@ -22,26 +22,27 @@
#include <node_signal_watcher.h>
#include <assert.h>

#include <node_vars.h>
#define callback_symbol NODE_VAR(callback_symbol)
#define signal_watcher_constructor_template NODE_VAR(signal_watcher_constructor_template)

namespace node {

using namespace v8;

Persistent<FunctionTemplate> SignalWatcher::constructor_template;
static Persistent<String> callback_symbol;

void SignalWatcher::Initialize(Handle<Object> target) {
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(SignalWatcher::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("SignalWatcher"));
signal_watcher_constructor_template = Persistent<FunctionTemplate>::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");
}
Expand Down Expand Up @@ -73,7 +74,7 @@ void SignalWatcher::Callback(EV_P_ ev_signal *watcher, int revents) {

Handle<Value> SignalWatcher::New(const Arguments& args) {
if (!args.IsConstructCall()) {
return FromConstructorTemplate(constructor_template, args);
return FromConstructorTemplate(signal_watcher_constructor_template, args);
}

HandleScope scope;
Expand Down
12 changes: 12 additions & 0 deletions src/node_vars.h
Expand Up @@ -149,6 +149,7 @@ struct globals {
v8::Persistent<v8::String> callback_sym;

// node_crypto.cc
uv_rwlock_t* locks;
v8::Persistent<v8::String> subject_symbol;
v8::Persistent<v8::String> subjectaltname_symbol;
v8::Persistent<v8::String> modulus_symbol;
Expand All @@ -167,6 +168,17 @@ struct globals {
v8::Persistent<v8::String> chars_written_sym;
v8::Persistent<v8::String> write_sym;
v8::Persistent<v8::FunctionTemplate> buffer_constructor_template;

// platform*.cc
char* process_title;
struct {
char *str;
size_t len;
} linux_process_title;

// node_signal_watcher.cc
v8::Persistent<v8::String> callback_symbol;
v8::Persistent<v8::FunctionTemplate> signal_watcher_constructor_template;
};

struct globals* globals_get();
Expand Down
3 changes: 2 additions & 1 deletion src/platform_darwin.cc
Expand Up @@ -39,13 +39,14 @@
#include <arpa/inet.h>
#include <ifaddrs.h>

#include <node_vars.h>
#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[]) {
Expand Down
4 changes: 3 additions & 1 deletion src/platform_freebsd.cc
Expand Up @@ -37,12 +37,14 @@
#include <unistd.h>
#include <time.h>

#include <node_vars.h>
#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[]) {
Expand Down
34 changes: 16 additions & 18 deletions src/platform_linux.cc
Expand Up @@ -48,20 +48,18 @@
# include <sys/sysinfo.h>
#endif

#include <node_vars.h>
#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;
Expand All @@ -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]);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion src/platform_win32.cc
Expand Up @@ -35,11 +35,13 @@
#include <platform_win32.h>
#include <psapi.h>

#include <node_vars.h>
#define process_title NODE_VAR(process_title)

namespace node {

using namespace v8;

static char *process_title = NULL;
double Platform::prog_start_time = Platform::GetUptime();


Expand Down

0 comments on commit e10fd32

Please sign in to comment.