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

Commit 0520464

Browse files
committed
queue: strengthen type checks
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
1 parent 3c172ea commit 0520464

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/queue.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
typedef void *QUEUE[2];
2020

2121
/* Private macros. */
22-
#define QUEUE_NEXT(q) ((*(q))[0])
23-
#define QUEUE_PREV(q) ((*(q))[1])
24-
#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT((QUEUE *) QUEUE_PREV(q)))
25-
#define QUEUE_NEXT_PREV(q) (QUEUE_PREV((QUEUE *) QUEUE_NEXT(q)))
22+
#define QUEUE_NEXT(q) (*(QUEUE **) &((*(q))[0]))
23+
#define QUEUE_PREV(q) (*(QUEUE **) &((*(q))[1]))
24+
#define QUEUE_PREV_NEXT(q) (QUEUE_NEXT(QUEUE_PREV(q)))
25+
#define QUEUE_NEXT_PREV(q) (QUEUE_PREV(QUEUE_NEXT(q)))
2626

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

3131
#define QUEUE_FOREACH(q, h) \
32-
for ((q) = (QUEUE *) (*(h))[0]; (q) != (h); (q) = (QUEUE *) (*(q))[0])
32+
for ((q) = QUEUE_NEXT(h); (q) != (h); (q) = QUEUE_NEXT(q))
3333

3434
#define QUEUE_EMPTY(q) \
35-
(QUEUE_NEXT(q) == (q))
35+
((const QUEUE *) (q) == (const QUEUE *) QUEUE_NEXT(q))
3636

3737
#define QUEUE_HEAD(q) \
3838
(QUEUE_NEXT(q))

0 commit comments

Comments
 (0)