From 0619467bd349af64c89ac0c325e8663026364bbf Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 8 Nov 2013 21:44:32 +0100 Subject: [PATCH] src: remove container_of, use CONTAINER_OF CONTAINER_OF was introduced a while ago but was not used consistently everywhere yet. This commit fixes that. Why CONTAINER_OF instead of container_of? The former makes it crystal clear that it's a macro, not a function. --- src/cares_wrap.cc | 4 ++-- src/node.cc | 4 ++-- src/node_crypto.cc | 12 ++++++------ src/node_http_parser.cc | 4 ++-- src/node_internals.h | 14 -------------- src/node_zlib.cc | 4 ++-- src/signal_wrap.cc | 2 +- src/stream_wrap.cc | 2 +- src/tls_wrap.cc | 4 ++-- 9 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 382516f..7758749 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -88,7 +88,7 @@ static void ares_timeout(uv_timer_t* handle, int status) { static void ares_poll_cb(uv_poll_t* watcher, int status, int events) { - ares_task_t* task = container_of(watcher, ares_task_t, poll_watcher); + ares_task_t* task = CONTAINER_OF(watcher, ares_task_t, poll_watcher); Environment* env = task->env; /* Reset the idle timer */ @@ -109,7 +109,7 @@ static void ares_poll_cb(uv_poll_t* watcher, int status, int events) { static void ares_poll_close_cb(uv_handle_t* watcher) { - ares_task_t* task = container_of(watcher, ares_task_t, poll_watcher); + ares_task_t* task = CONTAINER_OF(watcher, ares_task_t, poll_watcher); free(task); } diff --git a/src/node.cc b/src/node.cc index 77ce5e1..f21aac6 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1249,7 +1249,7 @@ static void GetActiveRequests(const FunctionCallbackInfo& args) { int i = 0; QUEUE_FOREACH(q, &req_wrap_queue) { - ReqWrap* w = container_of(q, ReqWrap, req_wrap_queue_); + ReqWrap* w = CONTAINER_OF(q, ReqWrap, req_wrap_queue_); if (w->persistent().IsEmpty()) continue; ary->Set(i++, w->object()); @@ -1271,7 +1271,7 @@ void GetActiveHandles(const FunctionCallbackInfo& args) { Local owner_sym = FIXED_ONE_BYTE_STRING(node_isolate, "owner"); QUEUE_FOREACH(q, &handle_wrap_queue) { - HandleWrap* w = container_of(q, HandleWrap, handle_wrap_queue_); + HandleWrap* w = CONTAINER_OF(q, HandleWrap, handle_wrap_queue_); if (w->persistent().IsEmpty() || (w->flags_ & HandleWrap::kUnref)) continue; Local object = w->object(); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 3bc5505..48d8154 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -3382,7 +3382,7 @@ class PBKDF2Request : public AsyncWrap { error_ = err; } - // TODO(trevnorris): Make private and make work with container_of macro. + // TODO(trevnorris): Make private and make work with CONTAINER_OF macro. uv_work_t work_req_; private: @@ -3412,7 +3412,7 @@ void EIO_PBKDF2(PBKDF2Request* req) { void EIO_PBKDF2(uv_work_t* work_req) { - PBKDF2Request* req = container_of(work_req, PBKDF2Request, work_req_); + PBKDF2Request* req = CONTAINER_OF(work_req, PBKDF2Request, work_req_); EIO_PBKDF2(req); } @@ -3432,7 +3432,7 @@ void EIO_PBKDF2After(PBKDF2Request* req, Local argv[2]) { void EIO_PBKDF2After(uv_work_t* work_req, int status) { assert(status == 0); - PBKDF2Request* req = container_of(work_req, PBKDF2Request, work_req_); + PBKDF2Request* req = CONTAINER_OF(work_req, PBKDF2Request, work_req_); Environment* env = req->env(); Context::Scope context_scope(env->context()); HandleScope handle_scope(env->isolate()); @@ -3590,7 +3590,7 @@ class RandomBytesRequest : public AsyncWrap { error_ = err; } - // TODO(trevnorris): Make private and make work with container_of macro. + // TODO(trevnorris): Make private and make work with CONTAINER_OF macro. uv_work_t work_req_; private: @@ -3602,7 +3602,7 @@ class RandomBytesRequest : public AsyncWrap { template void RandomBytesWork(uv_work_t* work_req) { - RandomBytesRequest* req = container_of(work_req, + RandomBytesRequest* req = CONTAINER_OF(work_req, RandomBytesRequest, work_req_); int r; @@ -3647,7 +3647,7 @@ void RandomBytesCheck(RandomBytesRequest* req, Local argv[2]) { void RandomBytesAfter(uv_work_t* work_req, int status) { assert(status == 0); - RandomBytesRequest* req = container_of(work_req, + RandomBytesRequest* req = CONTAINER_OF(work_req, RandomBytesRequest, work_req_); Environment* env = req->env(); diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 10378ee..1295701 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -77,7 +77,7 @@ const uint32_t kOnMessageComplete = 3; #define HTTP_CB(name) \ static int name(http_parser* p_) { \ - Parser* self = container_of(p_, Parser, parser_); \ + Parser* self = CONTAINER_OF(p_, Parser, parser_); \ return self->name##_(); \ } \ int name##_() @@ -85,7 +85,7 @@ const uint32_t kOnMessageComplete = 3; #define HTTP_DATA_CB(name) \ static int name(http_parser* p_, const char* at, size_t length) { \ - Parser* self = container_of(p_, Parser, parser_); \ + Parser* self = CONTAINER_OF(p_, Parser, parser_); \ return self->name##_(at, length); \ } \ int name##_(const char* at, size_t length) diff --git a/src/node_internals.h b/src/node_internals.h index 84c523b..e92aa2e 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -104,20 +104,6 @@ inline static int snprintf(char* buf, unsigned int len, const char* fmt, ...) { # define BITS_PER_LONG 32 #endif -#ifndef offset_of -// g++ in strict mode complains loudly about the system offsetof() macro -// because it uses NULL as the base address. -# define offset_of(type, member) \ - (reinterpret_cast( \ - reinterpret_cast(&(reinterpret_cast(8)->member)) - 8)) -#endif - -#ifndef container_of -# define container_of(ptr, type, member) \ - (reinterpret_cast(reinterpret_cast(ptr) - \ - offset_of(type, member))) -#endif - #ifndef ARRAY_SIZE # define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) #endif diff --git a/src/node_zlib.cc b/src/node_zlib.cc index aed93fe..5360b7a 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -203,7 +203,7 @@ class ZCtx : public WeakObject { // for a single write() call, until all of the input bytes have // been consumed. static void Process(uv_work_t* work_req) { - ZCtx *ctx = container_of(work_req, ZCtx, work_req_); + ZCtx *ctx = CONTAINER_OF(work_req, ZCtx, work_req_); // If the avail_out is left at 0, then it means that it ran out // of room. If there was avail_out left over, then it means @@ -252,7 +252,7 @@ class ZCtx : public WeakObject { static void After(uv_work_t* work_req, int status) { assert(status == 0); - ZCtx* ctx = container_of(work_req, ZCtx, work_req_); + ZCtx* ctx = CONTAINER_OF(work_req, ZCtx, work_req_); Environment* env = ctx->env(); Context::Scope context_scope(env->context()); diff --git a/src/signal_wrap.cc b/src/signal_wrap.cc index b0f1619..b38ca38 100644 --- a/src/signal_wrap.cc +++ b/src/signal_wrap.cc @@ -98,7 +98,7 @@ class SignalWrap : public HandleWrap { } static void OnSignal(uv_signal_t* handle, int signum) { - SignalWrap* wrap = container_of(handle, SignalWrap, handle_); + SignalWrap* wrap = CONTAINER_OF(handle, SignalWrap, handle_); Environment* env = wrap->env(); Context::Scope context_scope(env->context()); HandleScope handle_scope(env->isolate()); diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 89c1a3e..507819e 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -429,7 +429,7 @@ void StreamWrap::WriteUcs2String(const FunctionCallbackInfo& args) { void StreamWrap::AfterWrite(uv_write_t* req, int status) { - WriteWrap* req_wrap = container_of(req, WriteWrap, req_); + WriteWrap* req_wrap = CONTAINER_OF(req, WriteWrap, req_); StreamWrap* wrap = req_wrap->wrap(); Environment* env = wrap->env(); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 8575881..a18b6c1 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -118,7 +118,7 @@ void TLSCallbacks::InvokeQueued(int status) { // Process old queue while (q != &write_item_queue_) { QUEUE* next = static_cast(QUEUE_NEXT(q)); - WriteItem* wi = container_of(q, WriteItem, member_); + WriteItem* wi = CONTAINER_OF(q, WriteItem, member_); wi->cb_(&wi->w_->req_, status); delete wi; q = next; @@ -268,7 +268,7 @@ void TLSCallbacks::EncOut() { // Split-off queue if (established_ && !QUEUE_EMPTY(&write_item_queue_)) { - pending_write_item_ = container_of(QUEUE_NEXT(&write_item_queue_), + pending_write_item_ = CONTAINER_OF(QUEUE_NEXT(&write_item_queue_), WriteItem, member_); QUEUE_INIT(&write_item_queue_); -- 2.7.4