diff options
author | wm4 <wm4@nowhere> | 2020-03-13 16:49:39 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-03-13 17:34:46 +0100 |
commit | 8d965a1bfb3782343a03cff44977f11bb920f0b1 (patch) | |
tree | 2d115c24510ab36cc9ac7af8dea2b710537561c9 /options/m_option.h | |
parent | 5d5a7e19537a036fe16ce04555e6ce9449c47494 (diff) | |
download | mpv-8d965a1bfb3782343a03cff44977f11bb920f0b1.tar.bz2 mpv-8d965a1bfb3782343a03cff44977f11bb920f0b1.tar.xz |
options: change how option range min/max is handled
Before this commit, option declarations used M_OPT_MIN/M_OPT_MAX (and
some other identifiers based on these) to signal whether an option had
min/max values. Remove these flags, and make it use a range implicitly
on the condition if min<max is true.
This requires care in all cases when only M_OPT_MIN or M_OPT_MAX were
set (instead of both). Generally, the commit replaces all these
instances with using DBL_MAX/DBL_MIN for the "unset" part of the range.
This also happens to fix some cases where you could pass over-large
values to integer options, which were silently truncated, but now cause
an error.
This commit has some higher potential for regressions.
Diffstat (limited to 'options/m_option.h')
-rw-r--r-- | options/m_option.h | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/options/m_option.h b/options/m_option.h index 9ee103bd94..8d7063c212 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -18,6 +18,7 @@ #ifndef MPLAYER_M_OPTION_H #define MPLAYER_M_OPTION_H +#include <float.h> #include <string.h> #include <stddef.h> #include <stdbool.h> @@ -361,13 +362,14 @@ struct m_option { int offset; - // \brief Mostly useful for numeric types, the \ref M_OPT_MIN flags must - // also be set. - double min; - - // \brief Mostly useful for numeric types, the \ref M_OPT_MAX flags must - // also be set. - double max; + // Most numeric types restrict the range to [min, max] if min<max (this + // implies that if min/max are not set, the full range is used). In all + // cases, the actual range is clamped to the type's native range. + // Float types use [DBL_MIN, DBL_MAX], though by setting min or max to + // -/+INFINITY, the range can be extended to INFINITY. (This part is buggy + // for "float".) + // Some types will abuse the min or max field for unrelated things. + double min, max; // Type dependent data (for all kinds of extended settings). void *priv; @@ -382,15 +384,6 @@ struct m_option { char *format_file_size(int64_t size); -// The option has a minimum set in \ref m_option::min. -#define M_OPT_MIN (1 << 0) - -// The option has a maximum set in \ref m_option::max. -#define M_OPT_MAX (1 << 1) - -// The option has a minimum and maximum in m_option::min and m_option::max. -#define M_OPT_RANGE (M_OPT_MIN | M_OPT_MAX) - // The option is forbidden in config files. #define M_OPT_NOCFG (1 << 2) @@ -436,9 +429,6 @@ char *format_file_size(int64_t size); #define M_OPT_OPTIONAL_PARAM (1 << 30) // These are kept for compatibility with older code. -#define CONF_MIN M_OPT_MIN -#define CONF_MAX M_OPT_MAX -#define CONF_RANGE M_OPT_RANGE #define CONF_NOCFG M_OPT_NOCFG #define CONF_PRE_PARSE M_OPT_PRE_PARSE @@ -455,6 +445,9 @@ char *format_file_size(int64_t size); // might be allowed too). E.g. m_option_type_choice and m_option_type_flag. #define M_OPT_TYPE_CHOICE (1 << 1) +// When m_option.min/max are set, they denote a value range. +#define M_OPT_TYPE_USES_RANGE (1 << 2) + ///////////////////////////// Parser flags ///////////////////////////////// // OptionParserReturn @@ -621,7 +614,7 @@ extern const char m_option_path_separator; OPT_GENERAL(int64_t, __VA_ARGS__, .type = &m_option_type_int64) #define OPT_RANGE_(ctype, optname, varname, flags, minval, maxval, ...) \ - OPT_GENERAL(ctype, optname, varname, (flags) | CONF_RANGE, \ + OPT_GENERAL(ctype, optname, varname, flags, \ .min = minval, .max = maxval, __VA_ARGS__) #define OPT_INTRANGE(...) \ @@ -679,7 +672,7 @@ extern const char m_option_path_separator; // Union of choices and an int range. The choice values can be included in the // int range, or be completely separate - both works. #define OPT_CHOICE_OR_INT_(optname, varname, flags, minval, maxval, choices, ...) \ - OPT_GENERAL(int, optname, varname, (flags) | CONF_RANGE, \ + OPT_GENERAL(int, optname, varname, flags, \ .min = minval, .max = maxval, \ M_CHOICES(choices), __VA_ARGS__) #define OPT_CHOICE_OR_INT(...) \ |