18#include "ext/siphash.h"
20#define DECLARE_MAP_FNS(mapname_t, keytype, prefix) \
21 typedef struct mapname_t mapname_t; \
22 typedef struct prefix##_entry_t *prefix##_iter_t; \
23 MOCK_DECL(mapname_t*, prefix##_new, (void)); \
24 void* prefix##_set(mapname_t *map, keytype key, void *val); \
25 void* prefix##_get(const mapname_t *map, keytype key); \
26 void* prefix##_remove(mapname_t *map, keytype key); \
27 MOCK_DECL(void, prefix##_free_, (mapname_t *map, void (*free_val)(void*))); \
28 int prefix##_isempty(const mapname_t *map); \
29 int prefix##_size(const mapname_t *map); \
30 prefix##_iter_t *prefix##_iter_init(mapname_t *map); \
31 prefix##_iter_t *prefix##_iter_next(mapname_t *map, prefix##_iter_t *iter); \
32 prefix##_iter_t *prefix##_iter_next_rmv(mapname_t *map, \
33 prefix##_iter_t *iter); \
34 void prefix##_iter_get(prefix##_iter_t *iter, keytype *keyp, void **valp); \
35 int prefix##_iter_done(prefix##_iter_t *iter); \
36 void prefix##_assert_ok(const mapname_t *map)
39DECLARE_MAP_FNS(strmap_t,
const char *, strmap);
41DECLARE_MAP_FNS(digestmap_t,
const char *, digestmap);
44DECLARE_MAP_FNS(digest256map_t,
const uint8_t *, digest256map);
46#define MAP_FREE_AND_NULL(mapname_t, map, fn) \
48 mapname_t ## _free_((map), (fn)); \
52#define strmap_free(map, fn) MAP_FREE_AND_NULL(strmap, (map), (fn))
53#define digestmap_free(map, fn) MAP_FREE_AND_NULL(digestmap, (map), (fn))
54#define digest256map_free(map, fn) MAP_FREE_AND_NULL(digest256map, (map), (fn))
82#define MAP_FOREACH(prefix, map, keytype, keyvar, valtype, valvar) \
84 prefix##_iter_t *keyvar##_iter; \
85 for (keyvar##_iter = prefix##_iter_init(map); \
86 !prefix##_iter_done(keyvar##_iter); \
87 keyvar##_iter = prefix##_iter_next(map, keyvar##_iter)) { \
89 void *valvar##_voidp; \
91 prefix##_iter_get(keyvar##_iter, &keyvar, &valvar##_voidp); \
92 valvar = valvar##_voidp;
122#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar) \
124 prefix##_iter_t *keyvar##_iter; \
125 int keyvar##_del=0; \
126 for (keyvar##_iter = prefix##_iter_init(map); \
127 !prefix##_iter_done(keyvar##_iter); \
128 keyvar##_iter = keyvar##_del ? \
129 prefix##_iter_next_rmv(map, keyvar##_iter) : \
130 prefix##_iter_next(map, keyvar##_iter)) { \
132 void *valvar##_voidp; \
135 prefix##_iter_get(keyvar##_iter, &keyvar, &valvar##_voidp); \
136 valvar = valvar##_voidp;
140#define MAP_DEL_CURRENT(keyvar) \
146#define MAP_FOREACH_END } STMT_END ;
154#define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar) \
155 MAP_FOREACH(digestmap, map, const char *, keyvar, valtype, valvar)
165#define DIGESTMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
166 MAP_FOREACH_MODIFY(digestmap, map, const char *, keyvar, valtype, valvar)
168#define DIGESTMAP_FOREACH_END MAP_FOREACH_END
170#define DIGEST256MAP_FOREACH(map, keyvar, valtype, valvar) \
171 MAP_FOREACH(digest256map, map, const uint8_t *, keyvar, valtype, valvar)
172#define DIGEST256MAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
173 MAP_FOREACH_MODIFY(digest256map, map, const uint8_t *, \
174 keyvar, valtype, valvar)
175#define DIGEST256MAP_FOREACH_END MAP_FOREACH_END
177#define STRMAP_FOREACH(map, keyvar, valtype, valvar) \
178 MAP_FOREACH(strmap, map, const char *, keyvar, valtype, valvar)
179#define STRMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar) \
180 MAP_FOREACH_MODIFY(strmap, map, const char *, keyvar, valtype, valvar)
181#define STRMAP_FOREACH_END MAP_FOREACH_END
183void*
strmap_set_lc(strmap_t *map,
const char *key,
void *val);
187#define DECLARE_TYPED_DIGESTMAP_FNS(prefix, mapname_t, valtype) \
188 typedef struct mapname_t mapname_t; \
189 typedef struct prefix##_iter_t *prefix##_iter_t; \
190 ATTR_UNUSED static inline mapname_t* \
193 return (mapname_t*)digestmap_new(); \
195 ATTR_UNUSED static inline digestmap_t* \
196 prefix##_to_digestmap(mapname_t *map) \
198 return (digestmap_t*)map; \
200 ATTR_UNUSED static inline valtype* \
201 prefix##_get(mapname_t *map, const char *key) \
203 return (valtype*)digestmap_get((digestmap_t*)map, key); \
205 ATTR_UNUSED static inline valtype* \
206 prefix##_set(mapname_t *map, const char *key, valtype *val) \
208 return (valtype*)digestmap_set((digestmap_t*)map, key, val); \
210 ATTR_UNUSED static inline valtype* \
211 prefix##_remove(mapname_t *map, const char *key) \
213 return (valtype*)digestmap_remove((digestmap_t*)map, key); \
215 ATTR_UNUSED static inline void \
216 prefix##_f##ree_(mapname_t *map, void (*free_val)(void*)) \
218 digestmap_free_((digestmap_t*)map, free_val); \
220 ATTR_UNUSED static inline int \
221 prefix##_isempty(mapname_t *map) \
223 return digestmap_isempty((digestmap_t*)map); \
225 ATTR_UNUSED static inline int \
226 prefix##_size(mapname_t *map) \
228 return digestmap_size((digestmap_t*)map); \
230 ATTR_UNUSED static inline \
231 prefix##_iter_t *prefix##_iter_init(mapname_t *map) \
233 return (prefix##_iter_t*) digestmap_iter_init((digestmap_t*)map); \
235 ATTR_UNUSED static inline \
236 prefix##_iter_t *prefix##_iter_next(mapname_t *map, prefix##_iter_t *iter) \
238 return (prefix##_iter_t*) digestmap_iter_next( \
239 (digestmap_t*)map, (digestmap_iter_t*)iter); \
241 ATTR_UNUSED static inline prefix##_iter_t* \
242 prefix##_iter_next_rmv(mapname_t *map, prefix##_iter_t *iter) \
244 return (prefix##_iter_t*) digestmap_iter_next_rmv( \
245 (digestmap_t*)map, (digestmap_iter_t*)iter); \
247 ATTR_UNUSED static inline void \
248 prefix##_iter_get(prefix##_iter_t *iter, \
253 digestmap_iter_get((digestmap_iter_t*) iter, keyp, &v); \
256 ATTR_UNUSED static inline int \
257 prefix##_iter_done(prefix##_iter_t *iter) \
259 return digestmap_iter_done((digestmap_iter_t*)iter); \
void * strmap_get_lc(const strmap_t *map, const char *key)
void * strmap_remove_lc(strmap_t *map, const char *key)
void * strmap_set_lc(strmap_t *map, const char *key, void *val)
Macros to implement mocking and selective exposure for the test code.
Integer definitions used throughout Tor.