From 3377a30fb844a9804b895e20d702bbfc865fb70e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 13 Dec 2009 08:58:12 +0100 Subject: [PATCH] Move cb_persist functions out of dns module --- src/node.h | 19 +++++++++++++++++++ src/node_dns.cc | 19 +------------------ src/node_file.cc | 15 +++------------ 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/node.h b/src/node.h index fd872a0..44cf0db 100644 --- a/src/node.h +++ b/src/node.h @@ -58,5 +58,24 @@ ssize_t DecodeWrite(char *buf, v8::Local BuildStatsObject(struct stat * s); +static inline v8::Persistent* cb_persist( + const v8::Local &v) { + v8::Persistent *fn = new v8::Persistent(); + *fn = v8::Persistent::New(v8::Local::Cast(v)); + return fn; +} + +static inline v8::Persistent* cb_unwrap(void *data) { + v8::Persistent *cb = + reinterpret_cast*>(data); + assert((*cb)->IsFunction()); + return cb; +} + +static inline void cb_destroy(v8::Persistent * cb) { + cb->Dispose(); + delete cb; +} + } // namespace node #endif // SRC_NODE_H_ diff --git a/src/node_dns.cc b/src/node_dns.cc index 1dadab2..f173e7e 100644 --- a/src/node_dns.cc +++ b/src/node_dns.cc @@ -1,5 +1,6 @@ // Copyright 2009 Ryan Dahl #include +#include #include /* exit() */ #include @@ -21,24 +22,6 @@ static ev_timer timer_watcher; static Persistent errno_symbol; -static inline Persistent* cb_persist(const Local &v) { - Persistent *fn = new Persistent(); - *fn = Persistent::New(Local::Cast(v)); - return fn; -} - -static inline Persistent* cb_unwrap(void *data) { - Persistent *cb = - reinterpret_cast*>(data); - assert((*cb)->IsFunction()); - return cb; -} - -static inline void cb_destroy(Persistent * cb) { - cb->Dispose(); - delete cb; -} - static inline void set_timeout() { int maxwait = 20; int wait = dns_timeouts(NULL, maxwait, ev_now(EV_DEFAULT_UC)); diff --git a/src/node_file.cc b/src/node_file.cc index 1289064..c378cab 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -30,9 +30,7 @@ static inline Local errno_exception(int errorno) { static int After(eio_req *req) { HandleScope scope; - Persistent *callback = - reinterpret_cast*>(req->data); - assert((*callback)->IsFunction()); + Persistent *callback = cb_unwrap(req->data); ev_unref(EV_DEFAULT_UC); @@ -124,21 +122,14 @@ static int After(eio_req *req) { } // Dispose of the persistent handle - callback->Dispose(); - delete callback; + cb_destroy(callback); return 0; } -static Persistent* persistent_callback(const Local &v) { - Persistent *fn = new Persistent(); - *fn = Persistent::New(Local::Cast(v)); - return fn; -} - #define ASYNC_CALL(func, callback, ...) \ eio_req *req = eio_##func(__VA_ARGS__, EIO_PRI_DEFAULT, After, \ - persistent_callback(callback)); \ + cb_persist(callback)); \ assert(req); \ ev_ref(EV_DEFAULT_UC); \ return Undefined(); -- 2.7.4