aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lib/queue.h
diff options
context:
space:
mode:
authorerw7 <erw7.github@gmail.com>2019-10-16 16:23:07 +0200
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-03-30 21:55:50 -0400
commit36caafeb281bf872f11d475e594eb212636daa4d (patch)
tree11a0922ed39166ab9fa54249d03fd8d6244a78ce /src/nvim/lib/queue.h
parent4c76b1e981f072229944a22e5d5ee76fe42d994a (diff)
downloadrneovim-36caafeb281bf872f11d475e594eb212636daa4d.tar.gz
rneovim-36caafeb281bf872f11d475e594eb212636daa4d.tar.bz2
rneovim-36caafeb281bf872f11d475e594eb212636daa4d.zip
Change QUEUE_FOREACH macro to use while instead of for
Diffstat (limited to 'src/nvim/lib/queue.h')
-rw-r--r--src/nvim/lib/queue.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/nvim/lib/queue.h b/src/nvim/lib/queue.h
index ab9270081e..452998a5a4 100644
--- a/src/nvim/lib/queue.h
+++ b/src/nvim/lib/queue.h
@@ -33,11 +33,17 @@ typedef struct _queue {
#define QUEUE_DATA(ptr, type, field) \
((type *)((char *)(ptr) - offsetof(type, field)))
-// Important note: mutating the list while QUEUE_FOREACH is
-// iterating over its elements results in undefined behavior.
-#define QUEUE_FOREACH(q, h) \
- for ( /* NOLINT(readability/braces) */ \
- (q) = (h)->next; (q) != (h); (q) = (q)->next)
+// Important note: the node currently being processed can be safely deleted.
+// otherwise, mutating the list while QUEUE_FOREACH is iterating over its
+// elements results in undefined behavior.
+#define QUEUE_FOREACH(q, h, code) \
+ (q) = (h)->next; \
+ while((q) != (h)) { \
+ QUEUE *next = q->next; \
+ code \
+ (q) = next; \
+ }
+
// ffi.cdef is unable to swallow `bool` in place of `int` here.
static inline int QUEUE_EMPTY(const QUEUE *const q)