[pulseaudio-discuss] [PATCH] idxset: Allow deep copying with pa_idxset_copy()
Tanu Kaskinen
tanu.kaskinen at linux.intel.com
Sun Nov 17 12:47:59 PST 2013
---
src/modules/alsa/alsa-mixer.c | 2 +-
src/modules/alsa/alsa-sink.c | 9 +--------
src/pulsecore/idxset.c | 4 ++--
src/pulsecore/idxset.h | 7 +++++--
4 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 95c7628..2b90a6e 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -2574,7 +2574,7 @@ static bool element_create_settings(pa_alsa_element *e, pa_alsa_setting *templat
if (template) {
s = pa_xnewdup(pa_alsa_setting, template, 1);
- s->options = pa_idxset_copy(template->options);
+ s->options = pa_idxset_copy(template->options, NULL);
s->name = pa_sprintf_malloc("%s+%s", template->name, o->name);
s->description =
(template->description[0] && o->description[0])
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index e10e14e..ccf1137 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1534,17 +1534,10 @@ static void sink_update_requested_latency_cb(pa_sink *s) {
static pa_idxset* sink_get_formats(pa_sink *s) {
struct userdata *u = s->userdata;
- pa_idxset *ret = pa_idxset_new(NULL, NULL);
- pa_format_info *f;
- uint32_t idx;
pa_assert(u);
- PA_IDXSET_FOREACH(f, u->formats, idx) {
- pa_idxset_put(ret, pa_format_info_copy(f), NULL);
- }
-
- return ret;
+ return pa_idxset_copy(u->formats, (pa_copy_func_t) pa_format_info_copy);
}
static bool sink_set_formats(pa_sink *s, pa_idxset *formats) {
diff --git a/src/pulsecore/idxset.c b/src/pulsecore/idxset.c
index 3d2dbbe..eec73c6 100644
--- a/src/pulsecore/idxset.c
+++ b/src/pulsecore/idxset.c
@@ -458,7 +458,7 @@ bool pa_idxset_isempty(pa_idxset *s) {
return s->n_entries == 0;
}
-pa_idxset *pa_idxset_copy(pa_idxset *s) {
+pa_idxset *pa_idxset_copy(pa_idxset *s, pa_copy_func_t copy_func) {
pa_idxset *copy;
struct idxset_entry *i;
@@ -467,7 +467,7 @@ pa_idxset *pa_idxset_copy(pa_idxset *s) {
copy = pa_idxset_new(s->hash_func, s->compare_func);
for (i = s->iterate_list_head; i; i = i->iterate_next)
- pa_idxset_put(copy, i->data, NULL);
+ pa_idxset_put(copy, copy_func ? copy_func(i->data) : i->data, NULL);
return copy;
}
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
index 849253c..53ac402 100644
--- a/src/pulsecore/idxset.h
+++ b/src/pulsecore/idxset.h
@@ -49,6 +49,7 @@ int pa_idxset_string_compare_func(const void *a, const void *b);
typedef unsigned (*pa_hash_func_t)(const void *p);
typedef int (*pa_compare_func_t)(const void *a, const void *b);
+typedef void *(*pa_copy_func_t)(const void *p);
typedef struct pa_idxset pa_idxset;
@@ -105,8 +106,10 @@ unsigned pa_idxset_size(pa_idxset*s);
/* Return true of the idxset is empty */
bool pa_idxset_isempty(pa_idxset *s);
-/* Duplicate the idxset. This will not copy the actual indexes */
-pa_idxset *pa_idxset_copy(pa_idxset *s);
+/* Duplicate the idxset. This will not copy the actual indexes. If copy_func is
+ * set, each entry is copied using the provided function, otherwise a shallow
+ * copy will be made. */
+pa_idxset *pa_idxset_copy(pa_idxset *s, pa_copy_func_t copy_func);
/* A macro to ease iteration through all entries */
#define PA_IDXSET_FOREACH(e, s, idx) \
--
1.8.3.1
More information about the pulseaudio-discuss
mailing list