mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-11 13:30:02 -05:00
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:
parent
317b46b571
commit
6825df8cec
41 changed files with 232 additions and 205 deletions
|
|
@ -89,8 +89,8 @@ pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) {
|
|||
|
||||
memset(data, 0, sizeof(*data));
|
||||
data->proplist = pa_proplist_new();
|
||||
data->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->profiles = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_card_profile_free);
|
||||
data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
|
@ -128,10 +128,10 @@ void pa_card_new_data_done(pa_card_new_data *data) {
|
|||
pa_proplist_free(data->proplist);
|
||||
|
||||
if (data->profiles)
|
||||
pa_hashmap_free(data->profiles, (pa_free_cb_t) pa_card_profile_free);
|
||||
pa_hashmap_free(data->profiles);
|
||||
|
||||
if (data->ports)
|
||||
pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
|
||||
pa_hashmap_free(data->ports);
|
||||
|
||||
pa_xfree(data->name);
|
||||
pa_xfree(data->active_profile);
|
||||
|
|
@ -239,10 +239,10 @@ void pa_card_free(pa_card *c) {
|
|||
pa_assert(pa_idxset_isempty(c->sources));
|
||||
pa_idxset_free(c->sources, NULL);
|
||||
|
||||
pa_hashmap_free(c->ports, (pa_free_cb_t) pa_device_port_unref);
|
||||
pa_hashmap_free(c->ports);
|
||||
|
||||
if (c->profiles)
|
||||
pa_hashmap_free(c->profiles, (pa_free_cb_t) pa_card_profile_free);
|
||||
pa_hashmap_free(c->profiles);
|
||||
|
||||
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);
|
||||
|
||||
pa_assert(pa_hashmap_isempty(c->namereg));
|
||||
pa_hashmap_free(c->namereg, NULL);
|
||||
pa_hashmap_free(c->namereg);
|
||||
|
||||
pa_assert(pa_hashmap_isempty(c->shared));
|
||||
pa_hashmap_free(c->shared, NULL);
|
||||
pa_hashmap_free(c->shared);
|
||||
|
||||
pa_subscription_free_all(c);
|
||||
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ pa_database* pa_database_open(const char *fn, bool for_write) {
|
|||
|
||||
if (f || errno == ENOENT) { /* file not found is ok */
|
||||
db = pa_xnew0(simple_data, 1);
|
||||
db->map = pa_hashmap_new(hash_func, compare_func);
|
||||
db->map = pa_hashmap_new_full(hash_func, compare_func, NULL, (pa_free_cb_t) free_entry);
|
||||
db->filename = pa_xstrdup(path);
|
||||
db->tmp_filename = pa_sprintf_malloc(".%s.tmp", db->filename);
|
||||
db->read_only = !for_write;
|
||||
|
|
@ -265,7 +265,7 @@ void pa_database_close(pa_database *database) {
|
|||
pa_database_sync(database);
|
||||
pa_xfree(db->filename);
|
||||
pa_xfree(db->tmp_filename);
|
||||
pa_hashmap_free(db->map, (pa_free_cb_t) free_entry);
|
||||
pa_hashmap_free(db->map);
|
||||
pa_xfree(db);
|
||||
}
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ int pa_database_clear(pa_database *database) {
|
|||
|
||||
pa_assert(db);
|
||||
|
||||
pa_hashmap_remove_all(db->map, (pa_free_cb_t) free_entry);
|
||||
pa_hashmap_remove_all(db->map);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ static void device_port_free(pa_object *o) {
|
|||
pa_proplist_free(p->proplist);
|
||||
|
||||
if (p->profiles)
|
||||
pa_hashmap_free(p->profiles, NULL);
|
||||
pa_hashmap_free(p->profiles);
|
||||
|
||||
pa_xfree(p->name);
|
||||
pa_xfree(p->description);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
#define NBUCKETS 127
|
||||
|
||||
struct hashmap_entry {
|
||||
const void *key;
|
||||
void *key;
|
||||
void *value;
|
||||
|
||||
struct hashmap_entry *bucket_next, *bucket_previous;
|
||||
|
|
@ -46,6 +46,9 @@ struct pa_hashmap {
|
|||
pa_hash_func_t hash_func;
|
||||
pa_compare_func_t compare_func;
|
||||
|
||||
pa_free_cb_t key_free_func;
|
||||
pa_free_cb_t value_free_func;
|
||||
|
||||
struct hashmap_entry *iterate_list_head, *iterate_list_tail;
|
||||
unsigned n_entries;
|
||||
};
|
||||
|
|
@ -54,7 +57,7 @@ struct pa_hashmap {
|
|||
|
||||
PA_STATIC_FLIST_DECLARE(entries, 0, pa_xfree);
|
||||
|
||||
pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func) {
|
||||
pa_hashmap *pa_hashmap_new_full(pa_hash_func_t hash_func, pa_compare_func_t compare_func, pa_free_cb_t key_free_func, pa_free_cb_t value_free_func) {
|
||||
pa_hashmap *h;
|
||||
|
||||
h = pa_xmalloc0(PA_ALIGN(sizeof(pa_hashmap)) + NBUCKETS*sizeof(struct hashmap_entry*));
|
||||
|
|
@ -62,12 +65,19 @@ pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_f
|
|||
h->hash_func = hash_func ? hash_func : pa_idxset_trivial_hash_func;
|
||||
h->compare_func = compare_func ? compare_func : pa_idxset_trivial_compare_func;
|
||||
|
||||
h->key_free_func = key_free_func;
|
||||
h->value_free_func = value_free_func;
|
||||
|
||||
h->n_entries = 0;
|
||||
h->iterate_list_head = h->iterate_list_tail = NULL;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_func) {
|
||||
return pa_hashmap_new_full(hash_func, compare_func, NULL, NULL);
|
||||
}
|
||||
|
||||
static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
|
||||
pa_assert(h);
|
||||
pa_assert(e);
|
||||
|
|
@ -94,6 +104,9 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
|
|||
BY_HASH(h)[hash] = e->bucket_next;
|
||||
}
|
||||
|
||||
if (h->key_free_func)
|
||||
h->key_free_func(e->key);
|
||||
|
||||
if (pa_flist_push(PA_STATIC_FLIST_GET(entries), e) < 0)
|
||||
pa_xfree(e);
|
||||
|
||||
|
|
@ -101,10 +114,10 @@ static void remove_entry(pa_hashmap *h, struct hashmap_entry *e) {
|
|||
h->n_entries--;
|
||||
}
|
||||
|
||||
void pa_hashmap_free(pa_hashmap *h, pa_free_cb_t free_cb) {
|
||||
void pa_hashmap_free(pa_hashmap *h) {
|
||||
pa_assert(h);
|
||||
|
||||
pa_hashmap_remove_all(h, free_cb);
|
||||
pa_hashmap_remove_all(h);
|
||||
pa_xfree(h);
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +133,7 @@ static struct hashmap_entry *hash_scan(pa_hashmap *h, unsigned hash, const void
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int pa_hashmap_put(pa_hashmap *h, const void *key, void *value) {
|
||||
int pa_hashmap_put(pa_hashmap *h, void *key, void *value) {
|
||||
struct hashmap_entry *e;
|
||||
unsigned hash;
|
||||
|
||||
|
|
@ -194,7 +207,7 @@ void* pa_hashmap_remove(pa_hashmap *h, const void *key) {
|
|||
return data;
|
||||
}
|
||||
|
||||
void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb) {
|
||||
void pa_hashmap_remove_all(pa_hashmap *h) {
|
||||
pa_assert(h);
|
||||
|
||||
while (h->iterate_list_head) {
|
||||
|
|
@ -202,8 +215,8 @@ void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb) {
|
|||
data = h->iterate_list_head->value;
|
||||
remove_entry(h, h->iterate_list_head);
|
||||
|
||||
if (free_cb)
|
||||
free_cb(data);
|
||||
if (h->value_free_func)
|
||||
h->value_free_func(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,11 +36,15 @@ typedef struct pa_hashmap pa_hashmap;
|
|||
/* Create a new hashmap. Use the specified functions for hashing and comparing objects in the map */
|
||||
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_free_cb_t free_cb);
|
||||
/* Create a new hashmap. Use the specified functions for hashing and comparing objects in the map, and functions to free the key
|
||||
* and value (either or both can be NULL). */
|
||||
pa_hashmap *pa_hashmap_new_full(pa_hash_func_t hash_func, pa_compare_func_t compare_func, pa_free_cb_t key_free_func, pa_free_cb_t value_free_func);
|
||||
|
||||
/* Free the hash table. */
|
||||
void pa_hashmap_free(pa_hashmap*);
|
||||
|
||||
/* 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);
|
||||
int pa_hashmap_put(pa_hashmap *h, void *key, void *value);
|
||||
|
||||
/* Return an entry from the hashmap */
|
||||
void* pa_hashmap_get(pa_hashmap *h, const void *key);
|
||||
|
|
@ -48,8 +52,8 @@ void* pa_hashmap_get(pa_hashmap *h, const void *key);
|
|||
/* Returns the data of the entry while removing */
|
||||
void* pa_hashmap_remove(pa_hashmap *h, const void *key);
|
||||
|
||||
/* If free_cb is not NULL, it's called for each entry. */
|
||||
void pa_hashmap_remove_all(pa_hashmap *h, pa_free_cb_t free_cb);
|
||||
/* Remove all entries but don't free the hashmap */
|
||||
void pa_hashmap_remove_all(pa_hashmap *h);
|
||||
|
||||
/* Return the current number of entries of the hashmap */
|
||||
unsigned pa_hashmap_size(pa_hashmap *h);
|
||||
|
|
|
|||
|
|
@ -964,8 +964,8 @@ void pa_memimport_free(pa_memimport *i) {
|
|||
|
||||
pa_mutex_unlock(i->pool->mutex);
|
||||
|
||||
pa_hashmap_free(i->blocks, NULL);
|
||||
pa_hashmap_free(i->segments, NULL);
|
||||
pa_hashmap_free(i->blocks);
|
||||
pa_hashmap_free(i->segments);
|
||||
|
||||
pa_mutex_free(i->mutex);
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,15 @@ static int add_key_value(pa_modargs *ma, char *key, char *value, const char* con
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void free_func(void *p) {
|
||||
struct entry *e = p;
|
||||
pa_assert(e);
|
||||
|
||||
pa_xfree(e->key);
|
||||
pa_xfree(e->value);
|
||||
pa_xfree(e);
|
||||
}
|
||||
|
||||
pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
|
||||
enum {
|
||||
WHITESPACE,
|
||||
|
|
@ -110,8 +119,8 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
|
|||
size_t key_len = 0, value_len = 0;
|
||||
pa_modargs *ma = pa_xnew(pa_modargs, 1);
|
||||
|
||||
ma->raw = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
ma->unescaped = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
ma->raw = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, free_func);
|
||||
ma->unescaped = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, free_func);
|
||||
|
||||
if (!args)
|
||||
return ma;
|
||||
|
|
@ -247,20 +256,11 @@ fail:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void free_func(void *p) {
|
||||
struct entry *e = p;
|
||||
pa_assert(e);
|
||||
|
||||
pa_xfree(e->key);
|
||||
pa_xfree(e->value);
|
||||
pa_xfree(e);
|
||||
}
|
||||
|
||||
void pa_modargs_free(pa_modargs*ma) {
|
||||
pa_assert(ma);
|
||||
|
||||
pa_hashmap_free(ma->raw, free_func);
|
||||
pa_hashmap_free(ma->unescaped, free_func);
|
||||
pa_hashmap_free(ma->raw);
|
||||
pa_hashmap_free(ma->unescaped);
|
||||
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);
|
||||
pa_hashmap_free(c->wait_events);
|
||||
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);
|
||||
pa_hashmap_free(p->connections, NULL);
|
||||
pa_hashmap_free(p->objects);
|
||||
pa_hashmap_free(p->connections);
|
||||
pa_idxset_free(p->extensions, NULL);
|
||||
|
||||
for (i = 0; i < PA_DBUS_PROTOCOL_HOOK_MAX; ++i)
|
||||
|
|
@ -633,6 +633,23 @@ static pa_dbus_arg_info *copy_args(const pa_dbus_arg_info *src, unsigned n) {
|
|||
return dst;
|
||||
}
|
||||
|
||||
static void method_handler_free(pa_dbus_method_handler *h) {
|
||||
unsigned i;
|
||||
|
||||
pa_assert(h);
|
||||
|
||||
pa_xfree((char *) h->method_name);
|
||||
|
||||
for (i = 0; i < h->n_arguments; ++i) {
|
||||
pa_xfree((char *) h->arguments[i].name);
|
||||
pa_xfree((char *) h->arguments[i].type);
|
||||
pa_xfree((char *) h->arguments[i].direction);
|
||||
}
|
||||
|
||||
pa_xfree((pa_dbus_arg_info *) h->arguments);
|
||||
pa_xfree(h);
|
||||
}
|
||||
|
||||
static pa_hashmap *create_method_handlers(const pa_dbus_interface_info *info) {
|
||||
pa_hashmap *handlers;
|
||||
unsigned i;
|
||||
|
|
@ -640,7 +657,7 @@ static pa_hashmap *create_method_handlers(const pa_dbus_interface_info *info) {
|
|||
pa_assert(info);
|
||||
pa_assert(info->method_handlers || info->n_method_handlers == 0);
|
||||
|
||||
handlers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
handlers = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) method_handler_free);
|
||||
|
||||
for (i = 0; i < info->n_method_handlers; ++i) {
|
||||
pa_dbus_method_handler *h = pa_xnew(pa_dbus_method_handler, 1);
|
||||
|
|
@ -649,7 +666,7 @@ static pa_hashmap *create_method_handlers(const pa_dbus_interface_info *info) {
|
|||
h->n_arguments = info->method_handlers[i].n_arguments;
|
||||
h->receive_cb = info->method_handlers[i].receive_cb;
|
||||
|
||||
pa_hashmap_put(handlers, h->method_name, h);
|
||||
pa_hashmap_put(handlers, (char *) h->method_name, h);
|
||||
}
|
||||
|
||||
return handlers;
|
||||
|
|
@ -664,7 +681,7 @@ static pa_hashmap *extract_method_signatures(pa_hashmap *method_handlers) {
|
|||
|
||||
pa_assert(method_handlers);
|
||||
|
||||
signatures = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
signatures = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, pa_xfree);
|
||||
|
||||
PA_HASHMAP_FOREACH(handler, method_handlers, state) {
|
||||
sig_buf = pa_strbuf_new();
|
||||
|
|
@ -674,12 +691,21 @@ static pa_hashmap *extract_method_signatures(pa_hashmap *method_handlers) {
|
|||
pa_strbuf_puts(sig_buf, handler->arguments[i].type);
|
||||
}
|
||||
|
||||
pa_hashmap_put(signatures, handler->method_name, pa_strbuf_tostring_free(sig_buf));
|
||||
pa_hashmap_put(signatures, (char *) handler->method_name, pa_strbuf_tostring_free(sig_buf));
|
||||
}
|
||||
|
||||
return signatures;
|
||||
}
|
||||
|
||||
static void property_handler_free(pa_dbus_property_handler *h) {
|
||||
pa_assert(h);
|
||||
|
||||
pa_xfree((char *) h->property_name);
|
||||
pa_xfree((char *) h->type);
|
||||
|
||||
pa_xfree(h);
|
||||
}
|
||||
|
||||
static pa_hashmap *create_property_handlers(const pa_dbus_interface_info *info) {
|
||||
pa_hashmap *handlers;
|
||||
unsigned i = 0;
|
||||
|
|
@ -687,7 +713,7 @@ static pa_hashmap *create_property_handlers(const pa_dbus_interface_info *info)
|
|||
pa_assert(info);
|
||||
pa_assert(info->property_handlers || info->n_property_handlers == 0);
|
||||
|
||||
handlers = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
handlers = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) property_handler_free);
|
||||
|
||||
for (i = 0; i < info->n_property_handlers; ++i) {
|
||||
pa_dbus_property_handler *h = pa_xnew(pa_dbus_property_handler, 1);
|
||||
|
|
@ -696,7 +722,7 @@ static pa_hashmap *create_property_handlers(const pa_dbus_interface_info *info)
|
|||
h->get_cb = info->property_handlers[i].get_cb;
|
||||
h->set_cb = info->property_handlers[i].set_cb;
|
||||
|
||||
pa_hashmap_put(handlers, h->property_name, h);
|
||||
pa_hashmap_put(handlers, (char *) h->property_name, h);
|
||||
}
|
||||
|
||||
return handlers;
|
||||
|
|
@ -789,32 +815,6 @@ 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(pa_dbus_method_handler *h) {
|
||||
unsigned i;
|
||||
|
||||
pa_assert(h);
|
||||
|
||||
pa_xfree((char *) h->method_name);
|
||||
|
||||
for (i = 0; i < h->n_arguments; ++i) {
|
||||
pa_xfree((char *) h->arguments[i].name);
|
||||
pa_xfree((char *) h->arguments[i].type);
|
||||
pa_xfree((char *) h->arguments[i].direction);
|
||||
}
|
||||
|
||||
pa_xfree((pa_dbus_arg_info *) h->arguments);
|
||||
pa_xfree(h);
|
||||
}
|
||||
|
||||
static void property_handler_free(pa_dbus_property_handler *h) {
|
||||
pa_assert(h);
|
||||
|
||||
pa_xfree((char *) h->property_name);
|
||||
pa_xfree((char *) h->type);
|
||||
|
||||
pa_xfree(h);
|
||||
}
|
||||
|
||||
int pa_dbus_protocol_remove_interface(pa_dbus_protocol *p, const char* path, const char* interface) {
|
||||
struct object_entry *obj_entry;
|
||||
struct interface_entry *iface_entry;
|
||||
|
|
@ -835,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, 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);
|
||||
pa_hashmap_free(iface_entry->method_signatures);
|
||||
pa_hashmap_free(iface_entry->method_handlers);
|
||||
pa_hashmap_free(iface_entry->property_handlers);
|
||||
|
||||
for (i = 0; i < iface_entry->n_signals; ++i) {
|
||||
unsigned j;
|
||||
|
|
@ -861,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);
|
||||
pa_hashmap_free(obj_entry->interfaces);
|
||||
pa_xfree(obj_entry->introspection);
|
||||
pa_xfree(obj_entry);
|
||||
}
|
||||
|
|
@ -880,6 +880,14 @@ static void register_all_objects(pa_dbus_protocol *p, DBusConnection *conn) {
|
|||
pa_assert_se(dbus_connection_register_object_path(conn, obj_entry->path, &vtable, p));
|
||||
}
|
||||
|
||||
static void signal_paths_entry_free(struct signal_paths_entry *e) {
|
||||
pa_assert(e);
|
||||
|
||||
pa_xfree(e->signal);
|
||||
pa_idxset_free(e->paths, pa_xfree);
|
||||
pa_xfree(e);
|
||||
}
|
||||
|
||||
int pa_dbus_protocol_register_connection(pa_dbus_protocol *p, DBusConnection *conn, pa_client *client) {
|
||||
struct connection_entry *conn_entry;
|
||||
|
||||
|
|
@ -897,7 +905,8 @@ int pa_dbus_protocol_register_connection(pa_dbus_protocol *p, DBusConnection *co
|
|||
conn_entry->client = client;
|
||||
conn_entry->listening_for_all_signals = false;
|
||||
conn_entry->all_signals_objects = pa_idxset_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
conn_entry->listening_signals = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
conn_entry->listening_signals = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
|
||||
(pa_free_cb_t) signal_paths_entry_free);
|
||||
|
||||
pa_hashmap_put(p->connections, conn, conn_entry);
|
||||
|
||||
|
|
@ -927,14 +936,6 @@ static struct signal_paths_entry *signal_paths_entry_new(const char *signal_name
|
|||
return e;
|
||||
}
|
||||
|
||||
static void signal_paths_entry_free(struct signal_paths_entry *e) {
|
||||
pa_assert(e);
|
||||
|
||||
pa_xfree(e->signal);
|
||||
pa_idxset_free(e->paths, pa_xfree);
|
||||
pa_xfree(e);
|
||||
}
|
||||
|
||||
int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *conn) {
|
||||
struct connection_entry *conn_entry = NULL;
|
||||
|
||||
|
|
@ -948,7 +949,7 @@ int pa_dbus_protocol_unregister_connection(pa_dbus_protocol *p, DBusConnection *
|
|||
|
||||
dbus_connection_unref(conn_entry->connection);
|
||||
pa_idxset_free(conn_entry->all_signals_objects, pa_xfree);
|
||||
pa_hashmap_free(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
|
||||
pa_hashmap_free(conn_entry->listening_signals);
|
||||
pa_xfree(conn_entry);
|
||||
|
||||
return 0;
|
||||
|
|
@ -1006,7 +1007,7 @@ void pa_dbus_protocol_add_signal_listener(
|
|||
|
||||
/* We're not interested in individual signals anymore, so let's empty
|
||||
* listening_signals. */
|
||||
pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
|
||||
pa_hashmap_remove_all(conn_entry->listening_signals);
|
||||
|
||||
for (i = 0; i < n_objects; ++i)
|
||||
pa_idxset_put(conn_entry->all_signals_objects, pa_xstrdup(objects[i]), NULL);
|
||||
|
|
@ -1029,7 +1030,7 @@ void pa_dbus_protocol_remove_signal_listener(pa_dbus_protocol *p, DBusConnection
|
|||
} else {
|
||||
conn_entry->listening_for_all_signals = false;
|
||||
pa_idxset_remove_all(conn_entry->all_signals_objects, pa_xfree);
|
||||
pa_hashmap_remove_all(conn_entry->listening_signals, (pa_free_cb_t) signal_paths_entry_free);
|
||||
pa_hashmap_remove_all(conn_entry->listening_signals);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5139,7 +5139,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);
|
||||
pa_hashmap_free(p->extensions);
|
||||
|
||||
pa_assert_se(pa_shared_remove(p->core, "native-protocol") >= 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -109,8 +109,10 @@ pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data
|
|||
data->proplist = pa_proplist_new();
|
||||
data->volume_writable = true;
|
||||
|
||||
data->volume_factor_items = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->volume_factor_sink_items = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->volume_factor_items = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
|
||||
(pa_free_cb_t) volume_factor_entry_free);
|
||||
data->volume_factor_sink_items = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL,
|
||||
(pa_free_cb_t) volume_factor_entry_free);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
@ -241,10 +243,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_free_cb_t) volume_factor_entry_free);
|
||||
pa_hashmap_free(data->volume_factor_items);
|
||||
|
||||
if (data->volume_factor_sink_items)
|
||||
pa_hashmap_free(data->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
pa_hashmap_free(data->volume_factor_sink_items);
|
||||
|
||||
pa_proplist_free(data->proplist);
|
||||
}
|
||||
|
|
@ -766,13 +768,13 @@ static void sink_input_free(pa_object *o) {
|
|||
pa_idxset_free(i->direct_outputs, NULL);
|
||||
|
||||
if (i->thread_info.direct_outputs)
|
||||
pa_hashmap_free(i->thread_info.direct_outputs, NULL);
|
||||
pa_hashmap_free(i->thread_info.direct_outputs);
|
||||
|
||||
if (i->volume_factor_items)
|
||||
pa_hashmap_free(i->volume_factor_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
pa_hashmap_free(i->volume_factor_items);
|
||||
|
||||
if (i->volume_factor_sink_items)
|
||||
pa_hashmap_free(i->volume_factor_sink_items, (pa_free_cb_t) volume_factor_entry_free);
|
||||
pa_hashmap_free(i->volume_factor_sink_items);
|
||||
|
||||
pa_xfree(i->driver);
|
||||
pa_xfree(i);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data) {
|
|||
|
||||
pa_zero(*data);
|
||||
data->proplist = pa_proplist_new();
|
||||
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ void pa_sink_new_data_done(pa_sink_new_data *data) {
|
|||
pa_proplist_free(data->proplist);
|
||||
|
||||
if (data->ports)
|
||||
pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
|
||||
pa_hashmap_free(data->ports);
|
||||
|
||||
pa_xfree(data->name);
|
||||
pa_xfree(data->active_port);
|
||||
|
|
@ -325,7 +325,8 @@ pa_sink* pa_sink_new(
|
|||
0);
|
||||
|
||||
s->thread_info.rtpoll = NULL;
|
||||
s->thread_info.inputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
|
||||
s->thread_info.inputs = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
|
||||
(pa_free_cb_t) pa_sink_input_unref);
|
||||
s->thread_info.soft_volume = s->soft_volume;
|
||||
s->thread_info.soft_muted = s->muted;
|
||||
s->thread_info.state = s->state;
|
||||
|
|
@ -730,7 +731,7 @@ static void sink_free(pa_object *o) {
|
|||
}
|
||||
|
||||
pa_idxset_free(s->inputs, NULL);
|
||||
pa_hashmap_free(s->thread_info.inputs, (pa_free_cb_t) pa_sink_input_unref);
|
||||
pa_hashmap_free(s->thread_info.inputs);
|
||||
|
||||
if (s->silence.memblock)
|
||||
pa_memblock_unref(s->silence.memblock);
|
||||
|
|
@ -742,7 +743,7 @@ static void sink_free(pa_object *o) {
|
|||
pa_proplist_free(s->proplist);
|
||||
|
||||
if (s->ports)
|
||||
pa_hashmap_free(s->ports, (pa_free_cb_t) pa_device_port_unref);
|
||||
pa_hashmap_free(s->ports);
|
||||
|
||||
pa_xfree(s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data) {
|
|||
|
||||
pa_zero(*data);
|
||||
data->proplist = pa_proplist_new();
|
||||
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
||||
data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
@ -133,7 +133,7 @@ void pa_source_new_data_done(pa_source_new_data *data) {
|
|||
pa_proplist_free(data->proplist);
|
||||
|
||||
if (data->ports)
|
||||
pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
|
||||
pa_hashmap_free(data->ports);
|
||||
|
||||
pa_xfree(data->name);
|
||||
pa_xfree(data->active_port);
|
||||
|
|
@ -313,7 +313,8 @@ pa_source* pa_source_new(
|
|||
0);
|
||||
|
||||
s->thread_info.rtpoll = NULL;
|
||||
s->thread_info.outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
|
||||
s->thread_info.outputs = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
|
||||
(pa_free_cb_t) pa_source_output_unref);
|
||||
s->thread_info.soft_volume = s->soft_volume;
|
||||
s->thread_info.soft_muted = s->muted;
|
||||
s->thread_info.state = s->state;
|
||||
|
|
@ -660,7 +661,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);
|
||||
pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
|
||||
pa_hashmap_free(s->thread_info.outputs);
|
||||
|
||||
if (s->silence.memblock)
|
||||
pa_memblock_unref(s->silence.memblock);
|
||||
|
|
@ -672,7 +673,7 @@ static void source_free(pa_object *o) {
|
|||
pa_proplist_free(s->proplist);
|
||||
|
||||
if (s->ports)
|
||||
pa_hashmap_free(s->ports, (pa_free_cb_t) pa_device_port_unref);
|
||||
pa_hashmap_free(s->ports);
|
||||
|
||||
pa_xfree(s);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue