diff options
Diffstat (limited to 'lib/glcontainers.h')
-rw-r--r-- | lib/glcontainers.h | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/lib/glcontainers.h b/lib/glcontainers.h index a60bf2e3..56ae0993 100644 --- a/lib/glcontainers.h +++ b/lib/glcontainers.h @@ -30,6 +30,8 @@ #include "gl_map.h" #include "gl_set.h" +#include "mp.h" + /* These types are compatible with those required by Gnulib container * initialisation. */ @@ -48,27 +50,19 @@ gl_set_t new_string_set (gl_set_implementation_t implementation); /* Iterator macros. */ -#define GL_LIST_FOREACH_START(list, item) \ - do { \ - gl_list_iterator_t list##_iter = gl_list_iterator (list); \ - gl_list_node_t list##_node; \ - while (gl_list_iterator_next (&list##_iter, \ - (const void **) &item, \ - &list##_node)) - -#define GL_LIST_FOREACH_END(list) \ - gl_list_iterator_free (&list##_iter); \ - } while (0) - -#define GL_MAP_FOREACH_START(map, key, value) \ - do { \ - gl_map_iterator_t map##_iter = gl_map_iterator (map); \ - while (gl_map_iterator_next (&map##_iter, \ - (const void **) &key, \ - (const void **) &value)) +#define GL_LIST_FOREACH(list, item) \ + MPP_DECLARE (1, gl_list_iterator_t list##_iter = gl_list_iterator (list)) \ + MPP_DECLARE (2, gl_list_node_t list##_node) \ + MPP_WHILE (3, gl_list_iterator_next (&list##_iter, \ + (const void **) &item, \ + &list##_node)) \ + MPP_FINALLY (4, gl_list_iterator_free (&list##_iter)) -#define GL_MAP_FOREACH_END(map) \ - gl_map_iterator_free (&map##_iter); \ - } while (0) +#define GL_MAP_FOREACH(map, key, value) \ + MPP_DECLARE (1, gl_map_iterator_t map##_iter = gl_map_iterator (map)) \ + MPP_WHILE (2, gl_map_iterator_next (&map##_iter, \ + (const void **) &key, \ + (const void **) &value)) \ + MPP_FINALLY (3, gl_map_iterator_free (&map##_iter)) #endif /* MAN_GLCONTAINERS_H */ |