summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-10-25 15:31:47 +0200
committerwm4 <wm4@nowhere>2013-10-25 18:39:15 +0200
commit75e1c6f295ff9c0631371b6565c1d20e8f2da8b6 (patch)
treeae7cbf0114807ebb0fa8ecfd2bd64f9400d860c6 /mpvcore
parentcb3327fe48a35b20900c9ad47ddf4c17486a1e04 (diff)
downloadmpv-75e1c6f295ff9c0631371b6565c1d20e8f2da8b6.tar.bz2
mpv-75e1c6f295ff9c0631371b6565c1d20e8f2da8b6.tar.xz
m_config: allow not allocating option struct, and use it
In cases we're just listing options or checking their values (as it happens with -vo/-vf etc. suboption parsing), we don't need to allocate abd initialize the actual option struct. All we're interested in is the list of options.
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/m_config.c23
-rw-r--r--mpvcore/m_config.h4
-rw-r--r--mpvcore/m_option.c4
3 files changed, 23 insertions, 8 deletions
diff --git a/mpvcore/m_config.c b/mpvcore/m_config.c
index 3fd4056b56..66e5da25b7 100644
--- a/mpvcore/m_config.c
+++ b/mpvcore/m_config.c
@@ -198,13 +198,14 @@ struct m_config *m_config_new(void *talloc_parent, size_t size,
.optstruct_defaults = defaults,
.options = options,
};
- if (size) { // size==0 means a dummy object is created
+ // size==0 means a dummy object is created
+ if (size) {
config->optstruct = talloc_zero_size(config, size);
if (defaults)
memcpy(config->optstruct, defaults, size);
- if (options)
- add_options(config, "", config->optstruct, defaults, options);
}
+ if (options)
+ add_options(config, "", config->optstruct, defaults, options);
return config;
}
@@ -215,6 +216,13 @@ struct m_config *m_config_from_obj_desc(void *talloc_parent,
desc->options);
}
+// Like m_config_from_obj_desc(), but don't allocate option struct.
+struct m_config *m_config_from_obj_desc_noalloc(void *talloc_parent,
+ struct m_obj_desc *desc)
+{
+ return m_config_new(talloc_parent, 0, desc->priv_defaults, desc->options);
+}
+
int m_config_set_obj_params(struct m_config *conf, char **args)
{
for (int n = 0; args && args[n * 2 + 0]; n++) {
@@ -390,7 +398,7 @@ static void m_config_add_option(struct m_config *config,
if (arg->defval)
co.default_data = arg->defval;
- if (co.data && !co.default_data)
+ if (!co.default_data)
co.default_data = &default_value;
// Fill in the full name
@@ -405,8 +413,11 @@ static void m_config_add_option(struct m_config *config,
if (arg->type->flags & M_OPT_TYPE_USE_SUBSTRUCT) {
const struct m_sub_options *subopts = arg->priv;
- void *new_optstruct = m_config_alloc_struct(config, subopts);
- substruct_write_ptr(co.data, new_optstruct);
+ void *new_optstruct = NULL;
+ if (co.data) {
+ new_optstruct = m_config_alloc_struct(config, subopts);
+ substruct_write_ptr(co.data, new_optstruct);
+ }
const void *new_optstruct_def = substruct_read_ptr(co.default_data);
if (!new_optstruct_def)
diff --git a/mpvcore/m_config.h b/mpvcore/m_config.h
index c5d1d35e49..3d82d8cd24 100644
--- a/mpvcore/m_config.h
+++ b/mpvcore/m_config.h
@@ -73,6 +73,7 @@ typedef struct m_config {
// Create a new config object.
// talloc_parent: 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
@@ -86,6 +87,9 @@ struct m_config *m_config_new(void *talloc_parent, size_t size,
struct m_config *m_config_from_obj_desc(void *talloc_parent,
struct m_obj_desc *desc);
+struct m_config *m_config_from_obj_desc_noalloc(void *talloc_parent,
+ struct m_obj_desc *desc);
+
int m_config_set_obj_params(struct m_config *conf, char **args);
// Initialize an object (VO/VF/...) in one go, including legacy handling.
diff --git a/mpvcore/m_option.c b/mpvcore/m_option.c
index 095e86a2b5..cd88b4cdca 100644
--- a/mpvcore/m_option.c
+++ b/mpvcore/m_option.c
@@ -2140,7 +2140,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
}
if (_ret && desc.init_options) {
- struct m_config *config = m_config_from_obj_desc(NULL, &desc);
+ struct m_config *config = m_config_from_obj_desc_noalloc(NULL, &desc);
bstr s = bstr0(desc.init_options);
m_obj_parse_sub_config(opt, str, &s, config,
M_SETOPT_CHECK_ONLY, &plist);
@@ -2169,7 +2169,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr,
} else {
struct m_config *config = NULL;
if (!skip)
- config = m_config_from_obj_desc(NULL, &desc);
+ config = m_config_from_obj_desc_noalloc(NULL, &desc);
r = m_obj_parse_sub_config(opt, str, pstr, config,
M_SETOPT_CHECK_ONLY,
_ret ? &plist : NULL);