diff options
author | Dario Lombardo <lomato@gmail.com> | 2016-04-20 17:52:32 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-04-20 21:11:49 +0000 |
commit | 07e270124e7832ad81fcac715851e237f76f4c79 (patch) | |
tree | 0f58b62e25b5fb953323688c2fa062810b5c1b5b /epan/wmem | |
parent | d37734256c77ae99cb1cc93a4d2d1959584109a6 (diff) |
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 <a.broman58@gmail.com>
Diffstat (limited to 'epan/wmem')
-rw-r--r-- | epan/wmem/wmem_list.c | 12 | ||||
-rw-r--r-- | epan/wmem/wmem_list.h | 4 | ||||
-rw-r--r-- | epan/wmem/wmem_test.c | 13 |
3 files changed, 29 insertions, 0 deletions
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 @@ -102,6 +102,10 @@ 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 @@ -549,6 +549,12 @@ wmem_test_array(void) } static void +checkval(gpointer val, gpointer val_to_check) +{ + g_assert(val == val_to_check); +} + +static void wmem_test_list(void) { wmem_allocator_t *allocator; @@ -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<CONTAINER_ITERS; i++) { + wmem_list_append(list, GINT_TO_POINTER(1)); + } + wmem_list_foreach(list, checkval, GINT_TO_POINTER(1)); + wmem_destroy_list(list); } static void |