[vlc-commits] variables: add internal type callback_table_t for storing a list of callbacks

Felix Abecassis git at videolan.org
Mon Aug 4 12:16:06 CEST 2014


vlc | branch: master | Felix Abecassis <felix.abecassis at gmail.com> | Mon Aug  4 12:06:23 2014 +0200| [c4cd36ee80608967355b90bf18031b022e9ecdb6] | committer: Felix Abecassis

variables: add internal type callback_table_t for storing a list of callbacks

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

 src/misc/objects.c   |    4 ++--
 src/misc/variables.c |   35 +++++++++++++++++++----------------
 src/misc/variables.h |   12 ++++++++----
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index 0026ea8..3b04518 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -603,8 +603,8 @@ static void DumpVariable (const void *data, const VISIT which, const int depth)
         fputs( ", has choices", stdout );
     if( p_var->i_type & VLC_VAR_ISCOMMAND )
         fputs( ", command", stdout );
-    if( p_var->i_entries )
-        printf( ", %d callbacks", p_var->i_entries );
+    if( p_var->value_callbacks.i_entries )
+        printf( ", %d callbacks", p_var->value_callbacks.i_entries );
     switch( p_var->i_type & VLC_VAR_CLASS )
     {
         case VLC_VAR_VOID:
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 69d0dce..46d5194 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -169,10 +169,11 @@ static void Destroy( variable_t *p_var )
         free( p_var->choices_text.p_values );
     }
 #if 0 // ndef NDEBUG
-    for (int i = 0; i < p_var->i_entries; i++)
+    callback_table_t *p_table = &p_var->value_callbacks;
+    for (int i = 0; i < p_table->i_entries; i++)
     {
         const char *file = "?", *symbol = "?";
-        const void *addr = p_var->p_entries[i].pf_callback;
+        const void *addr = p_table->p_entries[i].pf_callback;
 # ifdef __GLIBC__
         Dl_info info;
 
@@ -189,7 +190,7 @@ static void Destroy( variable_t *p_var )
 
     free( p_var->psz_name );
     free( p_var->psz_text );
-    free( p_var->p_entries );
+    free( p_var->value_callbacks.p_entries );
     free( p_var );
 }
 
@@ -228,8 +229,7 @@ int var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
     p_var->choices_text.p_values = NULL;
 
     p_var->b_incallback = false;
-    p_var->i_entries = 0;
-    p_var->p_entries = NULL;
+    p_var->value_callbacks = (callback_table_t){ 0 };
 
     /* Always initialize the variable, even if it is a list variable; this
      * will lead to errors if the variable is not initialized, but it will
@@ -825,10 +825,11 @@ static int AddCallback( vlc_object_t *p_this, const char *psz_name,
     }
 
     WaitUnused( p_this, p_var );
-    INSERT_ELEM( p_var->p_entries,
-                 p_var->i_entries,
-                 p_var->i_entries,
-                 entry );
+    callback_table_t *p_table = &p_var->value_callbacks;
+    INSERT_ELEM( p_table->p_entries,
+                 p_table->i_entries,
+                 p_table->i_entries,
+                 entry);
 
     vlc_mutex_unlock( &p_priv->var_lock );
 
@@ -886,15 +887,16 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
 
     WaitUnused( p_this, p_var );
 
-    for( i_entry = p_var->i_entries ; i_entry-- ; )
+    callback_table_t *p_table = &p_var->value_callbacks;
+    for( i_entry = p_table->i_entries ; i_entry-- ; )
     {
-        if( p_var->p_entries[i_entry].pf_callback == entry.pf_callback
-            && p_var->p_entries[i_entry].p_data == entry.p_data )
+        if( p_table->p_entries[i_entry].pf_callback == entry.pf_callback
+            && p_table->p_entries[i_entry].p_data == entry.p_data )
         {
             break;
         }
 #ifndef NDEBUG
-        else if( p_var->p_entries[i_entry].pf_callback == entry.pf_callback )
+        else if( p_table->p_entries[i_entry].pf_callback == entry.pf_callback )
             b_found_similar = true;
 #endif
     }
@@ -911,7 +913,7 @@ static int DelCallback( vlc_object_t *p_this, const char *psz_name,
         return VLC_EGENERIC;
     }
 
-    REMOVE_ELEM( p_var->p_entries, p_var->i_entries, i_entry );
+    REMOVE_ELEM( p_table->p_entries, p_table->i_entries, i_entry );
 
     vlc_mutex_unlock( &p_priv->var_lock );
 
@@ -1317,11 +1319,12 @@ static int TriggerCallback( vlc_object_t *p_this, variable_t *p_var,
 {
     assert( p_this );
 
-    int i_entries = p_var->i_entries;
+    callback_table_t *p_table = &p_var->value_callbacks;
+    int i_entries = p_table->i_entries;
     if( i_entries == 0 )
         return VLC_SUCCESS;
 
-    callback_entry_t *p_entries = p_var->p_entries;
+    callback_entry_t *p_entries = p_table->p_entries;
     vlc_object_internals_t *p_priv = vlc_internals( p_this );
 
     assert( !p_var->b_incallback );
diff --git a/src/misc/variables.h b/src/misc/variables.h
index 8c203b6..d09ba66 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -66,6 +66,12 @@ typedef struct variable_ops_t
     void (*pf_free) ( vlc_value_t * );
 } variable_ops_t;
 
+typedef struct callback_table_t
+{
+    int                i_entries;
+    callback_entry_t * p_entries;
+} callback_table_t;
+
 /**
  * The structure describing a variable.
  * \note vlc_value_t is the common union for variable values
@@ -99,10 +105,8 @@ struct variable_t
     /** Set to TRUE if the variable is in a callback */
     bool   b_incallback;
 
-    /** Number of registered callbacks */
-    int                i_entries;
-    /** Array of registered callbacks */
-    callback_entry_t * p_entries;
+    /** Registered value callbacks */
+    callback_table_t    value_callbacks;
 };
 
 extern void var_DestroyAll( vlc_object_t * );



More information about the vlc-commits mailing list