From 1cb085a82e89ce4c9150871c910c75d9404d1e01 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 29 Nov 2019 00:16:52 +0100 Subject: options: get rid of GLOBAL_CONFIG hack Just an implementation detail that can be cleaned up now. Internally, m_config maintains a tree of m_sub_options structs, except for the root it was not defined explicitly. GLOBAL_CONFIG was a hack to get access to it anyway. Define it explicitly instead. --- options/m_config.c | 32 +++++++++++++++----------------- options/m_config.h | 19 ++++--------------- options/options.c | 10 ++++++++-- options/options.h | 3 +-- 4 files changed, 28 insertions(+), 36 deletions(-) (limited to 'options') diff --git a/options/m_config.c b/options/m_config.c index 542288f06f..318ced3d34 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -451,23 +451,15 @@ static void config_destroy(void *p) } struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, - size_t size, const void *defaults, - const struct m_option *options) + const struct m_sub_options *root) { struct m_config *config = talloc(talloc_ctx, struct m_config); talloc_set_destructor(config, config_destroy); *config = (struct m_config){.log = log,}; - struct m_sub_options *subopts = talloc_ptrtype(config, subopts); - *subopts = (struct m_sub_options){ - .opts = options, - .size = size, - .defaults = defaults, - }; - - config->shadow = m_config_shadow_new(subopts); + config->shadow = m_config_shadow_new(root); - if (size) { + if (root->size) { config->data = allocate_option_data(config, config->shadow, 0, config->shadow->data); config->optstruct = config->data->gdata[0].udata; @@ -500,9 +492,16 @@ static struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mpv_global *global, struct m_obj_desc *desc) { - struct m_config *c = - m_config_new(talloc_ctx, log, desc->priv_size, desc->priv_defaults, - desc->options); + struct m_sub_options *root = talloc_ptrtype(NULL, root); + *root = (struct m_sub_options){ + .opts = desc->options, + // (global == NULL got repurposed to mean "no alloc") + .size = global ? desc->priv_size : 0, + .defaults = desc->priv_defaults, + }; + + struct m_config *c = m_config_new(talloc_ctx, log, root); + talloc_steal(c, root); c->global = global; if (desc->set_defaults && c->global) desc->set_defaults(c->global, c->optstruct); @@ -513,7 +512,7 @@ struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, struct mp_log *log, struct m_obj_desc *desc) { - return m_config_new(talloc_ctx, log, 0, desc->priv_defaults, desc->options); + return m_config_from_obj_desc(talloc_ctx, log, NULL, desc); } static const struct m_config_group *find_group(struct mpv_global *global, @@ -1365,8 +1364,7 @@ struct m_config_cache *m_config_cache_alloc(void *ta_parent, int group_index = -1; for (int n = 0; n < shadow->num_groups; n++) { - // group==NULL is special cased to root group. - if (shadow->groups[n].group == group || (!group && !n)) { + if (shadow->groups[n].group == group) { group_index = n; break; } diff --git a/options/m_config.h b/options/m_config.h index 0f05e117a3..357dca5d4d 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -92,16 +92,10 @@ typedef struct m_config { // Create a new config object. // talloc_ctx: talloc parent context for the m_config allocation -// size: size of the optstruct (where option values are stored) -// size==0 creates a config object with no option struct allocated -// defaults: if not NULL, points to a struct of same type as optstruct, which -// contains default values for all options -// options: list of options. Each option defines a member of the optstruct -// and a corresponding option switch or sub-option field. -// Note that the m_config object will keep pointers to defaults and options. +// root: description of all options +// Note that the m_config object will keep pointers to root and log. struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, - size_t size, const void *defaults, - const struct m_option *options); + const struct m_sub_options *root); // Create a m_config for the given desc. This is for --af/--vf, which have // different sub-options for every filter (represented by separate desc @@ -279,8 +273,6 @@ struct m_config_cache { struct config_cache *internal; }; -#define GLOBAL_CONFIG NULL - // Create a mirror copy from the global options. // Keep in mind that a m_config_cache object is not thread-safe; it merely // provides thread-safe access to the global options. All API functions for @@ -290,9 +282,7 @@ struct m_config_cache { // time. // ta_parent: parent for the returned allocation // global: option data source -// group: the option group to return. This can be GLOBAL_CONFIG for the global -// option struct (MPOpts), or m_sub_options used in a certain -// OPT_SUBSTRUCT() item. +// group: the option group to return struct m_config_cache *m_config_cache_alloc(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); @@ -355,7 +345,6 @@ void m_config_cache_write_opt(struct m_config_cache *cache, void *ptr); // Like m_config_cache_alloc(), but return the struct (m_config_cache->opts) // directly, with no way to update the config. Basically this returns a copy // with a snapshot of the current option values. -// group==GLOBAL_CONFIG is a special case, and always returns the root group. void *mp_get_config_group(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); diff --git a/options/options.c b/options/options.c index 6437dc81c5..ee226843c2 100644 --- a/options/options.c +++ b/options/options.c @@ -318,7 +318,7 @@ const struct m_sub_options filter_conf = { #undef OPT_BASE_STRUCT #define OPT_BASE_STRUCT struct MPOpts -const m_option_t mp_opts[] = { +static const m_option_t mp_opts[] = { // handled in command line pre-parser (parse_commandline.c) {"v", &m_option_type_dummy_flag, CONF_NOCFG | M_OPT_NOPROP, .offset = -1}, @@ -896,7 +896,7 @@ const m_option_t mp_opts[] = { {0} }; -const struct MPOpts mp_default_opts = { +static const struct MPOpts mp_default_opts = { .use_terminal = 1, .msg_color = 1, .audio_decoders = NULL, @@ -991,4 +991,10 @@ const struct MPOpts mp_default_opts = { .cuda_device = -1, }; +const struct m_sub_options mp_opt_root = { + .opts = mp_opts, + .size = sizeof(struct MPOpts), + .defaults = &mp_default_opts, +}; + #endif /* MPLAYER_CFG_MPLAYER_H */ diff --git a/options/options.h b/options/options.h index 126e4cb59a..1935888032 100644 --- a/options/options.h +++ b/options/options.h @@ -355,8 +355,6 @@ struct filter_opts { int deinterlace; }; -extern const m_option_t mp_opts[]; -extern const struct MPOpts mp_default_opts; extern const struct m_sub_options vo_sub_opts; extern const struct m_sub_options dvd_conf; extern const struct m_sub_options mp_subtitle_sub_opts; @@ -364,5 +362,6 @@ extern const struct m_sub_options mp_osd_render_sub_opts; extern const struct m_sub_options filter_conf; extern const struct m_sub_options resample_conf; extern const struct m_sub_options stream_conf; +extern const struct m_sub_options mp_opt_root; #endif -- cgit v1.2.3