Mercurial > code
changeset 40:d741c948de89
Added a convenient macro PARRAY_FLUSH to free all objects
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 02 Oct 2011 10:59:09 +0200 |
parents | 70a7bbe96b1d |
children | 5252fa9b5cb1 |
files | array.c parray.c parray.h |
diffstat | 3 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/array.c Sun Oct 02 10:55:00 2011 +0200 +++ b/array.c Sun Oct 02 10:59:09 2011 +0200 @@ -238,8 +238,7 @@ } /* - * Reset the array, if the trash argument is set it will free the object - * too, otherwise the array is just truncated to 0 length. + * Erase every bytes and set the length to 0. */ void
--- a/parray.c Sun Oct 02 10:55:00 2011 +0200 +++ b/parray.c Sun Oct 02 10:59:09 2011 +0200 @@ -222,8 +222,7 @@ } /* - * Reset the array, if the trash argument is set it will free the object - * too, otherwise the array is just truncated to 0 length. + * Reset the array by setting each pointer to NULL and the length to 0. */ void
--- a/parray.h Sun Oct 02 10:55:00 2011 +0200 +++ b/parray.h Sun Oct 02 10:59:09 2011 +0200 @@ -67,4 +67,16 @@ for ((a)->_i = 0, var = PARRAY_INDEX((a), (a)->_i); \ (a)->_i < (a)->length; ++(a)->_i, var = PARRAY_INDEX((a), (a)->_i)) +#define PARRAY_FLUSH(a) \ +do { \ + void *i; \ + \ + PARRAY_FOREACH_R(a, i) { \ + free(i); \ + parray_unqueue((a)); \ + } \ + \ + (a)->length = 0; \ +} while (/* CONSTCOND */ 0); + #endif /* _PARRAY_H_ */