From: Florent Bruneau Date: Fri, 12 Sep 2008 20:37:14 +0000 (+0200) Subject: Add the A() macro to get the array type. X-Git-Url: http://git.madism.org/?p=apps%2Fpfixtools.git;a=commitdiff_plain;h=00bae73b4873e9c1e8d5526feecdb275f7bb756f;hp=d66ec885e2c3680b1b42e5cf99b18865c6c1736c Add the A() macro to get the array type. Signed-off-by: Florent Bruneau --- diff --git a/common/array.h b/common/array.h index b85fc50..04a632b 100644 --- a/common/array.h +++ b/common/array.h @@ -60,6 +60,7 @@ p_delete(array); \ } \ } +#define A(Type) Type ## _array_t #define ARRAY_INIT { NULL, 0, 0 } @@ -107,6 +108,16 @@ #define array_elt(array, n) (array).data[(n)] #define array_ptr(array, n) (array).data + (n) +#define array_foreach(array, action) \ + for (int __Ai = 0 ; __Ai < (array).len ; ++__Ai) { \ + action(array_ptr(array, __Ai)); \ + } +#define array_deep_wipe(array, wipe) \ + do { \ + array_foreach(array, wipe); \ + array_wipe(array); \ + } while (0) + ARRAY(char) ARRAY(int) diff --git a/common/buffer.h b/common/buffer.h index d044114..a1a96ec 100644 --- a/common/buffer.h +++ b/common/buffer.h @@ -41,7 +41,7 @@ #include "str.h" #include "array.h" -typedef char_array_t buffer_t; +typedef A(char) buffer_t; #define BUFFER_INIT {NULL, 0, 0} diff --git a/common/trie.c b/common/trie.c index 9ffa9b5..5bf18ec 100644 --- a/common/trie.c +++ b/common/trie.c @@ -52,10 +52,10 @@ struct trie_entry_t { ARRAY(trie_entry_t) struct trie_t { - trie_entry_t_array_t entries; - char_array_t c; - char_array_t keys; - int_array_t keys_offset; + A(trie_entry_t) entries; + A(char) c; + A(char) keys; + A(int) keys_offset; bool locked; };