Skip to content

Commit

Permalink
m_option: remove M_OPT_TYPE_DYNAMIC flag
Browse files Browse the repository at this point in the history
It's actually redundant with whether m_option_type.free is set. Some
option types were flagged inconsistently. Its only use was for running
an additional sanity check without any real functionality.
  • Loading branch information
wm4 committed Aug 30, 2016
1 parent 6f6d2eb commit 3bb1349
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion options/m_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static void m_config_add_option(struct m_config *config,
} else {
// Initialize options
if (co.data && co.default_data) {
if (arg->type->flags & M_OPT_TYPE_DYNAMIC) {
if (arg->type->free) {
// Would leak memory by overwriting *co.data repeatedly.
for (int i = 0; i < config->num_opts; i++) {
if (co.data == config->opts[i].data)
Expand Down
9 changes: 2 additions & 7 deletions options/m_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,6 @@ static void free_str(void *src)
const m_option_type_t m_option_type_string = {
.name = "String",
.size = sizeof(char *),
.flags = M_OPT_TYPE_DYNAMIC,
.parse = parse_str,
.print = print_str,
.copy = copy_str,
Expand Down Expand Up @@ -1486,7 +1485,7 @@ const m_option_type_t m_option_type_string_list = {
*/
.name = "String list",
.size = sizeof(char **),
.flags = M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD,
.flags = M_OPT_TYPE_ALLOW_WILDCARD,
.parse = parse_str_list,
.print = print_str_list,
.copy = copy_str_list,
Expand Down Expand Up @@ -1522,7 +1521,6 @@ static int parse_str_append_list(struct mp_log *log, const m_option_t *opt,
const m_option_type_t m_option_type_string_append_list = {
.name = "String list",
.size = sizeof(char **),
.flags = M_OPT_TYPE_DYNAMIC,
.parse = parse_str_append_list,
.print = print_str_list,
.copy = copy_str_list,
Expand Down Expand Up @@ -1636,7 +1634,6 @@ static int keyvalue_list_get(const m_option_t *opt, void *ta_parent,
const m_option_type_t m_option_type_keyvalue_list = {
.name = "Key/value list",
.size = sizeof(char **),
.flags = M_OPT_TYPE_DYNAMIC,
.parse = parse_keyvalue_list,
.print = print_keyvalue_list,
.copy = copy_str_list,
Expand Down Expand Up @@ -1703,7 +1700,6 @@ static int set_msglevels(const m_option_t *opt, void *dst,
const m_option_type_t m_option_type_msglevels = {
.name = "Output verbosity levels",
.size = sizeof(char **),
.flags = M_OPT_TYPE_DYNAMIC,
.parse = parse_msglevels,
.print = print_keyvalue_list,
.copy = copy_str_list,
Expand Down Expand Up @@ -3284,7 +3280,7 @@ static int get_obj_settings_list(const m_option_t *opt, void *ta_parent,
const m_option_type_t m_option_type_obj_settings_list = {
.name = "Object settings list",
.size = sizeof(m_obj_settings_t *),
.flags = M_OPT_TYPE_DYNAMIC | M_OPT_TYPE_ALLOW_WILDCARD,
.flags = M_OPT_TYPE_ALLOW_WILDCARD,
.parse = parse_obj_settings_list,
.print = print_obj_settings_list,
.copy = copy_obj_settings_list,
Expand Down Expand Up @@ -3405,7 +3401,6 @@ static int node_get(const m_option_t *opt, void *ta_parent,
const m_option_type_t m_option_type_node = {
.name = "Complex",
.size = sizeof(struct mpv_node),
.flags = M_OPT_TYPE_DYNAMIC,
.parse = parse_node,
.print = print_node,
.copy = copy_node,
Expand Down
10 changes: 1 addition & 9 deletions options/m_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,19 +403,11 @@ struct m_option {
*/
#define M_OPT_TYPE_ALLOW_WILDCARD (1 << 1)

// Dynamic data type.
/** This flag indicates that the data is dynamically allocated (m_option::p
* points to a pointer). It enables a little hack in the \ref Config which
* replaces the initial value of such variables with a dynamic copy in case
* the initial value is statically allocated (pretty common with strings).
*/
#define M_OPT_TYPE_DYNAMIC (1 << 2)

// The parameter is optional and by default no parameter is preferred. If
// ambiguous syntax is used ("--opt value"), the command line parser will
// assume that the argument takes no parameter. In config files, these
// options can be used without "=" and value.
#define M_OPT_TYPE_OPTIONAL_PARAM (1 << 3)
#define M_OPT_TYPE_OPTIONAL_PARAM (1 << 2)

///////////////////////////// Parser flags /////////////////////////////////

Expand Down

0 comments on commit 3bb1349

Please sign in to comment.