mirror of
https://github.com/mpv-player/mpv
synced 2024-08-20 08:55:06 +02:00
m_property: remove pointless explicitly clamping
This is basically dead code, and even the commit that added this code 4 years ago said that this should be for debugging only. (Though it is possible that the clamp callback was used for something else, and then unused again. Also, some of the clamping code remains and is used for internal checking, e.g. clamp_double().)
This commit is contained in:
parent
f519887fe7
commit
ce8dae3f0d
@ -133,14 +133,6 @@ static void copy_opt(const m_option_t *opt, void *dst, const void *src)
|
||||
|
||||
#define VAL(x) (*(int *)(x))
|
||||
|
||||
static int clamp_flag(const m_option_t *opt, void *val)
|
||||
{
|
||||
if (VAL(val) == 0 || VAL(val) == 1)
|
||||
return 0;
|
||||
VAL(val) = 0;
|
||||
return M_OPT_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
static int parse_flag(struct mp_log *log, const m_option_t *opt,
|
||||
struct bstr name, struct bstr param, void *dst)
|
||||
{
|
||||
@ -202,7 +194,6 @@ const m_option_type_t m_option_type_flag = {
|
||||
.print = print_flag,
|
||||
.copy = copy_opt,
|
||||
.add = add_flag,
|
||||
.clamp = clamp_flag,
|
||||
.set = flag_set,
|
||||
.get = flag_get,
|
||||
};
|
||||
@ -336,14 +327,6 @@ static int parse_longlong(struct mp_log *log, const m_option_t *opt,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int clamp_int(const m_option_t *opt, void *val)
|
||||
{
|
||||
long long tmp = *(int *)val;
|
||||
int r = clamp_longlong(opt, &tmp);
|
||||
*(int *)val = tmp;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int clamp_int64(const m_option_t *opt, void *val)
|
||||
{
|
||||
long long tmp = *(int64_t *)val;
|
||||
@ -475,7 +458,6 @@ const m_option_type_t m_option_type_int = {
|
||||
.copy = copy_opt,
|
||||
.add = add_int,
|
||||
.multiply = multiply_int,
|
||||
.clamp = clamp_int,
|
||||
.set = int_set,
|
||||
.get = int_get,
|
||||
};
|
||||
@ -488,7 +470,6 @@ const m_option_type_t m_option_type_int64 = {
|
||||
.copy = copy_opt,
|
||||
.add = add_int64,
|
||||
.multiply = multiply_int64,
|
||||
.clamp = clamp_int64,
|
||||
.set = int64_set,
|
||||
.get = int64_get,
|
||||
};
|
||||
@ -546,21 +527,6 @@ const char *m_opt_choice_str(const struct m_opt_choice_alternatives *choices,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int clamp_choice(const m_option_t *opt, void *val)
|
||||
{
|
||||
int v = *(int *)val;
|
||||
if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) {
|
||||
if (v >= opt->min && v <= opt->max)
|
||||
return 0;
|
||||
}
|
||||
;
|
||||
for (struct m_opt_choice_alternatives *alt = opt->priv; alt->name; alt++) {
|
||||
if (alt->value == v)
|
||||
return 0;
|
||||
}
|
||||
return M_OPT_INVALID;
|
||||
}
|
||||
|
||||
static int parse_choice(struct mp_log *log, const struct m_option *opt,
|
||||
struct bstr name, struct bstr param, void *dst)
|
||||
{
|
||||
@ -750,7 +716,6 @@ const struct m_option_type m_option_type_choice = {
|
||||
.print = print_choice,
|
||||
.copy = copy_opt,
|
||||
.add = add_choice,
|
||||
.clamp = clamp_choice,
|
||||
.set = choice_set,
|
||||
.get = choice_get,
|
||||
};
|
||||
@ -999,7 +964,6 @@ const m_option_type_t m_option_type_double = {
|
||||
.print = print_double,
|
||||
.pretty_print = print_double_f3,
|
||||
.copy = copy_opt,
|
||||
.clamp = clamp_double,
|
||||
.add = add_double,
|
||||
.multiply = multiply_double,
|
||||
.set = double_set,
|
||||
@ -1009,14 +973,6 @@ const m_option_type_t m_option_type_double = {
|
||||
#undef VAL
|
||||
#define VAL(x) (*(float *)(x))
|
||||
|
||||
static int clamp_float(const m_option_t *opt, void *val)
|
||||
{
|
||||
double tmp = VAL(val);
|
||||
int r = clamp_double(opt, &tmp);
|
||||
VAL(val) = tmp;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int parse_float(struct mp_log *log, const m_option_t *opt,
|
||||
struct bstr name, struct bstr param, void *dst)
|
||||
{
|
||||
@ -1078,7 +1034,6 @@ const m_option_type_t m_option_type_float = {
|
||||
.copy = copy_opt,
|
||||
.add = add_float,
|
||||
.multiply = multiply_float,
|
||||
.clamp = clamp_float,
|
||||
.set = float_set,
|
||||
.get = float_get,
|
||||
};
|
||||
@ -1179,7 +1134,6 @@ const m_option_type_t m_option_type_string = {
|
||||
.print = print_str,
|
||||
.copy = copy_str,
|
||||
.free = free_str,
|
||||
.clamp = clamp_str,
|
||||
.set = str_set,
|
||||
.get = str_get,
|
||||
};
|
||||
@ -2462,7 +2416,6 @@ const m_option_type_t m_option_type_time = {
|
||||
.pretty_print = pretty_print_time,
|
||||
.copy = copy_opt,
|
||||
.add = add_double,
|
||||
.clamp = clamp_double,
|
||||
.set = time_set,
|
||||
.get = time_get,
|
||||
};
|
||||
|
@ -291,13 +291,6 @@ struct m_option_type {
|
||||
// to the valid value range of the option.
|
||||
void (*multiply)(const m_option_t *opt, void *val, double f);
|
||||
|
||||
// Clamp the value in val to the option's valid value range.
|
||||
// Return values:
|
||||
// M_OPT_OUT_OF_RANGE: val was invalid, and modified (clamped) to be valid
|
||||
// M_OPT_INVALID: val was invalid, and can't be made valid
|
||||
// 0: val was already valid and is unchanged
|
||||
int (*clamp)(const m_option_t *opt, void *val);
|
||||
|
||||
// Set the option value in dst to the contents of src.
|
||||
// (If the option is dynamic, the old value in *dst has to be freed.)
|
||||
// Return values:
|
||||
|
@ -125,15 +125,6 @@ int m_property_do(struct mp_log *log, const struct m_property *prop_list,
|
||||
return r;
|
||||
}
|
||||
case M_PROPERTY_SET: {
|
||||
if (!log)
|
||||
return M_PROPERTY_ERROR;
|
||||
m_option_copy(&opt, &val, arg);
|
||||
r = opt.type->clamp ? opt.type->clamp(&opt, arg) : 0;
|
||||
m_option_free(&opt, &val);
|
||||
if (r != 0) {
|
||||
mp_err(log, "Property '%s': invalid value.\n", name);
|
||||
return M_PROPERTY_ERROR;
|
||||
}
|
||||
return do_action(prop_list, name, M_PROPERTY_SET, arg, ctx);
|
||||
}
|
||||
case M_PROPERTY_GET_NODE: {
|
||||
|
Loading…
Reference in New Issue
Block a user