summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-20 01:41:45 +0200
committerwm4 <wm4@nowhere>2012-09-23 14:58:56 +0200
commit397eb9364b83ede4c4f82f52dff8ed1ecb414338 (patch)
tree5502ae6dd6fc7b35a2fd9a227723acd786f3aa52
parentbfc3dbae88dc70a832e82c5b44474fdf5a5e65a5 (diff)
downloadmpv-397eb9364b83ede4c4f82f52dff8ed1ecb414338.tar.bz2
mpv-397eb9364b83ede4c4f82f52dff8ed1ecb414338.tar.xz
options: handle alias options differently
When setting an alias option, its value is not saved in the file-local options case. The ensure_backup function in m_config.c exits if it encounters an aliased option, because it should not be saved additionally to the original option. However, the original option is likely never saved in this case. Change it so that ensure_backup always accesses the original option. The original option is the one that first appears in the option list.
-rw-r--r--m_config.c10
-rw-r--r--m_config.h9
2 files changed, 9 insertions, 10 deletions
diff --git a/m_config.c b/m_config.c
index 11272766d2..c8cf250807 100644
--- a/m_config.c
+++ b/m_config.c
@@ -161,7 +161,7 @@ static int config_destroy(void *p)
{
struct m_config *config = p;
for (struct m_config_option *copt = config->opts; copt; copt = copt->next) {
- if (copt->flags & M_CFG_OPT_ALIAS)
+ if (copt->alias_owner)
continue;
if (copt->opt->type->flags & M_OPT_TYPE_DYNAMIC) {
m_option_free(copt->opt, copt->data);
@@ -219,14 +219,14 @@ void m_config_free(struct m_config *config)
static void ensure_backup(struct m_config *config, struct m_config_option *co)
{
+ while (co->alias_owner)
+ co = co->alias_owner;
if (!config->file_local_mode)
return;
if (co->opt->type->flags & M_OPT_TYPE_HAS_CHILD)
return;
if (co->opt->flags & M_OPT_GLOBAL)
return;
- if (co->flags & M_CFG_OPT_ALIAS)
- return;
if (co->global_backup)
return;
co->global_backup = talloc_zero_size(co, co->opt->type->size);
@@ -319,12 +319,12 @@ static void m_config_add_option(struct m_config *config,
for (struct m_config_option *i = config->opts; i; i = i->next) {
if (co->data == i->data) {
// So we don't save the same vars more than 1 time
- co->flags |= M_CFG_OPT_ALIAS;
+ co->alias_owner = i;
break;
}
}
}
- if (co->flags & M_CFG_OPT_ALIAS) {
+ if (co->alias_owner) {
assert(!arg->defval);
} else {
if (arg->defval) {
diff --git a/m_config.h b/m_config.h
index 80897ce0e4..6bb1f4ff35 100644
--- a/m_config.h
+++ b/m_config.h
@@ -43,10 +43,12 @@ struct m_config_option {
void *data;
// Raw value of the backup of the global value (or NULL).
void *global_backup;
- // See \ref ConfigOptionFlags.
- unsigned int flags;
// If this is a suboption, the option that contains this option.
struct m_config_option *parent;
+ // If this option aliases another, more important option. The alias_owner
+ // option is the one that has the most correct option type for the data
+ // variable, and which is considered the original.
+ struct m_config_option *alias_owner;
};
// Profiles allow to predefine some sets of options that can then
@@ -91,9 +93,6 @@ typedef struct m_config {
int (*includefunc)(struct m_config *conf, char *filename);
} m_config_t;
-// Set if another option already uses the same variable.
-#define M_CFG_OPT_ALIAS (1 << 1)
-
// Create a new config object.
struct m_config *
m_config_new(void *optstruct,