[vlc-commits] variables: use char ** for VLC_VAR_GETTEXT

Rémi Denis-Courmont git at videolan.org
Sun Jun 10 12:11:22 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jun  9 14:46:51 2018 +0300| [1b380f31b165f5c2288fb08a76e75c5ac8f13c05] | committer: Rémi Denis-Courmont

variables: use char ** for VLC_VAR_GETTEXT

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

 modules/control/oldrc.c                       | 24 ++++++++++++------------
 modules/gui/macosx/VLCMainMenu.m              |  9 +++++----
 modules/gui/qt/components/extended_panels.cpp |  6 +++---
 modules/gui/qt/menus.cpp                      | 16 +++++++---------
 src/misc/variables.c                          |  4 ++--
 5 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c
index 4a5fdfc0d5..7420e6733a 100644
--- a/modules/control/oldrc.c
+++ b/modules/control/oldrc.c
@@ -1094,7 +1094,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
              || !strcmp( psz_cmd, "strack" ) )
     {
         const char *psz_variable;
-        vlc_value_t val_name;
+        char *name;
 
         if( !strcmp( psz_cmd, "atrack" ) )
         {
@@ -1110,8 +1110,8 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
         }
 
         /* Get the descriptive name of the variable */
-        var_Change( p_input, psz_variable, VLC_VAR_GETTEXT, &val_name );
-        if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
+        var_Change( p_input, psz_variable, VLC_VAR_GETTEXT, &name );
+        if( !name ) name = strdup(psz_variable);
 
         if( newval.psz_string && *newval.psz_string )
         {
@@ -1133,7 +1133,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                 goto out;
             }
 
-            msg_rc( "+----[ %s ]", val_name.psz_string );
+            msg_rc( "+----[ %s ]", name );
             for ( int i = 0; i < val.i_count; i++ )
             {
                 if ( i_value == val.p_values[i].i_int )
@@ -1144,9 +1144,9 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                             text.p_values[i].psz_string );
             }
             var_FreeList( &val, &text );
-            msg_rc( "+----[ end of %s ]", val_name.psz_string );
+            msg_rc( "+----[ end of %s ]", name );
         }
-        free( val_name.psz_string );
+        free( name );
     }
 out:
     vlc_object_release( p_input );
@@ -1555,7 +1555,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
     else
     {
         /* get */
-        vlc_value_t val_name;
+        char *name;
         vlc_list_t val, text;
         float f_value = 0.;
         char *psz_value = NULL;
@@ -1581,10 +1581,10 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
         }
 
         /* Get the descriptive name of the variable */
-        var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT, &val_name );
-        if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
+        var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT, &name );
+        if( !name ) name = strdup(psz_variable);
 
-        msg_rc( "+----[ %s ]", val_name.psz_string );
+        msg_rc( "+----[ %s ]", name );
         if( !strcmp( psz_variable, "zoom" ) )
         {
             for ( int i = 0; i < val.i_count; i++ )
@@ -1611,9 +1611,9 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
             free( psz_value );
         }
         var_FreeList( &val, &text );
-        msg_rc( "+----[ end of %s ]", val_name.psz_string );
+        msg_rc( "+----[ end of %s ]", name );
 
-        free( val_name.psz_string );
+        free( name );
     }
     vlc_object_release( p_vout );
     return i_error;
diff --git a/modules/gui/macosx/VLCMainMenu.m b/modules/gui/macosx/VLCMainMenu.m
index 8449dec701..1ca3eda65d 100644
--- a/modules/gui/macosx/VLCMainMenu.m
+++ b/modules/gui/macosx/VLCMainMenu.m
@@ -1383,7 +1383,8 @@
                      var:(const char *)psz_variable
                 selector:(SEL)pf_callback
 {
-    vlc_value_t val, text;
+    vlc_value_t val;
+    char *text;
     int i_type = var_Type(p_object, psz_variable);
 
     switch(i_type & VLC_VAR_TYPE) {
@@ -1400,7 +1401,7 @@
 
     /* Get the descriptive name of the variable */
     var_Change(p_object, psz_variable, VLC_VAR_GETTEXT, &text);
-    [mi setTitle: _NS(text.psz_string ? text.psz_string : psz_variable)];
+    [mi setTitle: _NS(text ? text : psz_variable)];
 
     if (i_type & VLC_VAR_HASCHOICE) {
         NSMenu *menu = [mi submenu];
@@ -1408,7 +1409,7 @@
         [self setupVarMenu:menu forMenuItem:mi target:p_object
                        var:psz_variable selector:pf_callback];
 
-        free(text.psz_string);
+        free(text);
         return;
     }
 
@@ -1436,7 +1437,7 @@
     }
 
     if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
-    free(text.psz_string);
+    free(text);
 }
 
 
diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index c429bee753..25b192ffdd 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -669,14 +669,14 @@ void ExtV4l2::Refresh( void )
 
         for( int i = 0; i < val.i_count; i++ )
         {
-            vlc_value_t vartext;
+            char *vartext;
             const char *psz_var = text.p_values[i].psz_string;
 
             if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext ) )
                 continue;
 
-            QString name = qtr( vartext.psz_string );
-            free( vartext.psz_string );
+            QString name = qtr( vartext );
+            free( vartext );
             msg_Dbg( p_intf, "v4l2 control \"%" PRIx64 "\": %s (%s)",
                      val.p_values[i].i_int, psz_var, qtu( name ) );
 
diff --git a/modules/gui/qt/menus.cpp b/modules/gui/qt/menus.cpp
index 99958ab62e..a848feb0a4 100644
--- a/modules/gui/qt/menus.cpp
+++ b/modules/gui/qt/menus.cpp
@@ -1244,12 +1244,13 @@ static bool IsMenuEmpty( const char *psz_var, vlc_object_t *p_object )
     return val <= 1;
 }
 
-#define TEXT_OR_VAR qfue ( text.psz_string ? text.psz_string : psz_var )
+#define TEXT_OR_VAR qfue ( text ? text : psz_var )
 
 void VLCMenuBar::UpdateItem( QMenu *menu,
         const char *psz_var, vlc_object_t *p_object, bool b_submenu )
 {
-    vlc_value_t val, text;
+    vlc_value_t val;
+    char *text;
     int i_type;
 
     QAction *action = FindActionWithVar( menu, psz_var );
@@ -1299,11 +1300,8 @@ void VLCMenuBar::UpdateItem( QMenu *menu,
     }
 
     /* Get the descriptive name of the variable */
-    int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text );
-    if( i_ret != VLC_SUCCESS )
-    {
-        text.psz_string = NULL;
-    }
+    if( var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text ) )
+        text = NULL;
 
     if( !action )
     {
@@ -1333,7 +1331,7 @@ void VLCMenuBar::UpdateItem( QMenu *menu,
             action->setEnabled(
                 CreateChoicesMenu( menu, psz_var, p_object ) == 0 );
         }
-        FREENULL( text.psz_string );
+        free( text );
         return;
     }
     else
@@ -1354,7 +1352,7 @@ void VLCMenuBar::UpdateItem( QMenu *menu,
                     p_object, val, i_type, !val.b_bool );
             break;
     }
-    FREENULL( text.psz_string );
+    free( text );
 }
 
 #undef TEXT_OR_VAR
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 83498dadc5..273d17d3c2 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -590,8 +590,8 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name, int i_action, ...)
             break;
         }
         case VLC_VAR_GETTEXT:
-            va_arg(ap, vlc_value_t *)->psz_string =
-                p_var->psz_text ? strdup( p_var->psz_text ) : NULL;
+            *va_arg(ap, char **) = (p_var->psz_text != NULL)
+                ? strdup(p_var->psz_text) : NULL;
             break;
         default:
             break;



More information about the vlc-commits mailing list