From 07e270124e7832ad81fcac715851e237f76f4c79 Mon Sep 17 00:00:00 2001 From: Dario Lombardo Date: Wed, 20 Apr 2016 17:52:32 +0200 Subject: wmem: add foreach function to wmem_list. Makes wmem_list more similar to glib lists. Change-Id: Ifadf0627791a72c4118a14f205aa1a7189894d27 Reviewed-on: https://code.wireshark.org/review/15019 Reviewed-by: Anders Broman --- epan/wmem/wmem_list.c | 12 ++++++++++++ epan/wmem/wmem_list.h | 4 ++++ epan/wmem/wmem_test.c | 13 +++++++++++++ 3 files changed, 29 insertions(+) (limited to 'epan/wmem') diff --git a/epan/wmem/wmem_list.c b/epan/wmem/wmem_list.c index 0d7ade8c33..8422ed86c9 100644 --- a/epan/wmem/wmem_list.c +++ b/epan/wmem/wmem_list.c @@ -200,6 +200,18 @@ wmem_destroy_list(wmem_list_t *list) wmem_free(list->allocator, list); } +void +wmem_list_foreach(wmem_list_t *list, GFunc foreach_func, gpointer user_data) +{ + wmem_list_frame_t *cur; + + cur = list->head; + + while (cur) { + foreach_func(cur->data, user_data); + cur = cur->next; + } +} /* * Editor modelines - http://www.wireshark.org/tools/modelines.html * diff --git a/epan/wmem/wmem_list.h b/epan/wmem/wmem_list.h index bc4bba0811..d48b3fd74c 100644 --- a/epan/wmem/wmem_list.h +++ b/epan/wmem/wmem_list.h @@ -100,6 +100,10 @@ wmem_list_t * wmem_list_new(wmem_allocator_t *allocator) G_GNUC_MALLOC; +WS_DLL_PUBLIC +void +wmem_list_foreach(wmem_list_t *list, GFunc foreach_func, gpointer user_data); + WS_DLL_PUBLIC void wmem_destroy_list(wmem_list_t *list); diff --git a/epan/wmem/wmem_test.c b/epan/wmem/wmem_test.c index 983f2f19dd..c5d6cc2f70 100644 --- a/epan/wmem/wmem_test.c +++ b/epan/wmem/wmem_test.c @@ -548,6 +548,12 @@ wmem_test_array(void) wmem_destroy_allocator(allocator); } +static void +checkval(gpointer val, gpointer val_to_check) +{ + g_assert(val == val_to_check); +} + static void wmem_test_list(void) { @@ -635,6 +641,13 @@ wmem_test_list(void) } g_assert(wmem_list_count(list) == CONTAINER_ITERS); wmem_destroy_list(list); + + list = wmem_list_new(NULL); + for (i=0; i