From 8efe60d42351653671df9c1dc6f1dfcf2ed081d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 18 Oct 2022 11:15:57 +0200 Subject: [PATCH 1/2] Add ISC_{LIST,LINK}_INITIALIZER for designated initializers Since we are using designated initializers, we were missing initializers for ISC_LIST and ISC_LINK, add them, so you can do *foo = (foo_t){ .list = ISC_LIST_INITIALIZER }; Instead of: *foo = (foo_t){ 0 }; ISC_LIST_INIT(foo->list); (cherry picked from commit cb3c36b8bf926e208b9817926d40cf7956f34b67) --- lib/isc/include/isc/list.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/isc/include/isc/list.h b/lib/isc/include/isc/list.h index b7a783c3ad..007cec0f30 100644 --- a/lib/isc/include/isc/list.h +++ b/lib/isc/include/isc/list.h @@ -15,6 +15,16 @@ #include +#define ISC_LIST_INITIALIZER \ + { \ + .head = NULL, .tail = NULL, \ + } +#define ISC_LINK_INITIALIZER_TYPE(type) \ + { \ + .prev = (type *)-1, .next = (type *)-1, \ + } +#define ISC_LINK_INITIALIZER ISC_LINK_INITIALIZER_TYPE(void) + #ifdef ISC_LIST_CHECKINIT #define ISC_LINK_INSIST(x) ISC_INSIST(x) #else /* ifdef ISC_LIST_CHECKINIT */ From 6525ebc7777ed1cacd6bc6f9190e4f0572d62bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 18 Oct 2022 11:28:03 +0200 Subject: [PATCH 2/2] Replace (void *)-1 with ISC_LINK_TOMBSTONE Instead of having "arbitrary" (void *)-1 to define non-linked, add a ISC_LINK_TOMBSTONE(type) macro that replaces the "magic" value with a define. (cherry picked from commit 5e20c2ccfb3a2aaad6ead581a1801e6289a00e5d) --- lib/isc/include/isc/list.h | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/isc/include/isc/list.h b/lib/isc/include/isc/list.h index 007cec0f30..2cf4437542 100644 --- a/lib/isc/include/isc/list.h +++ b/lib/isc/include/isc/list.h @@ -15,13 +15,16 @@ #include +#define ISC_LINK_TOMBSTONE(type) ((type *)-1) + #define ISC_LIST_INITIALIZER \ { \ .head = NULL, .tail = NULL, \ } -#define ISC_LINK_INITIALIZER_TYPE(type) \ - { \ - .prev = (type *)-1, .next = (type *)-1, \ +#define ISC_LINK_INITIALIZER_TYPE(type) \ + { \ + .prev = ISC_LINK_TOMBSTONE(type), \ + .next = ISC_LINK_TOMBSTONE(type), \ } #define ISC_LINK_INITIALIZER ISC_LINK_INITIALIZER_TYPE(void) @@ -45,13 +48,15 @@ struct { \ type *prev, *next; \ } -#define ISC_LINK_INIT_TYPE(elt, link, type) \ - do { \ - (elt)->link.prev = (type *)(-1); \ - (elt)->link.next = (type *)(-1); \ +#define ISC_LINK_INIT_TYPE(elt, link, type) \ + do { \ + (elt)->link.prev = ISC_LINK_TOMBSTONE(type); \ + (elt)->link.next = ISC_LINK_TOMBSTONE(type); \ } while (0) -#define ISC_LINK_INIT(elt, link) ISC_LINK_INIT_TYPE(elt, link, void) -#define ISC_LINK_LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1)) +#define ISC_LINK_INIT(elt, link) ISC_LINK_INIT_TYPE(elt, link, void) +#define ISC_LINK_LINKED_TYPE(elt, link, type) \ + ((type *)((elt)->link.prev) != ISC_LINK_TOMBSTONE(type)) +#define ISC_LINK_LINKED(elt, link) ISC_LINK_LINKED_TYPE(elt, link, void) #define ISC_LIST_HEAD(list) ((list).head) #define ISC_LIST_TAIL(list) ((list).tail) @@ -113,8 +118,8 @@ ISC_INSIST((list).head == (elt)); \ (list).head = (elt)->link.next; \ } \ - (elt)->link.prev = (type *)(-1); \ - (elt)->link.next = (type *)(-1); \ + (elt)->link.prev = ISC_LINK_TOMBSTONE(type); \ + (elt)->link.next = ISC_LINK_TOMBSTONE(type); \ ISC_INSIST((list).head != (elt)); \ ISC_INSIST((list).tail != (elt)); \ } while (0)