From: Alexey Zaytsev <alexey.zaytsev@xxxxxxxxx> Signed-off-by: Alexey Zaytsev <alexey.zaytsev@xxxxxxxxx> --- ptrlist.c | 30 +++++++++++++++++++++++++++--- ptrlist.h | 7 +++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ptrlist.c b/ptrlist.c index 2620412..fb6b6db 100644 --- a/ptrlist.c +++ b/ptrlist.c @@ -12,9 +12,33 @@ #include "ptrlist.h" #include "allocate.h" #include "compat.h" +#include "lib.h" +#include "serialization.h" + +static int ptr_list_serializer(struct serialization_stream *s, struct ptr_list *w) +{ + die("Don't serialize abstract ptr lists, serialize your custom ones."); + return 0; +} + +__DECLARE_ALLOCATOR(struct ptr_list, ptr_list_core); +__ALLOCATOR(struct ptr_list, "ptr list", ptr_list_core); +DO_WRAP(struct ptr_list, ptr_list, "ptrlist.h", __alloc_ptr_list_core, + __alloc_ptrlist, __free_ptr_list_core, __free_ptrlist, + ptr_list_serializer); + + +struct ptr_list *fail_ptrlist_allocation(int i) +{ + die("Don't try to allocate ptr_list instances directly, use __add_ptr_list instead."); + return NULL; +} + +void fail_ptrlist_free(void *p) +{ + die("Don't free ptr list instances directly, use free_ptr_list instead."); +} -__DECLARE_ALLOCATOR(struct ptr_list, ptrlist); -__ALLOCATOR(struct ptr_list, "ptr list", ptrlist); int ptr_list_size(struct ptr_list *head) { @@ -95,7 +119,7 @@ restart: entry = next; } while (entry != head); } -} +} void split_ptr_list_head(struct ptr_list *head) { diff --git a/ptrlist.h b/ptrlist.h index fe43de1..1a16819 100644 --- a/ptrlist.h +++ b/ptrlist.h @@ -7,6 +7,8 @@ * (C) Copyright Linus Torvalds 2003-2005 */ +#include "serialization.h" + #define container(ptr, type, member) \ (type *)((void *)(ptr) - offsetof(type, member)) @@ -32,6 +34,8 @@ struct ptr_list { void *list[LIST_NODE_NR]; }; +DO_DECLARE_WRAPPER(struct ptr_list, ptr_list, __alloc_ptrlist, __free_ptrlist); + #define ptr_list_empty(x) ((x) == NULL) void * undo_ptr_list_last(struct ptr_list **head); @@ -46,6 +50,9 @@ extern void __free_ptr_list(struct ptr_list **); extern int ptr_list_size(struct ptr_list *); extern int linearize_ptr_list(struct ptr_list *, void **, int); +/* To be used by custom ptr list serializers. */ +struct ptr_list *fail_ptrlist_allocation(int); +void fail_ptrlist_free(void *); /* * Hey, who said that you can't do overloading in C? * -- 1.5.6.3 -- 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