Fix warnings caused by bad prototypes.

This commit is contained in:
David Given 2022-08-03 21:13:12 +02:00
parent 86ded9ea2c
commit 03420ef4ad
2 changed files with 22 additions and 20 deletions

View file

@ -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; struct smap* map = mapp;
int i; int i;
@ -44,34 +44,36 @@ void smap_put(struct smap *mapp, const char* key, void* value)
append(map, key, value); append(map, key, value);
} }
void smap_init(struct smap *mapp) void smap_init(void *mapp)
{ {
mapp->count = 0; struct smap* map = mapp;
mapp->item = NULL; map->count = 0;
mapp->max = 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; int i;
for (i=0; i<mapp->count; i++) for (i=0; i<map->count; i++)
{ {
struct smap_node* node = &mapp->item[i]; struct smap_node* node = &map->item[i];
if (free_key) if (free_key)
{ {
free(node->left); free((void*) node->left);
} }
if (free_value) if (free_value)
{ {
free(node->right); free(node->right);
} }
} }
mapp->count = 0; map->count = 0;
free(mapp->item); 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; struct smap* map = mapp;
int i; int i;
@ -86,7 +88,7 @@ void smap_add(struct smap *mapp, const char* key, void* value)
append(map, key, 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; struct smap* map = mapp;
int i; int i;

View file

@ -8,7 +8,7 @@
struct smap_node struct smap_node
{ {
char* left; const char* left;
void* right; void* right;
}; };
@ -23,7 +23,7 @@ struct smap
#define SMAPOF(RIGHT) \ #define SMAPOF(RIGHT) \
struct { \ struct { \
struct { char* left; RIGHT* right; }* item; \ struct { const char* left; RIGHT* right; }* item; \
int count; \ int count; \
int max; \ int max; \
} }
@ -31,28 +31,28 @@ struct smap
/** Initializes a string map and returns the initialized /** Initializes a string map and returns the initialized
* handle in `mapp`. * 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 /** Adds a new item with name `key` in the string map if
* it does not already exist, otherwise replaces the * it does not already exist, otherwise replaces the
* value `value` associated with the existing `key`. * 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 /** Adds a new item in a string map only if `key` does
* not already exist in the string map. * 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 /** Returns the value associated with the specified `key`, returns
* NULL if `key` is not present in the string map. * 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. /** Frees the data structure associated with the string map.
* Also frees the memory associated with the key if * Also frees the memory associated with the key if
* `free_key` is non-zero, and free the memory associated * `free_key` is non-zero, and free the memory associated
* with the value if `free_value` is non-zero. * 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 #endif