hashmap: Add the ability to free keys

Since the hashmap stores a pointer to the key provided at pa_hashmap_put()
time, it make sense to allow the hashmap to be given ownership of the key and
have it free it at pa_hashmap_remove/free time.

To do this cleanly, we now provide the key and value free functions at hashmap
creation time with a pa_hashmap_new_full. With this, we do away with the free
function that was provided at remove/free time for freeing the value.
This commit is contained in:
Arun Raghavan 2013-09-14 11:50:10 +05:30
parent 317b46b571
commit 6825df8cec
41 changed files with 232 additions and 205 deletions

View file

@ -317,7 +317,7 @@ int pa__init(pa_module *m) {
m->userdata = u = pa_xnew(struct userdata, 1);
u->cache = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
u->cache = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) rule_free);
u->client_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CLIENT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) client_new_cb, u);
u->client_proplist_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) client_proplist_changed_cb, u);
@ -348,7 +348,7 @@ void pa__done(pa_module *m) {
pa_hook_slot_free(u->client_proplist_changed_slot);
if (u->cache)
pa_hashmap_free(u->cache, (pa_free_cb_t) rule_free);
pa_hashmap_free(u->cache);
pa_xfree(u);
}