[vlc-devel] [PATCH] config: only create the variables once in the object

Steve Lhomme robux4 at ycbcr.xyz
Mon Mar 16 15:13:28 CET 2020


config_LoadCmdLine() is called twice for the libvlc object and thus created the
command-line option variables twice in the same object.

We try to create the variable if the type doesn't match (unlikely) so we can
assert later in the code.
---
 src/config/cmdline.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/config/cmdline.c b/src/config/cmdline.c
index 72df85347a9..4b0d24ad130 100644
--- a/src/config/cmdline.c
+++ b/src/config/cmdline.c
@@ -212,11 +212,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
                 switch( CONFIG_CLASS(p_conf->i_type) )
                 {
                     case CONFIG_ITEM_STRING:
-                        var_Create( p_this, psz_name, VLC_VAR_STRING );
+                        if ( var_Type( p_this, psz_name ) != VLC_VAR_STRING )
+                            var_Create( p_this, psz_name, VLC_VAR_STRING );
                         var_SetString( p_this, psz_name, state.arg );
                         break;
                     case CONFIG_ITEM_INTEGER:
-                        var_Create( p_this, psz_name, VLC_VAR_INTEGER );
+                        if ( var_Type( p_this, psz_name ) != VLC_VAR_INTEGER )
+                            var_Create( p_this, psz_name, VLC_VAR_INTEGER );
                         var_Change( p_this, psz_name, VLC_VAR_SETMINMAX,
                             (vlc_value_t){ .i_int = p_conf->min.i },
                             (vlc_value_t){ .i_int = p_conf->max.i } );
@@ -224,14 +226,16 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
                                         strtoll(state.arg, NULL, 0));
                         break;
                     case CONFIG_ITEM_FLOAT:
-                        var_Create( p_this, psz_name, VLC_VAR_FLOAT );
+                        if ( var_Type( p_this, psz_name ) != VLC_VAR_FLOAT )
+                            var_Create( p_this, psz_name, VLC_VAR_FLOAT );
                         var_Change( p_this, psz_name, VLC_VAR_SETMINMAX,
                             (vlc_value_t){ .f_float = p_conf->min.f },
                             (vlc_value_t){ .f_float = p_conf->max.f } );
                         var_SetFloat( p_this, psz_name, us_atof(state.arg) );
                         break;
                     case CONFIG_ITEM_BOOL:
-                        var_Create( p_this, psz_name, VLC_VAR_BOOL );
+                        if ( var_Type( p_this, psz_name ) != VLC_VAR_BOOL )
+                            var_Create( p_this, psz_name, VLC_VAR_BOOL );
                         var_SetBool( p_this, psz_name, !flag );
                         break;
                 }
@@ -246,11 +250,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
             switch( CONFIG_CLASS(pp_shortopts[i_cmd]->i_type) )
             {
                 case CONFIG_ITEM_STRING:
-                    var_Create( p_this, name, VLC_VAR_STRING );
+                    if ( var_Type( p_this, name ) != VLC_VAR_STRING )
+                        var_Create( p_this, name, VLC_VAR_STRING );
                     var_SetString( p_this, name, state.arg );
                     break;
                 case CONFIG_ITEM_INTEGER:
-                    var_Create( p_this, name, VLC_VAR_INTEGER );
+                    if ( var_Type( p_this, name ) != VLC_VAR_INTEGER )
+                        var_Create( p_this, name, VLC_VAR_INTEGER );
                     if( i_cmd == 'v' )
                     {
                         i_verbose++; /* -v */
@@ -263,7 +269,8 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
                     }
                     break;
                 case CONFIG_ITEM_BOOL:
-                    var_Create( p_this, name, VLC_VAR_BOOL );
+                    if ( var_Type( p_this, name ) != VLC_VAR_BOOL )
+                        var_Create( p_this, name, VLC_VAR_BOOL );
                     var_SetBool( p_this, name, true );
                     break;
             }
-- 
2.17.1



More information about the vlc-devel mailing list