[vlc-commits] variables: remove HASMIN and HASMAX flags

Rémi Denis-Courmont git at videolan.org
Sat Oct 22 11:14:46 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 22 11:55:52 2016 +0300| [f08b4c6d26b360e428eb9bfc35caf393b31cff51] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f08b4c6d26b360e428eb9bfc35caf393b31cff51
---

 include/vlc_variables.h   |  2 --
 src/misc/variables.c      | 41 ++++++++++++++++-------------------------
 test/src/misc/variables.c | 25 ++++++++++++++++++-------
 3 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index 28e0fd1..842e1d0 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -60,8 +60,6 @@
  * @{
  */
 #define VLC_VAR_HASCHOICE 0x0100
-#define VLC_VAR_HASMIN    0x0200
-#define VLC_VAR_HASMAX    0x0400
 
 #define VLC_VAR_ISCOMMAND 0x2000
 
diff --git a/src/misc/variables.c b/src/misc/variables.c
index ffe5908..c779d34 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -32,6 +32,7 @@
 # include <search.h>
 #endif
 #include <assert.h>
+#include <float.h>
 #include <math.h>
 #include <limits.h>
 
@@ -215,9 +216,9 @@ static void CheckValue(variable_t *var, vlc_value_t *val)
     switch (var->i_type & VLC_VAR_TYPE)
     {
         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;
-            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;
             if (var->step.i_int != 0 && (val->i_int % var->step.i_int))
                 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)
             break;
 
         case VLC_VAR_FLOAT:
-            if ((var->i_type & VLC_VAR_HASMIN)
-             && isless(val->f_float, var->min.f_float))
+            if (isless(val->f_float, var->min.f_float))
                 val->f_float = var->min.f_float;
-            if ((var->i_type & VLC_VAR_HASMAX)
-             && isgreater(val->f_float, var->max.f_float))
+            if (isgreater(val->f_float, var->max.f_float))
                 val->f_float = var->max.f_float;
             if (var->step.f_float != 0.f)
                 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 )
         case VLC_VAR_INTEGER:
             p_var->ops = &int_ops;
             p_var->val.i_int = 0;
+            p_var->min.i_int = INT64_MIN;
+            p_var->max.i_int = INT64_MAX;
             break;
         case VLC_VAR_STRING:
             p_var->ops = &string_ops;
@@ -357,7 +358,9 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
             break;
         case VLC_VAR_FLOAT:
             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;
         case VLC_VAR_COORDS:
             p_var->ops = &coords_ops;
@@ -498,33 +501,23 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
     {
         case VLC_VAR_SETMIN:
             assert(p_var->ops->pf_free == FreeDummy);
-            p_var->i_type |= VLC_VAR_HASMIN;
             p_var->min = *p_val;
             CheckValue( p_var, &p_var->val );
             break;
         case VLC_VAR_GETMIN:
-            if( p_var->i_type & VLC_VAR_HASMIN )
-                *p_val = p_var->min;
-            else
-                ret = VLC_EGENERIC;
+            *p_val = p_var->min;
             break;
         case VLC_VAR_SETMAX:
             assert(p_var->ops->pf_free == FreeDummy);
-            p_var->i_type |= VLC_VAR_HASMAX;
             p_var->max = *p_val;
             CheckValue( p_var, &p_var->val );
             break;
         case VLC_VAR_GETMAX:
-            if( p_var->i_type & VLC_VAR_HASMAX )
-                *p_val = p_var->max;
-            else
-                ret = VLC_EGENERIC;
+            *p_val = p_var->max;
             break;
         case VLC_VAR_SETMINMAX:
             assert(p_var->ops->pf_free == FreeDummy);
-            p_var->i_type |= VLC_VAR_HASMIN;
             p_var->min = *p_val;
-            p_var->i_type |= VLC_VAR_HASMAX;
             p_var->max = *p_val2;
             break;
         case VLC_VAR_SETSTEP:
@@ -536,20 +529,18 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
             switch (p_var->i_type & VLC_VAR_TYPE)
             {
                 case VLC_VAR_INTEGER:
-                    if (p_var->step.i_int != 0)
-                        *p_val = p_var->step;
-                    else
+                    if (p_var->step.i_int == 0)
                         ret = VLC_EGENERIC;
                     break;
                 case VLC_VAR_FLOAT:
-                    if (p_var->step.f_float != 0.f)
-                        *p_val = p_var->step;
-                    else
+                    if (p_var->step.f_float == 0.f)
                         ret = VLC_EGENERIC;
                     break;
                 default:
                     ret = VLC_EGENERIC;
             }
+            if (ret == VLC_SUCCESS)
+                *p_val = p_var->step;
             break;
         case VLC_VAR_ADDCHOICE:
         {
diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c
index b8cebe3..c4525cc 100644
--- a/test/src/misc/variables.c
+++ b/test/src/misc/variables.c
@@ -285,7 +285,9 @@ static void test_limits( libvlc_int_t *p_libvlc )
     var_Create( p_libvlc, "bla", VLC_VAR_INTEGER );
 
     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;
     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 )
     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_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 );
-    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 );
-    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 );
+    val.i_int = 4212;
     var_Change( p_libvlc, "bla", VLC_VAR_SETSTEP, &val, NULL );
     assert( var_Change( p_libvlc, "bla" , VLC_VAR_GETSTEP, &val, NULL ) == 0
          && val.i_int == 4212 );
@@ -427,9 +438,9 @@ static void test_creation_and_type( libvlc_int_t *p_libvlc )
     var_Create( p_libvlc, "bla", VLC_VAR_INTEGER );
     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_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_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" );
@@ -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_SETSTEP, &val, NULL );
     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_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" );



More information about the vlc-commits mailing list