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

@ -2109,12 +2109,12 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
if (y->devices) {
remove_all_devices(y);
pa_hashmap_free(y->devices, NULL);
pa_hashmap_free(y->devices);
}
if (y->transports) {
pa_assert(pa_hashmap_isempty(y->transports));
pa_hashmap_free(y->transports, NULL);
pa_hashmap_free(y->transports);
}
if (y->connection) {

View file

@ -184,7 +184,7 @@ void pa__done(pa_module* m) {
pa_xfree(mi);
}
pa_hashmap_free(u->hashmap, NULL);
pa_hashmap_free(u->hashmap);
}
if (u->modargs)

View file

@ -393,7 +393,7 @@ int pa__init(pa_module*m) {
u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
u->hci = pa_xstrdup(pa_modargs_get_value(ma, "hci", DEFAULT_HCI));
u->hci_path = pa_sprintf_malloc("/org/bluez/%s", u->hci);
u->bondings = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
u->bondings = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) bonding_free);
if (!(u->dbus_connection = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &e))) {
pa_log("Failed to get D-Bus connection: %s", e.message);
@ -466,7 +466,7 @@ void pa__done(pa_module*m) {
return;
if (u->bondings)
pa_hashmap_free(u->bondings, (pa_free_cb_t) bonding_free);
pa_hashmap_free(u->bondings);
if (u->dbus_connection) {
update_matches(u, false);