aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-12-15 00:12:41 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-12-27 12:01:46 +0100
commitda9b52ecbc38916b3c58b68a9a98f94c6fc8c438 (patch)
tree8bc9758b52c00b861ad01f4a37e603cdadb19e05
parent1b896707d95982c7c9cdd5cd0ab4afd80f766a94 (diff)
downloadsparse-da9b52ecbc38916b3c58b68a9a98f94c6fc8c438.tar.gz
ptrlist: avoid mixing reverse and non-reverse macros
The macros used to iterate the ptrlists exist in two kinds: those to iterate forward direction and those to iterate in the reverse direction. Those macros must be used in pair: one for the top of the loop and one at the end of the loop. However, if we mix them, for example like: FOR_EACH_PTR(list, var) { ... } FOR_EACH_PTR_REVERSE(var); things will still work for lists with a single block (most of them) but will behave strangely and of course wrongly when reaching the next block. So, to avoid future debugging fun, add a unused variable, discarded at compile time, but with distinct prefix for each direction. This way, mixing the macros will create a warning at compile time. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--ptrlist.h29
1 files changed, 17 insertions, 12 deletions
diff --git a/ptrlist.h b/ptrlist.h
index 2411e745..4bf8c709 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -89,27 +89,27 @@ extern void __free_ptr_list(struct ptr_list **);
DO_FINISH(ptr, __head##ptr, __list##ptr, __nr##ptr)
#define RECURSE_PTR_REVERSE(ptr, new) \
- DO_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr, \
+ DO_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr, __rname##new, \
new, __head##new, __list##new, __nr##new, PTR_ENTRY_UNTAG)
#define FOR_EACH_PTR(head, ptr) \
- DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_NOTAG)
+ DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, __name##ptr, PTR_ENTRY_NOTAG)
#define FOR_EACH_PTR_TAG(head, ptr) \
- DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_UNTAG)
+ DO_FOR_EACH(head, ptr, __head##ptr, __list##ptr, __nr##ptr, __name##ptr, PTR_ENTRY_UNTAG)
#define END_FOR_EACH_PTR(ptr) \
- DO_END_FOR_EACH(ptr, __head##ptr, __list##ptr, __nr##ptr)
+ DO_END_FOR_EACH(ptr, __head##ptr, __list##ptr, __nr##ptr, __name##ptr)
#define FOR_EACH_PTR_REVERSE(head, ptr) \
- DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_NOTAG)
+ DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, __rname##ptr, PTR_ENTRY_NOTAG)
#define FOR_EACH_PTR_REVERSE_TAG(head, ptr) \
- DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, PTR_ENTRY_UNTAG)
+ DO_FOR_EACH_REVERSE(head, ptr, __head##ptr, __list##ptr, __nr##ptr, __rname##ptr, PTR_ENTRY_UNTAG)
#define END_FOR_EACH_PTR_REVERSE(ptr) \
- DO_END_FOR_EACH_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr)
+ DO_END_FOR_EACH_REVERSE(ptr, __head##ptr, __list##ptr, __nr##ptr, __rname##ptr)
#define THIS_ADDRESS(ptr) \
DO_THIS_ADDRESS(ptr, __head##ptr, __list##ptr, __nr##ptr)
@@ -184,9 +184,10 @@ extern void __free_ptr_list(struct ptr_list **);
VRFY_PTR_LIST(__head); /* Sanity-check nesting */ \
} while (0)
-#define DO_FOR_EACH(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \
+#define DO_FOR_EACH(head, ptr, __head, __list, __nr, __name, PTR_ENTRY) do { \
__typeof__(head) __head = (head); \
__typeof__(head) __list = __head; \
+ __typeof__(head) __name = __head; \
int __nr; \
if (!__head) \
break; \
@@ -196,14 +197,16 @@ extern void __free_ptr_list(struct ptr_list **);
if (__list->rm && !ptr) \
continue; \
-#define DO_END_FOR_EACH(ptr, __head, __list, __nr) \
+#define DO_END_FOR_EACH(ptr, __head, __list, __nr, __name) \
} \
} while ((__list = __list->next) != __head); \
+ (void) __name; \
} while (0)
-#define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do { \
+#define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, __name, PTR_ENTRY) do { \
__typeof__(head) __head = (head); \
__typeof__(head) __list = __head; \
+ __typeof__(head) __name = __head; \
int __nr; \
if (!head) \
break; \
@@ -216,15 +219,17 @@ extern void __free_ptr_list(struct ptr_list **);
continue; \
-#define DO_END_FOR_EACH_REVERSE(ptr, __head, __list, __nr) \
+#define DO_END_FOR_EACH_REVERSE(ptr, __head, __list, __nr, __name) \
} \
} while (__list != __head); \
+ (void) __name; \
} while (0)
-#define DO_REVERSE(ptr, __head, __list, __nr, new, __newhead, \
+#define DO_REVERSE(ptr, __head, __list, __nr, __name, new, __newhead, \
__newlist, __newnr, PTR_ENTRY) do { \
__typeof__(__head) __newhead = __head; \
__typeof__(__head) __newlist = __list; \
+ __typeof__(__head) __name = __list; \
int __newnr = __nr; \
new = ptr; \
goto __inside##new; \