From 9a54f33be82bd5b6136117bb3a8a37e2431e7544 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 28 Sep 2006 12:36:41 +0000 Subject: [PATCH] Make list_entry, hash_entry more type-safe. Suggestion from Godmar Back. --- src/lib/kernel/hash.h | 5 +++-- src/lib/kernel/list.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/kernel/hash.h b/src/lib/kernel/hash.h index 3f2e43c..db9f674 100644 --- a/src/lib/kernel/hash.h +++ b/src/lib/kernel/hash.h @@ -36,8 +36,9 @@ struct hash_elem name of the outer structure STRUCT and the member name MEMBER of the hash element. See the big comment at the top of the file for an example. */ -#define hash_entry(HASH_ELEM, STRUCT, MEMBER) \ - ((STRUCT *) ((uint8_t *) (HASH_ELEM) - offsetof (STRUCT, MEMBER))) +#define hash_entry(HASH_ELEM, STRUCT, MEMBER) \ + ((STRUCT *) ((uint8_t *) &(HASH_ELEM)->list_elem \ + - offsetof (STRUCT, MEMBER.list_elem))) /* Computes and returns the hash value for hash element E, given auxiliary data AUX. */ diff --git a/src/lib/kernel/list.h b/src/lib/kernel/list.h index a041299..2388f9a 100644 --- a/src/lib/kernel/list.h +++ b/src/lib/kernel/list.h @@ -105,8 +105,9 @@ struct list name of the outer structure STRUCT and the member name MEMBER of the list element. See the big comment at the top of the file for an example. */ -#define list_entry(LIST_ELEM, STRUCT, MEMBER) \ - ((STRUCT *) ((uint8_t *) (LIST_ELEM) - offsetof (STRUCT, MEMBER))) +#define list_entry(LIST_ELEM, STRUCT, MEMBER) \ + ((STRUCT *) ((uint8_t *) &(LIST_ELEM)->next \ + - offsetof (STRUCT, MEMBER.next))) void list_init (struct list *); -- 2.30.2