mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-09 13:29:59 -05:00
hashmap: Use pa_free_cb_t instead of pa_free2_cb_t
The previous patch removed module-gconf's dependency on the userdata pointer of the free callback, and that was the only place where the userdata pointer of pa_free2_cb_t was used, so now there's no need for pa_free2_cb_t in pa_hashmap_free(). Using pa_free_cb_t instead allows removing a significant amount of repetitive code.
This commit is contained in:
parent
dcf043842e
commit
8872c238ba
41 changed files with 112 additions and 308 deletions
|
|
@ -57,7 +57,6 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
|
|||
|
||||
void pa_card_profile_free(pa_card_profile *c) {
|
||||
pa_assert(c);
|
||||
pa_assert(!c->card); /* Card profiles shouldn't be freed before removing them from the card. */
|
||||
|
||||
pa_xfree(c->name);
|
||||
pa_xfree(c->description);
|
||||
|
|
@ -126,14 +125,8 @@ void pa_card_new_data_done(pa_card_new_data *data) {
|
|||
|
||||
pa_proplist_free(data->proplist);
|
||||
|
||||
if (data->profiles) {
|
||||
pa_card_profile *c;
|
||||
|
||||
while ((c = pa_hashmap_steal_first(data->profiles)))
|
||||
pa_card_profile_free(c);
|
||||
|
||||
pa_hashmap_free(data->profiles, NULL, NULL);
|
||||
}
|
||||
if (data->profiles)
|
||||
pa_hashmap_free(data->profiles, (pa_free_cb_t) pa_card_profile_free);
|
||||
|
||||
if (data->ports)
|
||||
pa_device_port_hashmap_free(data->ports);
|
||||
|
|
@ -246,16 +239,8 @@ void pa_card_free(pa_card *c) {
|
|||
|
||||
pa_device_port_hashmap_free(c->ports);
|
||||
|
||||
if (c->profiles) {
|
||||
pa_card_profile *p;
|
||||
|
||||
while ((p = pa_hashmap_steal_first(c->profiles))) {
|
||||
p->card = NULL;
|
||||
pa_card_profile_free(p);
|
||||
}
|
||||
|
||||
pa_hashmap_free(c->profiles, NULL, NULL);
|
||||
}
|
||||
if (c->profiles)
|
||||
pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_card_profile_free);
|
||||
|
||||
pa_proplist_free(c->proplist);
|
||||
pa_xfree(c->driver);
|
||||
|
|
|
|||
|
|
@ -194,10 +194,10 @@ static void core_free(pa_object *o) {
|
|||
pa_idxset_free(c->sink_inputs, NULL, NULL);
|
||||
|
||||
pa_assert(pa_hashmap_isempty(c->namereg));
|
||||
pa_hashmap_free(c->namereg, NULL, NULL);
|
||||
pa_hashmap_free(c->namereg, NULL);
|
||||
|
||||
pa_assert(pa_hashmap_isempty(c->shared));
|
||||
pa_hashmap_free(c->shared, NULL, NULL);
|
||||
pa_hashmap_free(c->shared, NULL);
|
||||
|
||||
pa_subscription_free_all(c);
|
||||
|
||||
|
|
|
|||
|
|
@ -264,10 +264,9 @@ void pa_database_close(pa_database *database) {
|
|||
pa_assert(db);
|
||||
|
||||
pa_database_sync(database);
|
||||
pa_database_clear(database);
|
||||
pa_xfree(db->filename);
|
||||
pa_xfree(db->tmp_filename);
|
||||
pa_hashmap_free(db->map, NULL, NULL);
|
||||
pa_hashmap_free(db->map, (pa_free_cb_t) free_entry);
|
||||
pa_xfree(db);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,10 @@ static void device_port_free(pa_object *o) {
|
|||
|
||||
if (p->proplist)
|
||||
pa_proplist_free(p->proplist);
|
||||
|
||||
if (p->profiles)
|
||||
pa_hashmap_free(p->profiles, NULL, NULL);
|
||||
pa_hashmap_free(p->profiles, NULL);
|
||||
|
||||
pa_xfree(p->name);
|
||||
pa_xfree(p->description);
|
||||
pa_xfree(p);
|
||||
|
|
@ -88,14 +90,9 @@ pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *des
|
|||
}
|
||||
|
||||
void pa_device_port_hashmap_free(pa_hashmap *h) {
|
||||
pa_device_port *p;
|
||||
|
||||
pa_assert(h);
|
||||
|
||||
while ((p = pa_hashmap_steal_first(h)))
|
||||
pa_device_port_unref(p);
|
||||
|
||||
pa_hashmap_free(h, NULL, NULL);
|
||||
pa_hashmap_free(h, (pa_free_cb_t) pa_device_port_unref);
|
||||
}
|
||||
|
||||
void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
|
|||
h->n_entries--;
|
||||
}
|
||||
|
||||
void pa_hashmap_free(pa_hashmap*h, pa_free2_cb_t free_cb, void *userdata) {
|
||||
void pa_hashmap_free(pa_hashmap *h, pa_free_cb_t free_cb) {
|
||||
pa_assert(h);
|
||||
|
||||
while (h->iterate_list_head) {
|
||||
|
|
@ -110,7 +110,7 @@ void pa_hashmap_free(pa_hashmap*h, pa_free2_cb_t free_cb, void *userdata) {
|
|||
remove_entry(h, h->iterate_list_head);
|
||||
|
||||
if (free_cb)
|
||||
free_cb(data, userdata);
|
||||
free_cb(data);
|
||||
}
|
||||
|
||||
pa_xfree(h);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <pulse/def.h>
|
||||
|
||||
#include <pulsecore/idxset.h>
|
||||
|
||||
/* Simple Implementation of a hash table. Memory management is the
|
||||
|
|
@ -35,7 +37,7 @@ typedef struct pa_hashmap pa_hashmap;
|
|||
pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func);
|
||||
|
||||
/* Free the hash table. Calls the specified function for every value in the table. The function may be NULL */
|
||||
void pa_hashmap_free(pa_hashmap*, pa_free2_cb_t free_cb, void *userdata);
|
||||
void pa_hashmap_free(pa_hashmap*, pa_free_cb_t free_cb);
|
||||
|
||||
/* Add an entry to the hashmap. Returns non-zero when the entry already exists */
|
||||
int pa_hashmap_put(pa_hashmap *h, const void *key, void *value);
|
||||
|
|
|
|||
|
|
@ -964,8 +964,8 @@ void pa_memimport_free(pa_memimport *i) {
|
|||
|
||||
pa_mutex_unlock(i->pool->mutex);
|
||||
|
||||
pa_hashmap_free(i->blocks, NULL, NULL);
|
||||
pa_hashmap_free(i->segments, NULL, NULL);
|
||||
pa_hashmap_free(i->blocks, NULL);
|
||||
pa_hashmap_free(i->segments, NULL);
|
||||
|
||||
pa_mutex_free(i->mutex);
|
||||
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void free_func(void *p, void*userdata) {
|
||||
static void free_func(void *p) {
|
||||
struct entry *e = p;
|
||||
pa_assert(e);
|
||||
|
||||
|
|
@ -259,8 +259,8 @@ static void free_func(void *p, void*userdata) {
|
|||
void pa_modargs_free(pa_modargs*ma) {
|
||||
pa_assert(ma);
|
||||
|
||||
pa_hashmap_free(ma->raw, free_func, NULL);
|
||||
pa_hashmap_free(ma->unescaped, free_func, NULL);
|
||||
pa_hashmap_free(ma->raw, free_func);
|
||||
pa_hashmap_free(ma->unescaped, free_func);
|
||||
pa_xfree(ma);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ pa_cond *pa_cond_new(void) {
|
|||
void pa_cond_free(pa_cond *c) {
|
||||
assert(c);
|
||||
|
||||
pa_hashmap_free(c->wait_events, NULL, NULL);
|
||||
pa_hashmap_free(c->wait_events, NULL);
|
||||
pa_xfree(c);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -169,8 +169,8 @@ void pa_dbus_protocol_unref(pa_dbus_protocol *p) {
|
|||
pa_assert(pa_hashmap_isempty(p->connections));
|
||||
pa_assert(pa_idxset_isempty(p->extensions));
|
||||
|
||||
pa_hashmap_free(p->objects, NULL, NULL);
|
||||
pa_hashmap_free(p->connections, NULL, NULL);
|
||||
pa_hashmap_free(p->objects, NULL);
|
||||
pa_hashmap_free(p->connections, NULL);
|
||||
pa_idxset_free(p->extensions, NULL, NULL);
|
||||
|
||||
for (i = 0; i < PA_DBUS_PROTOCOL_HOOK_MAX; ++i)
|
||||
|
|
@ -789,8 +789,7 @@ static void unregister_object(pa_dbus_protocol *p, struct object_entry *obj_entr
|
|||
pa_assert_se(dbus_connection_unregister_object_path(conn_entry->connection, obj_entry->path));
|
||||
}
|
||||
|
||||
static void method_handler_free_cb(void *p, void *userdata) {
|
||||
pa_dbus_method_handler *h = p;
|
||||
static void method_handler_free(pa_dbus_method_handler *h) {
|
||||
unsigned i;
|
||||
|
||||
pa_assert(h);
|
||||
|
|
@ -807,15 +806,7 @@ static void method_handler_free_cb(void *p, void *userdata) {
|
|||
pa_xfree(h);
|
||||
}
|
||||
|
||||
static void method_signature_free_cb(void *p, void *userdata) {
|
||||
pa_assert(p);
|
||||
|
||||
pa_xfree(p);
|
||||
}
|
||||
|
||||
static void property_handler_free_cb(void *p, void *userdata) {
|
||||
pa_dbus_property_handler *h = p;
|
||||
|
||||
static void property_handler_free(pa_dbus_property_handler *h) {
|
||||
pa_assert(h);
|
||||
|
||||
pa_xfree((char *) h->property_name);
|
||||
|
|
@ -844,9 +835,9 @@ int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, con
|
|||
pa_log_debug("Interface %s removed from object %s", iface_entry->name, obj_entry->path);
|
||||
|
||||
pa_xfree(iface_entry->name);
|
||||
pa_hashmap_free(iface_entry->method_signatures, method_signature_free_cb, NULL);
|
||||
pa_hashmap_free(iface_entry->method_handlers, method_handler_free_cb, NULL);
|
||||
pa_hashmap_free(iface_entry->property_handlers, property_handler_free_cb, NULL);
|
||||
pa_hashmap_free(iface_entry->method_signatures, pa_xfree);
|
||||
pa_hashmap_free(iface_entry->method_handlers, (pa_free_cb_t) method_handler_free);
|
||||
pa_hashmap_free(iface_entry->property_handlers, (pa_free_cb_t) property_handler_free);
|
||||
|
||||
for (i = 0; i < iface_entry->n_signals; ++i) {
|
||||
unsigned j;
|
||||
|
|
@ -870,7 +861,7 @@ int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, con
|
|||
|
||||
pa_hashmap_remove(p->objects, path);
|
||||
pa_xfree(obj_entry->path);
|
||||
pa_hashmap_free(obj_entry->interfaces, NULL, NULL);
|
||||
pa_hashmap_free(obj_entry->interfaces, NULL);
|
||||
pa_xfree(obj_entry->introspection);
|
||||
pa_xfree(obj_entry);
|
||||
}
|
||||
|
|
@ -952,7 +943,6 @@ static void signal_paths_entry_free(struct signal_paths_entry *e) {
|
|||
|
||||
int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn) {
|
||||
struct connection_entry *conn_entry = NULL;
|
||||
struct signal_paths_entry *signal_paths_entry = NULL;
|
||||
char *object_path = NULL;
|
||||
|
||||
pa_assert(p);
|
||||
|
|
@ -970,10 +960,7 @@ int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *
|
|||
|
||||
pa_idxset_free(conn_entry->all_signals_objects, NULL, NULL);
|
||||
|
||||
while ((signal_paths_entry = pa_hashmap_steal_first(conn_entry->listening_signals)))
|
||||
signal_paths_entry_free(signal_paths_entry);
|
||||
|
||||
pa_hashmap_free(conn_entry->listening_signals, NULL, NULL);
|
||||
pa_hashmap_free(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
|
||||
pa_xfree(conn_entry);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -5100,7 +5100,7 @@ void pa_native_protocol_unref(pa_native_protocol *p) {
|
|||
for (h = 0; h < PA_NATIVE_HOOK_MAX; h++)
|
||||
pa_hook_done(&p->hooks[h]);
|
||||
|
||||
pa_hashmap_free(p->extensions, NULL, NULL);
|
||||
pa_hashmap_free(p->extensions, NULL);
|
||||
|
||||
pa_assert_se(pa_shared_remove(p->core, "native-protocol") >= 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -74,10 +74,6 @@ static void volume_factor_entry_free(struct volume_factor_entry *volume_entry) {
|
|||
pa_xfree(volume_entry);
|
||||
}
|
||||
|
||||
static void volume_factor_entry_free2(struct volume_factor_entry *volume_entry, void *userdarta) {
|
||||
volume_factor_entry_free(volume_entry);
|
||||
}
|
||||
|
||||
static void volume_factor_from_hashmap(pa_cvolume *v, pa_hashmap *items, uint8_t channels) {
|
||||
struct volume_factor_entry *entry;
|
||||
void *state = NULL;
|
||||
|
|
@ -245,10 +241,10 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data) {
|
|||
pa_format_info_free(data->format);
|
||||
|
||||
if (data->volume_factor_items)
|
||||
pa_hashmap_free(data->volume_factor_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
|
||||
pa_hashmap_free(data->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
|
||||
if (data->volume_factor_sink_items)
|
||||
pa_hashmap_free(data->volume_factor_sink_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
|
||||
pa_hashmap_free(data->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
|
||||
pa_proplist_free(data->proplist);
|
||||
}
|
||||
|
|
@ -745,12 +741,13 @@ static void sink_input_free(pa_object *o) {
|
|||
pa_idxset_free(i->direct_outputs, NULL, NULL);
|
||||
|
||||
if (i->thread_info.direct_outputs)
|
||||
pa_hashmap_free(i->thread_info.direct_outputs, NULL, NULL);
|
||||
pa_hashmap_free(i->thread_info.direct_outputs, NULL);
|
||||
|
||||
if (i->volume_factor_items)
|
||||
pa_hashmap_free(i->volume_factor_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
|
||||
pa_hashmap_free(i->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
|
||||
if (i->volume_factor_sink_items)
|
||||
pa_hashmap_free(i->volume_factor_sink_items, (pa_free2_cb_t) volume_factor_entry_free2, NULL);
|
||||
pa_hashmap_free(i->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
|
||||
pa_xfree(i->driver);
|
||||
pa_xfree(i);
|
||||
|
|
|
|||
|
|
@ -715,7 +715,6 @@ void pa_sink_unlink(pa_sink* s) {
|
|||
/* Called from main context */
|
||||
static void sink_free(pa_object *o) {
|
||||
pa_sink *s = PA_SINK(o);
|
||||
pa_sink_input *i;
|
||||
|
||||
pa_assert(s);
|
||||
pa_assert_ctl_context();
|
||||
|
|
@ -732,11 +731,7 @@ static void sink_free(pa_object *o) {
|
|||
}
|
||||
|
||||
pa_idxset_free(s->inputs, NULL, NULL);
|
||||
|
||||
while ((i = pa_hashmap_steal_first(s->thread_info.inputs)))
|
||||
pa_sink_input_unref(i);
|
||||
|
||||
pa_hashmap_free(s->thread_info.inputs, NULL, NULL);
|
||||
pa_hashmap_free(s->thread_info.inputs, (pa_free_cb_t) pa_sink_input_unref);
|
||||
|
||||
if (s->silence.memblock)
|
||||
pa_memblock_unref(s->silence.memblock);
|
||||
|
|
|
|||
|
|
@ -648,7 +648,6 @@ void pa_source_unlink(pa_source *s) {
|
|||
|
||||
/* Called from main context */
|
||||
static void source_free(pa_object *o) {
|
||||
pa_source_output *so;
|
||||
pa_source *s = PA_SOURCE(o);
|
||||
|
||||
pa_assert(s);
|
||||
|
|
@ -661,11 +660,7 @@ static void source_free(pa_object *o) {
|
|||
pa_log_info("Freeing source %u \"%s\"", s->index, s->name);
|
||||
|
||||
pa_idxset_free(s->outputs, NULL, NULL);
|
||||
|
||||
while ((so = pa_hashmap_steal_first(s->thread_info.outputs)))
|
||||
pa_source_output_unref(so);
|
||||
|
||||
pa_hashmap_free(s->thread_info.outputs, NULL, NULL);
|
||||
pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
|
||||
|
||||
if (s->silence.memblock)
|
||||
pa_memblock_unref(s->silence.memblock);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue