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

@ -745,7 +745,7 @@ int pa__init(pa_module*m) {
u->avahi_poll = pa_avahi_poll_new(u->api);
u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
u->services = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL, (pa_free_cb_t) service_free);
u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
@ -786,7 +786,7 @@ fail:
static void client_free(pa_mainloop_api *api PA_GCC_UNUSED, void *userdata) {
struct userdata *u = (struct userdata *) userdata;
pa_hashmap_free(u->services, (pa_free_cb_t) service_free);
pa_hashmap_free(u->services);
if (u->main_entry_group)
avahi_entry_group_free(u->main_entry_group);