src: replace ngx-queue.h with queue.h
authorBen Noordhuis <info@bnoordhuis.nl>
Tue, 4 Jun 2013 10:21:58 +0000 (12:21 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Tue, 4 Jun 2013 10:22:03 +0000 (12:22 +0200)
No functional changes, just one less entry in the LICENSE file.

LICENSE
node.gyp
src/handle_wrap.cc
src/handle_wrap.h
src/ngx-queue.h [deleted file]
src/node.cc
src/queue.h [new file with mode: 0644]
src/req_wrap.h

diff --git a/LICENSE b/LICENSE
index 2fd8100..0dd08f2 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -431,34 +431,6 @@ maintained libraries. The externally maintained libraries used by Node are:
     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   """
 
-- src/ngx-queue.h. ngx-queue.h is taken from the nginx source tree. nginx's
-  license follows:
-  """
-    Copyright (C) 2002-2012 Igor Sysoev
-    Copyright (C) 2011,2012 Nginx, Inc.
-
-    Redistribution and use in source and binary forms, with or without
-    modification, are permitted provided that the following conditions
-    are met:
-    1. Redistributions of source code must retain the above copyright
-       notice, this list of conditions and the following disclaimer.
-    2. Redistributions in binary form must reproduce the above copyright
-       notice, this list of conditions and the following disclaimer in the
-       documentation and/or other materials provided with the distribution.
-
-    THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
-    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-    ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
-    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-    OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-    SUCH DAMAGE.
-  """
-
 - wrk is located at tools/wrk. wrk's license follows:
   """
 
index 67c8df2..a89161f 100644 (file)
--- a/node.gyp
+++ b/node.gyp
         'src/node_string.h',
         'src/node_version.h',
         'src/node_watchdog.h',
-        'src/ngx-queue.h',
         'src/pipe_wrap.h',
+        'src/queue.h',
         'src/tty_wrap.h',
         'src/tcp_wrap.h',
         'src/udp_wrap.h',
index 390f686..5de0daa 100644 (file)
@@ -20,7 +20,7 @@
 // USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "node.h"
-#include "ngx-queue.h"
+#include "queue.h"
 #include "handle_wrap.h"
 
 namespace node {
@@ -43,7 +43,7 @@ using v8::Value;
 
 
 // defined in node.cc
-extern ngx_queue_t handle_wrap_queue;
+extern QUEUE handle_wrap_queue;
 static Persistent<String> close_sym;
 
 
@@ -115,13 +115,13 @@ HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) {
   assert(object->InternalFieldCount() > 0);
   object_ = v8::Persistent<v8::Object>::New(node_isolate, object);
   object_->SetAlignedPointerInInternalField(0, this);
-  ngx_queue_insert_tail(&handle_wrap_queue, &handle_wrap_queue_);
+  QUEUE_INSERT_TAIL(&handle_wrap_queue, &handle_wrap_queue_);
 }
 
 
 HandleWrap::~HandleWrap() {
   assert(object_.IsEmpty());
-  ngx_queue_remove(&handle_wrap_queue_);
+  QUEUE_REMOVE(&handle_wrap_queue_);
 }
 
 
index d77485c..3a42148 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef HANDLE_WRAP_H_
 #define HANDLE_WRAP_H_
 
-#include "ngx-queue.h"
+#include "queue.h"
 
 namespace node {
 
@@ -70,7 +70,7 @@ class HandleWrap {
   private:
     friend v8::Handle<v8::Value> GetActiveHandles(const v8::Arguments&);
     static void OnClose(uv_handle_t* handle);
-    ngx_queue_t handle_wrap_queue_;
+    QUEUE handle_wrap_queue_;
     // Using double underscore due to handle_ member in tcp_wrap. Probably
     // tcp_wrap should rename it's member to 'handle'.
     uv_handle_t* handle__;
diff --git a/src/ngx-queue.h b/src/ngx-queue.h
deleted file mode 100644 (file)
index 7058ce4..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- */
-
-
-#ifndef NGX_QUEUE_H_INCLUDED_
-#define NGX_QUEUE_H_INCLUDED_
-
-
-typedef struct ngx_queue_s  ngx_queue_t;
-
-struct ngx_queue_s {
-    ngx_queue_t  *prev;
-    ngx_queue_t  *next;
-};
-
-
-#define ngx_queue_init(q)                                                     \
-    (q)->prev = q;                                                            \
-    (q)->next = q
-
-
-#define ngx_queue_empty(h)                                                    \
-    (h == (h)->prev)
-
-
-#define ngx_queue_insert_head(h, x)                                           \
-    (x)->next = (h)->next;                                                    \
-    (x)->next->prev = x;                                                      \
-    (x)->prev = h;                                                            \
-    (h)->next = x
-
-
-#define ngx_queue_insert_after   ngx_queue_insert_head
-
-
-#define ngx_queue_insert_tail(h, x)                                           \
-    (x)->prev = (h)->prev;                                                    \
-    (x)->prev->next = x;                                                      \
-    (x)->next = h;                                                            \
-    (h)->prev = x
-
-
-#define ngx_queue_head(h)                                                     \
-    (h)->next
-
-
-#define ngx_queue_last(h)                                                     \
-    (h)->prev
-
-
-#define ngx_queue_sentinel(h)                                                 \
-    (h)
-
-
-#define ngx_queue_next(q)                                                     \
-    (q)->next
-
-
-#define ngx_queue_prev(q)                                                     \
-    (q)->prev
-
-
-#if (NGX_DEBUG)
-
-#define ngx_queue_remove(x)                                                   \
-    (x)->next->prev = (x)->prev;                                              \
-    (x)->prev->next = (x)->next;                                              \
-    (x)->prev = NULL;                                                         \
-    (x)->next = NULL
-
-#else
-
-#define ngx_queue_remove(x)                                                   \
-    (x)->next->prev = (x)->prev;                                              \
-    (x)->prev->next = (x)->next
-
-#endif
-
-
-#define ngx_queue_split(h, q, n)                                              \
-    (n)->prev = (h)->prev;                                                    \
-    (n)->prev->next = n;                                                      \
-    (n)->next = q;                                                            \
-    (h)->prev = (q)->prev;                                                    \
-    (h)->prev->next = h;                                                      \
-    (q)->prev = n;
-
-
-#define ngx_queue_add(h, n)                                                   \
-    (h)->prev->next = (n)->next;                                              \
-    (n)->next->prev = (h)->prev;                                              \
-    (h)->prev = (n)->prev;                                                    \
-    (h)->prev->next = h;
-
-
-#define ngx_queue_data(q, type, link)                                         \
-    (type *) ((unsigned char *) q - offsetof(type, link))
-
-
-#define ngx_queue_foreach(q, h)                                               \
-    for ((q) = ngx_queue_head(h); (q) != (h); (q) = ngx_queue_next(q))
-
-
-#endif /* NGX_QUEUE_H_INCLUDED_ */
index 461ecf4..ee364bd 100644 (file)
@@ -93,8 +93,8 @@ extern char **environ;
 
 namespace node {
 
-ngx_queue_t handle_wrap_queue = { &handle_wrap_queue, &handle_wrap_queue };
-ngx_queue_t req_wrap_queue = { &req_wrap_queue, &req_wrap_queue };
+QUEUE handle_wrap_queue = { &handle_wrap_queue, &handle_wrap_queue };
+QUEUE req_wrap_queue = { &req_wrap_queue, &req_wrap_queue };
 
 // declared in req_wrap.h
 Persistent<String> process_symbol;
@@ -1249,10 +1249,10 @@ static Handle<Value> GetActiveRequests(const Arguments& args) {
   HandleScope scope(node_isolate);
 
   Local<Array> ary = Array::New();
-  ngx_queue_t* q = NULL;
+  QUEUE* q = NULL;
   int i = 0;
 
-  ngx_queue_foreach(q, &req_wrap_queue) {
+  QUEUE_FOREACH(q, &req_wrap_queue) {
     ReqWrap<uv_req_t>* w = container_of(q, ReqWrap<uv_req_t>, req_wrap_queue_);
     if (w->object_.IsEmpty()) continue;
     ary->Set(i++, w->object_);
@@ -1268,12 +1268,12 @@ Handle<Value> GetActiveHandles(const Arguments& args) {
   HandleScope scope(node_isolate);
 
   Local<Array> ary = Array::New();
-  ngx_queue_t* q = NULL;
+  QUEUE* q = NULL;
   int i = 0;
 
   Local<String> owner_sym = String::New("owner");
 
-  ngx_queue_foreach(q, &handle_wrap_queue) {
+  QUEUE_FOREACH(q, &handle_wrap_queue) {
     HandleWrap* w = container_of(q, HandleWrap, handle_wrap_queue_);
     if (w->object_.IsEmpty() || (w->flags_ & HandleWrap::kUnref)) continue;
     Local<Value> obj = w->object_->Get(owner_sym);
diff --git a/src/queue.h b/src/queue.h
new file mode 100644 (file)
index 0000000..0a3783b
--- /dev/null
@@ -0,0 +1,92 @@
+/* Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef QUEUE_H_
+#define QUEUE_H_
+
+typedef void *QUEUE[2];
+
+/* Private macros. */
+#define QUEUE_NEXT(q)       ((*(q))[0])
+#define QUEUE_PREV(q)       ((*(q))[1])
+#define QUEUE_PREV_NEXT(q)  (QUEUE_NEXT((QUEUE *) QUEUE_PREV(q)))
+#define QUEUE_NEXT_PREV(q)  (QUEUE_PREV((QUEUE *) QUEUE_NEXT(q)))
+
+/* Public macros. */
+#define QUEUE_DATA(ptr, type, field)                                          \
+  ((type *) ((char *) (ptr) - ((long) &((type *) 0)->field)))
+
+#define QUEUE_FOREACH(q, h)                                                   \
+  for ((q) = (QUEUE *) (*(h))[0]; (q) != (h); (q) = (QUEUE *) (*(q))[0])
+
+#define QUEUE_EMPTY(q)                                                        \
+  (QUEUE_NEXT(q) == (q))
+
+#define QUEUE_HEAD(q)                                                         \
+  (QUEUE_NEXT(q))
+
+#define QUEUE_INIT(q)                                                         \
+  do {                                                                        \
+    QUEUE_NEXT(q) = (q);                                                      \
+    QUEUE_PREV(q) = (q);                                                      \
+  }                                                                           \
+  while (0)
+
+#define QUEUE_ADD(h, n)                                                       \
+  do {                                                                        \
+    QUEUE_PREV_NEXT(h) = QUEUE_NEXT(n);                                       \
+    QUEUE_NEXT_PREV(n) = QUEUE_PREV(h);                                       \
+    QUEUE_PREV(h) = QUEUE_PREV(n);                                            \
+    QUEUE_PREV_NEXT(h) = (h);                                                 \
+  }                                                                           \
+  while (0)
+
+#define QUEUE_SPLIT(h, q, n)                                                  \
+  do {                                                                        \
+    QUEUE_PREV(n) = QUEUE_PREV(h);                                            \
+    QUEUE_PREV_NEXT(n) = (n);                                                 \
+    QUEUE_NEXT(n) = (q);                                                      \
+    QUEUE_PREV(h) = QUEUE_PREV(q);                                            \
+    QUEUE_PREV_NEXT(h) = (h);                                                 \
+    QUEUE_PREV(q) = (n);                                                      \
+  }                                                                           \
+  while (0)
+
+#define QUEUE_INSERT_HEAD(h, q)                                               \
+  do {                                                                        \
+    QUEUE_NEXT(q) = QUEUE_NEXT(h);                                            \
+    QUEUE_PREV(q) = (h);                                                      \
+    QUEUE_NEXT_PREV(q) = (q);                                                 \
+    QUEUE_NEXT(h) = (q);                                                      \
+  }                                                                           \
+  while (0)
+
+#define QUEUE_INSERT_TAIL(h, q)                                               \
+  do {                                                                        \
+    QUEUE_NEXT(q) = (h);                                                      \
+    QUEUE_PREV(q) = QUEUE_PREV(h);                                            \
+    QUEUE_PREV_NEXT(q) = (q);                                                 \
+    QUEUE_PREV(h) = (q);                                                      \
+  }                                                                           \
+  while (0)
+
+#define QUEUE_REMOVE(q)                                                       \
+  do {                                                                        \
+    QUEUE_PREV_NEXT(q) = QUEUE_NEXT(q);                                       \
+    QUEUE_NEXT_PREV(q) = QUEUE_PREV(q);                                       \
+  }                                                                           \
+  while (0)
+
+#endif /* QUEUE_H_ */
index 587111b..60e4184 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef REQ_WRAP_H_
 #define REQ_WRAP_H_
 
-#include "ngx-queue.h"
+#include "queue.h"
 #include "node_internals.h"
 
 namespace node {
@@ -30,7 +30,7 @@ namespace node {
 // defined in node.cc
 extern v8::Persistent<v8::String> process_symbol;
 extern v8::Persistent<v8::String> domain_symbol;
-extern ngx_queue_t req_wrap_queue;
+extern QUEUE req_wrap_queue;
 
 template <typename T>
 class ReqWrap {
@@ -51,12 +51,12 @@ class ReqWrap {
       }
     }
 
-    ngx_queue_insert_tail(&req_wrap_queue, &req_wrap_queue_);
+    QUEUE_INSERT_TAIL(&req_wrap_queue, &req_wrap_queue_);
   }
 
 
   ~ReqWrap() {
-    ngx_queue_remove(&req_wrap_queue_);
+    QUEUE_REMOVE(&req_wrap_queue_);
     // Assert that someone has called Dispatched()
     assert(req_.data == this);
     assert(!object_.IsEmpty());
@@ -70,7 +70,7 @@ class ReqWrap {
   }
 
   v8::Persistent<v8::Object> object_;
-  ngx_queue_t req_wrap_queue_;
+  QUEUE req_wrap_queue_;
   void* data_;
   T req_; // *must* be last, GetActiveRequests() in node.cc depends on it
 };