options: fix filter list comparison (again)

This was completely broken: it compared the first item of the filter
list only. Apparently I forgot that this is a list. This probably broke
aspects of runtime filter changing probably since commit  b16cea750f.

Fix this, and remove some redundant code from obj_settings_equals().
Which is not the same as m_obj_settings_equal(), so rename it to make
confusing them harder. (obj_setting_match() has these very weird label
semantics that should probably just be killed. Or not.)
This commit is contained in:
wm4 2019-12-18 06:49:48 +01:00
parent 0a1588d39b
commit 9b9307ea9f
3 changed files with 18 additions and 19 deletions

View File

@ -524,8 +524,7 @@ bool mp_output_chain_update_filters(struct mp_output_chain *c,
struct mp_user_filter *u = NULL;
for (int i = 0; i < p->num_user_filters; i++) {
struct m_option t = {.type = &m_option_type_obj_settings_list};
if (!used[i] && m_option_equal(&t, &entry, &p->user_filters[i]->args))
if (!used[i] && m_obj_settings_equal(entry, p->user_filters[i]->args))
{
u = p->user_filters[i];
used[i] = true;

View File

@ -2813,27 +2813,13 @@ static void obj_setting_free(m_obj_settings_t *item)
}
// If at least one item has a label, compare labels only - otherwise ignore them.
static bool obj_setting_equals(m_obj_settings_t *a, m_obj_settings_t *b)
static bool obj_setting_match(m_obj_settings_t *a, m_obj_settings_t *b)
{
bstr la = bstr0(a->label), lb = bstr0(b->label);
if (la.len || lb.len)
return bstr_equals(la, lb);
if (strcmp(a->name, b->name) != 0)
return false;
int a_attr_count = 0;
while (a->attribs && a->attribs[a_attr_count])
a_attr_count++;
int b_attr_count = 0;
while (b->attribs && b->attribs[b_attr_count])
b_attr_count++;
if (a_attr_count != b_attr_count)
return false;
for (int n = 0; n < a_attr_count; n++) {
if (strcmp(a->attribs[n], b->attribs[n]) != 0)
return false;
}
return true;
return m_obj_settings_equal(a, b);
}
static int obj_settings_list_num_items(m_obj_settings_t *obj_list)
@ -2898,7 +2884,7 @@ static int obj_settings_find_by_content(m_obj_settings_t *obj_list,
m_obj_settings_t *item)
{
for (int n = 0; obj_list && obj_list[n].name; n++) {
if (obj_setting_equals(&obj_list[n], item))
if (obj_setting_match(&obj_list[n], item))
return n;
}
return -1;
@ -3632,6 +3618,18 @@ static bool obj_settings_list_equal(const m_option_t *opt, void *pa, void *pb)
if (a == b || !a || !b)
return a == b;
for (int n = 0; a[n].name || b[n].name; n++) {
if (!a[n].name || !b[n].name)
return false;
if (!m_obj_settings_equal(&a[n], &b[n]))
return false;
}
return true;
}
bool m_obj_settings_equal(struct m_obj_settings *a, struct m_obj_settings *b)
{
if (!str_equal(NULL, &a->name, &b->name))
return false;

View File

@ -181,6 +181,8 @@ typedef struct m_obj_settings {
char **attribs;
} m_obj_settings_t;
bool m_obj_settings_equal(struct m_obj_settings *a, struct m_obj_settings *b);
struct m_opt_choice_alternatives {
char *name;
int value;