[vlc-commits] variables: voidify var_TriggerCallback()

Rémi Denis-Courmont git at videolan.org
Sat Nov 28 11:51:06 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 28 12:10:01 2015 +0200| [2850821ad70765c499319fdb9598780c2fd4597e] | committer: Rémi Denis-Courmont

variables: voidify var_TriggerCallback()

The function can only fail if the named variable does not exist. The
only case where the error was actually checked was after another check
that the variable exists (Old RC).

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

 include/vlc_variables.h      |    2 +-
 modules/control/oldrc.c      |    8 ++++----
 modules/lua/libs/variables.c |    3 ++-
 src/misc/variables.c         |   26 ++++++++------------------
 4 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index d855c30..0a732f6 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -173,7 +173,7 @@ VLC_API void var_FreeList( vlc_value_t *, vlc_value_t * );
  *****************************************************************************/
 VLC_API int var_AddCallback( vlc_object_t *, const char *, vlc_callback_t, void * );
 VLC_API int var_DelCallback( vlc_object_t *, const char *, vlc_callback_t, void * );
-VLC_API int var_TriggerCallback( vlc_object_t *, const char * );
+VLC_API void var_TriggerCallback( vlc_object_t *, const char * );
 
 VLC_API int var_AddListCallback( vlc_object_t *, const char *, vlc_list_callback_t, void * );
 VLC_API int var_DelListCallback( vlc_object_t *, const char *, vlc_list_callback_t, void * );
diff --git a/modules/control/oldrc.c b/modules/control/oldrc.c
index dba7616..c6598ae 100644
--- a/modules/control/oldrc.c
+++ b/modules/control/oldrc.c
@@ -605,10 +605,10 @@ static void *Run( void *data )
         /* If the user typed a registered local command, try it */
         if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
         {
-            int i_ret;
+            int i_ret = VLC_SUCCESS;
 
             if ((var_Type( p_intf, psz_cmd) & VLC_VAR_CLASS) == VLC_VAR_VOID)
-                i_ret = var_TriggerCallback( p_intf, psz_cmd );
+                var_TriggerCallback( p_intf, psz_cmd );
             else
                 i_ret = var_SetString( p_intf, psz_cmd, psz_arg );
             msg_rc( "%s: returned %i (%s)",
@@ -617,12 +617,12 @@ static void *Run( void *data )
         /* Or maybe it's a global command */
         else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
         {
-            int i_ret;
+            int i_ret = VLC_SUCCESS;
 
             /* FIXME: it's a global command, but we should pass the
              * local object as an argument, not p_intf->p_libvlc. */
             if ((var_Type( p_intf->p_libvlc, psz_cmd) & VLC_VAR_CLASS) == VLC_VAR_VOID)
-                i_ret = var_TriggerCallback( p_intf, psz_cmd );
+                var_TriggerCallback( p_intf, psz_cmd );
             else
                 i_ret = var_SetString( p_intf->p_libvlc, psz_cmd, psz_arg );
             if( i_ret != 0 )
diff --git a/modules/lua/libs/variables.c b/modules/lua/libs/variables.c
index f468b82..3b49ea6 100644
--- a/modules/lua/libs/variables.c
+++ b/modules/lua/libs/variables.c
@@ -286,7 +286,8 @@ static int vlclua_trigger_callback( lua_State *L )
     vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
     const char *psz_var = luaL_checkstring( L, 2 );
 
-    return vlclua_push_ret( L, var_TriggerCallback( *pp_obj, psz_var ) );
+    var_TriggerCallback( *pp_obj, psz_var );
+    return vlclua_push_ret( L, 0 );
 }
 
 static int vlclua_inc_integer( lua_State *L )
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 8c7c998..76371ae 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -1038,29 +1038,19 @@ int var_DelCallback( vlc_object_t *p_this, const char *psz_name,
  * \param p_this The object that hold the variable
  * \param psz_name The name of the variable
  */
-int var_TriggerCallback( vlc_object_t *p_this, const char *psz_name )
+void var_TriggerCallback( vlc_object_t *p_this, const char *psz_name )
 {
-    variable_t *p_var;
-
-    assert( p_this );
-
     vlc_object_internals_t *p_priv = vlc_internals( p_this );
-
-    p_var = Lookup( p_this, psz_name );
-    if( p_var == NULL )
+    variable_t *p_var = Lookup( p_this, psz_name );
+    if( p_var != NULL )
     {
-        vlc_mutex_unlock( &p_priv->var_lock );
-        return VLC_ENOVAR;
-    }
-
-    WaitUnused( p_this, p_var );
-
-    /* Deal with callbacks. Tell we're in a callback, release the lock,
-     * call stored functions, retake the lock. */
-    TriggerCallback( p_this, p_var, psz_name, p_var->val );
+        WaitUnused( p_this, p_var );
 
+        /* Deal with callbacks. Tell we're in a callback, release the lock,
+         * call stored functions, retake the lock. */
+        TriggerCallback( p_this, p_var, psz_name, p_var->val );
+    }
     vlc_mutex_unlock( &p_priv->var_lock );
-    return VLC_SUCCESS;
 }
 
 #undef var_AddListCallback



More information about the vlc-commits mailing list