]> git.sesse.net Git - vlc/blobdiff - src/misc/variables.c
Remove vlc_global()
[vlc] / src / misc / variables.c
index c97d8cdef451c75baf24d4c433ad3f56275a28ec..4a6d8e908d0f5d821a85d9ba77d1cd4f3d09b56d 100644 (file)
@@ -135,6 +135,7 @@ static void FreeList( vlc_value_t *p_val )
 }
 
 static const struct variable_ops_t
+void_ops   = { NULL,       DupDummy,  FreeDummy,  },
 addr_ops   = { CmpAddress, DupDummy,  FreeDummy,  },
 bool_ops   = { CmpBool,    DupDummy,  FreeDummy,  },
 float_ops  = { CmpFloat,   DupDummy,  FreeDummy,  },
@@ -276,6 +277,9 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
             p_var->ops = &list_ops;
             p_var->val.p_list = &dummy_null_list;
             break;
+        default:
+            p_var->ops = &void_ops;
+            break;
     }
 
     /* Duplicate the default data we stored. */
@@ -845,25 +849,6 @@ int __var_Get( vlc_object_t *p_this, const char *psz_name, vlc_value_t *p_val )
 }
 
 
-#undef var_AcquireMutex
-/**
- * Finds a process-wide mutex, creates it if needed, and locks it.
- * Unlock with vlc_mutex_unlock().
- */
-vlc_mutex_t *var_AcquireMutex( const char *name )
-{
-    libvlc_global_data_t *p_global = vlc_global();
-    vlc_value_t val;
-
-    if( var_Create( p_global, name, VLC_VAR_MUTEX ) )
-        return NULL;
-
-    var_Get( p_global, name, &val );
-    vlc_mutex_lock( val.p_address );
-    return val.p_address;
-}
-
-
 /**
  * Register a callback in a variable
  *
@@ -1092,6 +1077,7 @@ void var_OptionParse( vlc_object_t *p_obj, const char *psz_option,
         {
             msg_Err( p_obj, "unsafe option \"%s\" has been ignored for "
                             "security reasons", psz_name );
+            free( psz_name );
             return;
         }
     }
@@ -1158,6 +1144,10 @@ void var_OptionParse( vlc_object_t *p_obj, const char *psz_option,
 
     var_Set( p_obj, psz_name, val );
 
+    // If that's a list, remove all elements allocated
+    if( i_type == VLC_VAR_LIST )
+        FreeList( &val );
+
 cleanup:
     free( psz_name );
 }
@@ -1446,22 +1436,48 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
 
 /*****************************************************************************
  * InheritValue: try to inherit the value of this variable from the same one
- *               in our closest parent.
+ * in our closest parent, libvlc or ultimately from the configuration.
+ * The function should always be entered with the object var_lock locked.
  *****************************************************************************/
 static int InheritValue( vlc_object_t *p_this, const char *psz_name,
                          vlc_value_t *p_val, int i_type )
 {
     int i_var;
     variable_t *p_var;
-    vlc_object_internals_t *p_priv;
-
-    /* No need to take the structure lock,
-     * we are only looking for our parents */
 
-    if( !p_this->p_parent && !p_this->p_libvlc )
+    if( p_this->p_parent || ( p_this->p_libvlc && p_this != p_this->p_libvlc ) )
     {
-        switch( i_type & VLC_VAR_CLASS )
+        vlc_object_internals_t *p_priv;
+
+        if( p_this->p_parent )
+            p_priv = vlc_internals( p_this->p_parent );
+        else
+            p_priv = vlc_internals( p_this->p_libvlc );
+
+        i_var = Lookup( p_priv->p_vars, p_priv->i_vars, psz_name );
+
+        if( i_var >= 0 )
         {
+            /* We found it! */
+            p_var = &p_priv->p_vars[i_var];
+
+            /* Really get the variable */
+            *p_val = p_var->val;
+
+            /* Duplicate value if needed */
+            p_var->ops->pf_dup( p_val );
+
+            return VLC_SUCCESS;
+        }
+        else if ( p_this->p_parent ) /* We are still not there */
+            return InheritValue( p_this->p_parent, psz_name, p_val, i_type );
+
+        /* else take value from config */
+    }
+
+
+    switch( i_type & VLC_VAR_CLASS )
+    {
         case VLC_VAR_STRING:
             p_val->psz_string = config_GetPsz( p_this, psz_name );
             if( !p_val->psz_string ) p_val->psz_string = strdup("");
@@ -1507,41 +1523,8 @@ static int InheritValue( vlc_object_t *p_this, const char *psz_name,
         default:
             return VLC_ENOOBJ;
             break;
-        }
-
-        return VLC_SUCCESS;
     }
-
-    if( !p_this->p_parent )
-        p_priv = vlc_internals( p_this->p_libvlc );
-    else
-        p_priv = vlc_internals( p_this->p_parent );
-
-    /* Look for the variable */
-    vlc_mutex_lock( &p_priv->var_lock );
-
-    i_var = Lookup( p_priv->p_vars, p_priv->i_vars, psz_name );
-
-    if( i_var >= 0 )
-    {
-        /* We found it! */
-        p_var = &p_priv->p_vars[i_var];
-
-        /* Really get the variable */
-        *p_val = p_var->val;
-
-        /* Duplicate value if needed */
-        p_var->ops->pf_dup( p_val );
-
-        vlc_mutex_unlock( &p_priv->var_lock );
-        return VLC_SUCCESS;
-    }
-
-    vlc_mutex_unlock( &p_priv->var_lock );
-
-    /* We're still not there */
-
-    return InheritValue( p_this->p_parent, psz_name, p_val, i_type );
+    return VLC_SUCCESS;
 }
 
 /**********************************************************************