Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
queue: strengthen type checks
Browse files Browse the repository at this point in the history
Rewrite some of the macros in a way that:

  a) makes them more likely to trigger compile-time errors if used
     inappropriately, and

  b) makes C++ compilers happy
  • Loading branch information
bnoordhuis committed Nov 2, 2013
1 parent 3c172ea commit 0520464
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
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)))
#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0]))
#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1]))
#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q)))
#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q)))

/* Public macros. */
#define QUEUE_DATA(ptr, type, field) \
((type *) ((char *) (ptr) - ((char *) &((type *) 0)->field)))

#define QUEUE_FOREACH(q, h) \
for ((q) = (QUEUE *) (*(h))[0]; (q) != (h); (q) = (QUEUE *) (*(q))[0])
for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q))

#define QUEUE_EMPTY(q) \
(QUEUE_NEXT(q) == (q))
((const QUEUE *) (q) == (const QUEUE *) QUEUE_NEXT(q))

#define QUEUE_HEAD(q) \
(QUEUE_NEXT(q))
Expand Down

0 comments on commit 0520464

Please sign in to comment.