Browse Source

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.
v0.11.9-release
Ben Noordhuis 11 years ago
parent
commit
0619467bd3
  1. 4
      src/cares_wrap.cc
  2. 4
      src/node.cc
  3. 12
      src/node_crypto.cc
  4. 4
      src/node_http_parser.cc
  5. 14
      src/node_internals.h
  6. 4
      src/node_zlib.cc
  7. 2
      src/signal_wrap.cc
  8. 2
      src/stream_wrap.cc
  9. 4
      src/tls_wrap.cc

4
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);
}

4
src/node.cc

@ -1249,7 +1249,7 @@ static void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
int i = 0;
QUEUE_FOREACH(q, &req_wrap_queue) {
ReqWrap<uv_req_t>* w = container_of(q, ReqWrap<uv_req_t>, req_wrap_queue_);
ReqWrap<uv_req_t>* w = CONTAINER_OF(q, ReqWrap<uv_req_t>, req_wrap_queue_);
if (w->persistent().IsEmpty())
continue;
ary->Set(i++, w->object());
@ -1271,7 +1271,7 @@ void GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
Local<String> 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> object = w->object();

12
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<Value> 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 <bool pseudoRandom>
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<Value> 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();

4
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)

14
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<intptr_t>( \
reinterpret_cast<char*>(&(reinterpret_cast<type*>(8)->member)) - 8))
#endif
#ifndef container_of
# define container_of(ptr, type, member) \
(reinterpret_cast<type*>(reinterpret_cast<char*>(ptr) - \
offset_of(type, member)))
#endif
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
#endif

4
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());

2
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());

2
src/stream_wrap.cc

@ -429,7 +429,7 @@ void StreamWrap::WriteUcs2String(const FunctionCallbackInfo<Value>& 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();

4
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*>(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_);

Loading…
Cancel
Save