Commit f08b4c6d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

variables: remove HASMIN and HASMAX flags

Scalar types always have limits. As of the previous commit, those flags
are no longer used externally anyway.
parent 229a415f
...@@ -60,8 +60,6 @@ ...@@ -60,8 +60,6 @@
* @{ * @{
*/ */
#define VLC_VAR_HASCHOICE 0x0100 #define VLC_VAR_HASCHOICE 0x0100
#define VLC_VAR_HASMIN 0x0200
#define VLC_VAR_HASMAX 0x0400
#define VLC_VAR_ISCOMMAND 0x2000 #define VLC_VAR_ISCOMMAND 0x2000
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
# include <search.h> # include <search.h>
#endif #endif
#include <assert.h> #include <assert.h>
#include <float.h>
#include <math.h> #include <math.h>
#include <limits.h> #include <limits.h>
...@@ -215,9 +216,9 @@ static void CheckValue(variable_t *var, vlc_value_t *val) ...@@ -215,9 +216,9 @@ static void CheckValue(variable_t *var, vlc_value_t *val)
switch (var->i_type & VLC_VAR_TYPE) switch (var->i_type & VLC_VAR_TYPE)
{ {
case VLC_VAR_INTEGER: case VLC_VAR_INTEGER:
if ((var->i_type & VLC_VAR_HASMIN) && val->i_int < var->min.i_int) if (val->i_int < var->min.i_int)
val->i_int = var->min.i_int; val->i_int = var->min.i_int;
if ((var->i_type & VLC_VAR_HASMAX) && val->i_int > var->max.i_int) if (val->i_int > var->max.i_int)
val->i_int = var->max.i_int; val->i_int = var->max.i_int;
if (var->step.i_int != 0 && (val->i_int % var->step.i_int)) if (var->step.i_int != 0 && (val->i_int % var->step.i_int))
val->i_int = (val->i_int + (var->step.i_int / 2)) val->i_int = (val->i_int + (var->step.i_int / 2))
...@@ -225,11 +226,9 @@ static void CheckValue(variable_t *var, vlc_value_t *val) ...@@ -225,11 +226,9 @@ static void CheckValue(variable_t *var, vlc_value_t *val)
break; break;
case VLC_VAR_FLOAT: case VLC_VAR_FLOAT:
if ((var->i_type & VLC_VAR_HASMIN) if (isless(val->f_float, var->min.f_float))
&& isless(val->f_float, var->min.f_float))
val->f_float = var->min.f_float; val->f_float = var->min.f_float;
if ((var->i_type & VLC_VAR_HASMAX) if (isgreater(val->f_float, var->max.f_float))
&& isgreater(val->f_float, var->max.f_float))
val->f_float = var->max.f_float; val->f_float = var->max.f_float;
if (var->step.f_float != 0.f) if (var->step.f_float != 0.f)
val->f_float = var->step.f_float val->f_float = var->step.f_float
...@@ -350,6 +349,8 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) ...@@ -350,6 +349,8 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
case VLC_VAR_INTEGER: case VLC_VAR_INTEGER:
p_var->ops = &int_ops; p_var->ops = &int_ops;
p_var->val.i_int = 0; p_var->val.i_int = 0;
p_var->min.i_int = INT64_MIN;
p_var->max.i_int = INT64_MAX;
break; break;
case VLC_VAR_STRING: case VLC_VAR_STRING:
p_var->ops = &string_ops; p_var->ops = &string_ops;
...@@ -357,7 +358,9 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) ...@@ -357,7 +358,9 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
break; break;
case VLC_VAR_FLOAT: case VLC_VAR_FLOAT:
p_var->ops = &float_ops; p_var->ops = &float_ops;
p_var->val.f_float = 0.0; p_var->val.f_float = 0.f;
p_var->min.f_float = FLT_MIN;
p_var->max.f_float = FLT_MAX;
break; break;
case VLC_VAR_COORDS: case VLC_VAR_COORDS:
p_var->ops = &coords_ops; p_var->ops = &coords_ops;
...@@ -498,33 +501,23 @@ int var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -498,33 +501,23 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
{ {
case VLC_VAR_SETMIN: case VLC_VAR_SETMIN:
assert(p_var->ops->pf_free == FreeDummy); assert(p_var->ops->pf_free == FreeDummy);
p_var->i_type |= VLC_VAR_HASMIN;
p_var->min = *p_val; p_var->min = *p_val;
CheckValue( p_var, &p_var->val ); CheckValue( p_var, &p_var->val );
break; break;
case VLC_VAR_GETMIN: case VLC_VAR_GETMIN:
if( p_var->i_type & VLC_VAR_HASMIN ) *p_val = p_var->min;
*p_val = p_var->min;
else
ret = VLC_EGENERIC;
break; break;
case VLC_VAR_SETMAX: case VLC_VAR_SETMAX:
assert(p_var->ops->pf_free == FreeDummy); assert(p_var->ops->pf_free == FreeDummy);
p_var->i_type |= VLC_VAR_HASMAX;
p_var->max = *p_val; p_var->max = *p_val;
CheckValue( p_var, &p_var->val ); CheckValue( p_var, &p_var->val );
break; break;
case VLC_VAR_GETMAX: case VLC_VAR_GETMAX:
if( p_var->i_type & VLC_VAR_HASMAX ) *p_val = p_var->max;
*p_val = p_var->max;
else
ret = VLC_EGENERIC;
break; break;
case VLC_VAR_SETMINMAX: case VLC_VAR_SETMINMAX:
assert(p_var->ops->pf_free == FreeDummy); assert(p_var->ops->pf_free == FreeDummy);
p_var->i_type |= VLC_VAR_HASMIN;
p_var->min = *p_val; p_var->min = *p_val;
p_var->i_type |= VLC_VAR_HASMAX;
p_var->max = *p_val2; p_var->max = *p_val2;
break; break;
case VLC_VAR_SETSTEP: case VLC_VAR_SETSTEP:
...@@ -536,20 +529,18 @@ int var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -536,20 +529,18 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
switch (p_var->i_type & VLC_VAR_TYPE) switch (p_var->i_type & VLC_VAR_TYPE)
{ {
case VLC_VAR_INTEGER: case VLC_VAR_INTEGER:
if (p_var->step.i_int != 0) if (p_var->step.i_int == 0)
*p_val = p_var->step;
else
ret = VLC_EGENERIC; ret = VLC_EGENERIC;
break; break;
case VLC_VAR_FLOAT: case VLC_VAR_FLOAT:
if (p_var->step.f_float != 0.f) if (p_var->step.f_float == 0.f)
*p_val = p_var->step;
else
ret = VLC_EGENERIC; ret = VLC_EGENERIC;
break; break;
default: default:
ret = VLC_EGENERIC; ret = VLC_EGENERIC;
} }
if (ret == VLC_SUCCESS)
*p_val = p_var->step;
break; break;
case VLC_VAR_ADDCHOICE: case VLC_VAR_ADDCHOICE:
{ {
......
...@@ -285,7 +285,9 @@ static void test_limits( libvlc_int_t *p_libvlc ) ...@@ -285,7 +285,9 @@ static void test_limits( libvlc_int_t *p_libvlc )
var_Create( p_libvlc, "bla", VLC_VAR_INTEGER ); var_Create( p_libvlc, "bla", VLC_VAR_INTEGER );
var_Change( p_libvlc, "bla", VLC_VAR_GETMIN, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_GETMIN, &val, NULL );
assert( val.i_int == 0 ); assert( val.i_int == INT64_MIN );
var_Change( p_libvlc, "bla", VLC_VAR_GETMAX, &val, NULL );
assert( val.i_int == INT64_MAX );
val.i_int = -1234; val.i_int = -1234;
var_Change( p_libvlc, "bla", VLC_VAR_SETMIN, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETMIN, &val, NULL );
...@@ -394,13 +396,22 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc ) ...@@ -394,13 +396,22 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc )
assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ) == VLC_SUCCESS ); assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ) == VLC_SUCCESS );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND) ); assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND) );
assert( var_Change( p_libvlc, "bla", VLC_VAR_GETMIN, &val, NULL ) != 0
|| val.i_int == INT64_MIN );
val.i_int = 4212;
var_Change( p_libvlc, "bla", VLC_VAR_SETMIN, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETMIN, &val, NULL );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASMIN) ); assert( var_Change( p_libvlc, "bla", VLC_VAR_GETMIN, &val, NULL ) == 0
&& val.i_int == 4212 );
assert( var_Change( p_libvlc, "bla", VLC_VAR_GETMAX, &val, NULL ) != 0
|| val.i_int == INT64_MAX );
val.i_int = 4212;
var_Change( p_libvlc, "bla", VLC_VAR_SETMAX, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETMAX, &val, NULL );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASMIN | VLC_VAR_HASMAX) ); assert( var_Change( p_libvlc, "bla", VLC_VAR_GETMAX, &val, NULL ) == 0
&& val.i_int == 4212 );
assert( var_Change( p_libvlc, "bla" , VLC_VAR_GETSTEP, &val, NULL ) != 0 ); assert( var_Change( p_libvlc, "bla" , VLC_VAR_GETSTEP, &val, NULL ) != 0 );
val.i_int = 4212;
var_Change( p_libvlc, "bla", VLC_VAR_SETSTEP, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETSTEP, &val, NULL );
assert( var_Change( p_libvlc, "bla" , VLC_VAR_GETSTEP, &val, NULL ) == 0 assert( var_Change( p_libvlc, "bla" , VLC_VAR_GETSTEP, &val, NULL ) == 0
&& val.i_int == 4212 ); && val.i_int == 4212 );
...@@ -427,9 +438,9 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc ) ...@@ -427,9 +438,9 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc )
var_Create( p_libvlc, "bla", VLC_VAR_INTEGER ); var_Create( p_libvlc, "bla", VLC_VAR_INTEGER );
var_Change( p_libvlc, "bla", VLC_VAR_SETMIN, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETMIN, &val, NULL );
assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ) == VLC_SUCCESS ); assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ) == VLC_SUCCESS );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASMIN) ); assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND) );
assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ) == VLC_SUCCESS ); assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ) == VLC_SUCCESS );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASMIN | VLC_VAR_HASCHOICE) ); assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE) );
var_Destroy( p_libvlc, "bla" ); var_Destroy( p_libvlc, "bla" );
var_Destroy( p_libvlc, "bla" ); var_Destroy( p_libvlc, "bla" );
...@@ -440,9 +451,9 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc ) ...@@ -440,9 +451,9 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc )
var_Change( p_libvlc, "bla", VLC_VAR_SETMAX, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETMAX, &val, NULL );
var_Change( p_libvlc, "bla", VLC_VAR_SETSTEP, &val, NULL ); var_Change( p_libvlc, "bla", VLC_VAR_SETSTEP, &val, NULL );
assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ) == VLC_SUCCESS ); assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND ) == VLC_SUCCESS );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASMAX) ); assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND) );
assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ) == VLC_SUCCESS ); assert( var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE ) == VLC_SUCCESS );
assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASMAX | VLC_VAR_HASCHOICE) ); assert( var_Type( p_libvlc, "bla" ) == (VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE) );
var_Destroy( p_libvlc, "bla" ); var_Destroy( p_libvlc, "bla" );
var_Destroy( p_libvlc, "bla" ); var_Destroy( p_libvlc, "bla" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment