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 */
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);
}
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());
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();
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:
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);
}
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());
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:
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;
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();
#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##_()
#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)
# 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
// 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
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());
}
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());
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();
// 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;
// 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_);