[PATCH 01/13] ptrlist: let all pointer lists have the same parametrized structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, all pointer lists have the same concrete structure,
struct ptr_list, which is also used as a generic pointer list.
But they're each declared with a phony type which just allows
to get back the type of the pointer:
	struct <name> { <TYPE> list[0]; };
vs.
	struct ptr_list {
		....
		void * list[NR];
	};

Since the declaration doesn't match the real representation
every operation done on pointer lists must cast forth & back the
list pointer to the generic type. OTOH, type safety is assured
by phony extra statements which are NOP but would produce warnings
if, for example, the type of the list doesn't correspond to
the element to be stored or retrieved.

This patch and the following ones takes another approach where
all pointer lists are declared *and* defined to essentially the
same structure but kinda parametrized with the type of the pointers
to be stored in the list. This has the advantage that most operations
are done on the real types and thus to eliminate all the type checking
statements and most of the casts (the ones remaining are the ones
needed to interface with the generic type used for the functionalities
implemented as functions).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 ptrlist.h | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/ptrlist.h b/ptrlist.h
index e3a84ea0a..6cec720e0 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -10,7 +10,6 @@
  */
 
 /* Silly type-safety check ;) */
-#define DECLARE_PTR_LIST(listname,type)	struct listname { type *list[1]; }
 #define CHECK_TYPE(head,ptr)		(void)(&(ptr) == &(head)->list[0])
 #define TYPEOF(head)			__typeof__(&(head)->list[0])
 #define VRFY_PTR_LIST(head)		(void)(sizeof((head)->list[0]))
@@ -24,13 +23,16 @@
 
 #define LIST_NODE_NR (13)
 
-struct ptr_list {
-	int nr:8;
-	int rm:8;
-	struct ptr_list *prev;
-	struct ptr_list *next;
-	void *list[LIST_NODE_NR];
-};
+#define DECLARE_PTR_LIST(listname, type)	\
+	struct listname {			\
+		int nr:8;			\
+		int rm:8;			\
+		struct listname *prev;		\
+		struct listname *next;		\
+		type *list[LIST_NODE_NR];	\
+	}
+
+DECLARE_PTR_LIST(ptr_list, void);
 
 #define ptr_list_empty(x) ((x) == NULL)
 
-- 
2.17.1

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux