[vlc-commits] variables: inline var_FreeList() in simple loops

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 10 11:36:33 2018 +0300| [704887466867cfd854c87f4ddd01b22514d059af] | committer: Rémi Denis-Courmont

variables: inline var_FreeList() in simple loops

This works like config choices.

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

 modules/control/oldrc.c                         | 42 ++++++++++++-------------
 modules/gui/macosx/VLCMainMenu.m                |  7 ++++-
 modules/gui/qt/components/controller_widget.cpp |  7 ++++-
 modules/gui/qt/components/extended_panels.cpp   | 23 +++++++++-----
 modules/gui/qt/menus.cpp                        |  5 ++-
 modules/lua/libs/variables.c                    |  6 +++-
 test/src/misc/variables.c                       |  4 ++-
 7 files changed, 59 insertions(+), 35 deletions(-)

diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c
index 6a03c6108f..2e92a31f06 100644
--- a/modules/control/oldrc.c
+++ b/modules/control/oldrc.c
@@ -1138,14 +1138,12 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
             msg_rc( "+----[ %s ]", name );
             for ( size_t i = 0; i < count; i++ )
             {
-                if ( i_value == val.p_values[i].i_int )
-                    msg_rc( "| %"PRId64" - %s *", val.p_values[i].i_int,
-                            text[i] );
-                else
-                    msg_rc( "| %"PRId64" - %s", val.p_values[i].i_int,
-                            text[i] );
+                msg_rc( "| %"PRId64" - %s%s", val.p_values[i].i_int, text[i],
+                        (i_value == val.p_values[i].i_int) ? " *" : "" );
+                free(text[i]);
             }
-            var_FreeList( &val, &text );
+            free(text);
+            free(val.p_values);
             msg_rc( "+----[ end of %s ]", name );
         }
         free( name );
@@ -1593,25 +1591,25 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
         {
             for ( size_t i = 0; i < count; i++ )
             {
-                if ( f_value == val.p_values[i].f_float )
-                    msg_rc( "| %f - %s *", val.p_values[i].f_float, text[i] );
-                else
-                    msg_rc( "| %f - %s", val.p_values[i].f_float, text[i] );
+                msg_rc( "| %f - %s%s", val.p_values[i].f_float, text[i],
+                        f_value == val.p_values[i].f_float ? " *" : "" );
+                free(text[i]);
             }
         }
         else
         {
             for ( size_t i = 0; i < count; i++ )
             {
-                if ( !strcmp( psz_value, val.p_values[i].psz_string ) )
-                    msg_rc( "| %s - %s *", val.p_values[i].psz_string,
-                            text[i] );
-                else
-                    msg_rc( "| %s - %s", val.p_values[i].psz_string, text[i] );
+                msg_rc( "| %s - %s%s", val.p_values[i].psz_string, text[i],
+                       strcmp(psz_value, val.p_values[i].psz_string)
+                           ? "" : " *" );
+                free(text[i]);
+                free(val.p_values[i].psz_string);
             }
             free( psz_value );
         }
-        var_FreeList( &val, &text );
+        free(text);
+        free(val.p_values);
         msg_rc( "+----[ end of %s ]", name );
 
         free( name );
@@ -1692,12 +1690,12 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd,
         msg_rc( "+----[ %s ]", cmd );
         for ( size_t i = 0; i < count; i++ )
         {
-            if ( i_value == val.p_values[i].i_int )
-                msg_rc( "| %"PRId64" - %s *", val.p_values[i].i_int, text[i] );
-            else
-                msg_rc( "| %"PRId64" - %s", val.p_values[i].i_int, text[i] );
+            msg_rc( "| %"PRId64" - %s%s", val.p_values[i].i_int, text[i],
+                    i_value == val.p_values[i].i_int ? " *" : "" );
+            free(text[i]);
         }
-        var_FreeList( &val, &text );
+        free(text);
+        free(val.p_values);
         msg_rc( "+----[ end of %s ]", cmd );
     }
     else
diff --git a/modules/gui/macosx/VLCMainMenu.m b/modules/gui/macosx/VLCMainMenu.m
index b86b60ba3e..3712f65e14 100644
--- a/modules/gui/macosx/VLCMainMenu.m
+++ b/modules/gui/macosx/VLCMainMenu.m
@@ -1527,6 +1527,8 @@
                 if (!strcmp(val.psz_string, val_list.p_values[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
                     [lmi setState: TRUE ];
 
+                free(text_list[i]);
+                free(val_list.p_values[i].psz_string);
                 break;
 
             case VLC_VAR_INTEGER:
@@ -1542,6 +1544,8 @@
 
                 if (val_list.p_values[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
                     [lmi setState: TRUE ];
+
+                free(text_list[i]);
                 break;
 
             default:
@@ -1551,7 +1555,8 @@
 
     /* clean up everything */
     if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
-    var_FreeList(&val_list, &text_list);
+    free(text);
+    free(val_list.p_values);
 }
 
 - (void)toggleVar:(id)sender
diff --git a/modules/gui/qt/components/controller_widget.cpp b/modules/gui/qt/components/controller_widget.cpp
index 25184bc370..69d340e43a 100644
--- a/modules/gui/qt/components/controller_widget.cpp
+++ b/modules/gui/qt/components/controller_widget.cpp
@@ -285,10 +285,15 @@ void AspectRatioComboBox::updateRatios()
     var_Change( p_vout, "aspect-ratio", VLC_VAR_GETCHOICES,
                 &count, &val_list, &text_list );
     for( size_t i = 0; i < count; i++ )
+    {
         addItem( qfu( text_list[i] ),
                  QString( val_list.p_values[i].psz_string ) );
+        free(text_list[i]);
+        free(val_list.p_values[i].psz_string);
+    }
     setEnabled( true );
-    var_FreeList( &val_list, &text_list );
+    free(text_list);
+    free(val_list.p_values);
     vlc_object_release( p_vout );
 }
 
diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index f1a6638659..1d4a427287 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -672,14 +672,17 @@ void ExtV4l2::Refresh( void )
 
         for( size_t i = 0; i < count; i++ )
         {
-            char *vartext;
-            const char *psz_var = text[i];
+            char *vartext, *psz_var = text[i];
+            QString name;
 
-            if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext ) )
-                continue;
+            if( !var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext ) )
+            {
+                name = qtr(vartext);
+                free(vartext);
+            }
+            else
+                name = qfu(psz_var);
 
-            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 ) );
 
@@ -709,8 +712,10 @@ void ExtV4l2::Refresh( void )
                                        qlonglong( val2.p_values[j].i_int) );
                             if( i_val == val2.p_values[j].i_int )
                                 combobox->setCurrentIndex( j );
+                            free(text2[j]);
                         }
-                        var_FreeList( &val2, &text2 );
+                        free(text2);
+                        free(val2.p_values);
 
                         CONNECT( combobox, currentIndexChanged( int ), this,
                                  ValueChange( int ) );
@@ -774,8 +779,10 @@ void ExtV4l2::Refresh( void )
                     msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
                     break;
             }
+            free(psz_var);
         }
-        var_FreeList( &val, &text );
+        free(text);
+        free(val.p_values);
         vlc_object_release( p_obj );
     }
     else
diff --git a/modules/gui/qt/menus.cpp b/modules/gui/qt/menus.cpp
index c2d44e4185..a783218602 100644
--- a/modules/gui/qt/menus.cpp
+++ b/modules/gui/qt/menus.cpp
@@ -1426,6 +1426,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
                         val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
 
                 free( val.psz_string );
+                free(CURVAL.psz_string);
                 break;
 
             case VLC_VAR_INTEGER:
@@ -1450,11 +1451,13 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
             default:
                 break;
         }
+        free(CURTEXT);
     }
     currentGroup = NULL;
 
     /* clean up everything */
-    var_FreeList( &val_list, &text_list );
+    free(text_list);
+    free(val_list.p_values);
 
 #undef RADIO_OR_COMMAND
 #undef CURVAL
diff --git a/modules/lua/libs/variables.c b/modules/lua/libs/variables.c
index ef0f1c3dcf..7cb6e75678 100644
--- a/modules/lua/libs/variables.c
+++ b/modules/lua/libs/variables.c
@@ -238,6 +238,8 @@ static int vlclua_var_get_list( lua_State *L )
         if( !vlclua_pushvalue( L, val.i_type, val.p_values[i] ) )
              lua_pushnil( L );
         lua_settable( L, -3 );
+        if( (val.i_type & VLC_VAR_CLASS) == VLC_VAR_STRING )
+            free(val.p_values[i].psz_string);
     }
 
     lua_createtable( L, count, 0 );
@@ -246,9 +248,11 @@ static int vlclua_var_get_list( lua_State *L )
         lua_pushinteger( L, i + 1 );
         lua_pushstring( L, text[i] );
         lua_settable( L, -3 );
+        free(text[i]);
     }
 
-    var_FreeList( &val, &text );
+    free(text);
+    free(val.p_values);
     return 2;
 }
 
diff --git a/test/src/misc/variables.c b/test/src/misc/variables.c
index a0a29b28cd..54c39a53ed 100644
--- a/test/src/misc/variables.c
+++ b/test/src/misc/variables.c
@@ -343,7 +343,9 @@ static void test_choices( libvlc_int_t *p_libvlc )
     var_Change( p_libvlc, "bla", VLC_VAR_GETCHOICES, &count, &vals, &texts );
     assert( count == 1 && vals.i_count == 1 && vals.p_values[0].i_int == 1 &&
             !strcmp( texts[0], "one" ) );
-    var_FreeList( &vals, &texts );
+    free(texts[0]);
+    free(texts);
+    free(vals.p_values);
 
     var_Change( p_libvlc, "bla", VLC_VAR_CLEARCHOICES );
     assert( var_CountChoices( p_libvlc, "bla" ) == 0 );



More information about the vlc-commits mailing list