diff --git a/modules/src/data/smap.c b/modules/src/data/smap.c index 35e594997..abc8d180e 100644 --- a/modules/src/data/smap.c +++ b/modules/src/data/smap.c @@ -26,7 +26,7 @@ static void append(void* mapp, const char* key, void* value) } -void smap_put(struct smap *mapp, const char* key, void* value) +void smap_put(void *mapp, const char* key, void* value) { struct smap* map = mapp; int i; @@ -44,34 +44,36 @@ void smap_put(struct smap *mapp, const char* key, void* value) append(map, key, value); } -void smap_init(struct smap *mapp) +void smap_init(void *mapp) { - mapp->count = 0; - mapp->item = NULL; - mapp->max = 0; + struct smap* map = mapp; + map->count = 0; + map->item = NULL; + map->max = 0; } -void smap_free(struct smap *mapp, int free_key, int free_value) +void smap_free(void *mapp, int free_key, int free_value) { + struct smap* map = mapp; int i; - for (i=0; icount; i++) + for (i=0; icount; i++) { - struct smap_node* node = &mapp->item[i]; + struct smap_node* node = &map->item[i]; if (free_key) { - free(node->left); + free((void*) node->left); } if (free_value) { free(node->right); } } - mapp->count = 0; - free(mapp->item); + map->count = 0; + free(map->item); } -void smap_add(struct smap *mapp, const char* key, void* value) +void smap_add(void *mapp, const char* key, void* value) { struct smap* map = mapp; int i; @@ -86,7 +88,7 @@ void smap_add(struct smap *mapp, const char* key, void* value) append(map, key, value); } -void* smap_get(struct smap *mapp, const char* left) +void* smap_get(void *mapp, const char* left) { struct smap* map = mapp; int i; diff --git a/modules/src/data/smap.h b/modules/src/data/smap.h index 184c2b176..eef2488c1 100644 --- a/modules/src/data/smap.h +++ b/modules/src/data/smap.h @@ -8,7 +8,7 @@ struct smap_node { - char* left; + const char* left; void* right; }; @@ -23,7 +23,7 @@ struct smap #define SMAPOF(RIGHT) \ struct { \ - struct { char* left; RIGHT* right; }* item; \ + struct { const char* left; RIGHT* right; }* item; \ int count; \ int max; \ } @@ -31,28 +31,28 @@ struct smap /** Initializes a string map and returns the initialized * handle in `mapp`. */ -extern void smap_init(struct smap *mapp); +extern void smap_init(void *mapp); /** Adds a new item with name `key` in the string map if * it does not already exist, otherwise replaces the * value `value` associated with the existing `key`. */ -extern void smap_put(struct smap *mapp, const char* key, void* value); +extern void smap_put(void *mapp, const char* key, void* value); /** Adds a new item in a string map only if `key` does * not already exist in the string map. */ -extern void smap_add(struct smap *mapp, const char* key, void* value); +extern void smap_add(void *mapp, const char* key, void* value); /** Returns the value associated with the specified `key`, returns * NULL if `key` is not present in the string map. * */ -extern void* smap_get(struct smap* mapp, const char* key); +extern void* smap_get(void* mapp, const char* key); /** Frees the data structure associated with the string map. * Also frees the memory associated with the key if * `free_key` is non-zero, and free the memory associated * with the value if `free_value` is non-zero. * */ -extern void smap_free(struct smap *mapp, int free_key, int free_value); +extern void smap_free(void *mapp, int free_key, int free_value); #endif