[vlc-devel] commit: The input_items array is private data. ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon May 5 22:40:09 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Mon May  5 22:17:20 2008 +0300| [04a4af73ffcb9602a697e5b2bd8df21c9e9b3c6d]

The input_items array is private data.

Hide it before someone thinks (s)he can use it without locking libvlc.

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

 include/vlc_main.h  |    4 ----
 src/input/item.c    |   16 ++++++++++------
 src/libvlc-common.c |    8 ++++----
 src/libvlc.h        |    5 +++++
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/include/vlc_main.h b/include/vlc_main.h
index 76356bc..f416228 100644
--- a/include/vlc_main.h
+++ b/include/vlc_main.h
@@ -47,10 +47,6 @@ struct libvlc_int_t
 
     global_stats_t       *p_stats;           ///< Global statistics
 
-    /* There is no real reason to keep a list of items, but not to break
-     * everything, let's keep it */
-    input_item_array_t    input_items;       ///< Array of all created input items
-    int                   i_last_input_id ;  ///< Last id of input item
 
     /* Structure storing the action name / key associations */
     struct hotkey
diff --git a/src/input/item.c b/src/input/item.c
index 4aed77b..1432a56 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -183,6 +183,7 @@ char *input_ItemGetInfo( input_item_t *p_i,
 static void input_ItemDestroy ( gc_object_t *p_this )
 {
     vlc_object_t *p_obj = (vlc_object_t *)p_this->p_destructor_arg;
+    libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
     input_item_t *p_input = (input_item_t *) p_this;
     int i;
 
@@ -190,9 +191,9 @@ static void input_ItemDestroy ( gc_object_t *p_this )
 
     vlc_mutex_lock( &p_obj->p_libvlc->object_lock );
 
-    ARRAY_BSEARCH( p_obj->p_libvlc->input_items,->i_id, int, p_input->i_id, i);
+    ARRAY_BSEARCH( priv->input_items,->i_id, int, p_input->i_id, i);
     if( i != -1 )
-        ARRAY_REMOVE( p_obj->p_libvlc->input_items, i);
+        ARRAY_REMOVE( priv->input_items, i);
 
     vlc_mutex_unlock( &p_obj->p_libvlc->object_lock );
 
@@ -301,14 +302,15 @@ int input_ItemAddInfo( input_item_t *p_i,
 
 input_item_t *__input_ItemGetById( vlc_object_t *p_obj, int i_id )
 {
+    libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
     input_item_t * p_ret = NULL;
     int i;
 
     vlc_mutex_lock( &p_obj->p_libvlc->object_lock );
 
-    ARRAY_BSEARCH( p_obj->p_libvlc->input_items, ->i_id, int, i_id, i);
+    ARRAY_BSEARCH( priv->input_items, ->i_id, int, i_id, i);
     if( i != -1 )
-        p_ret = ARRAY_VAL( p_obj->p_libvlc->input_items, i);
+        p_ret = ARRAY_VAL( priv->input_items, i);
 
     vlc_mutex_unlock( &p_obj->p_libvlc->object_lock );
 
@@ -334,14 +336,16 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
                                 mtime_t i_duration,
                                 int i_type )
 {
+    libvlc_priv_t *priv = libvlc_priv (p_obj->p_libvlc);
+
     DECMALLOC_NULL( p_input, input_item_t );
 
     input_ItemInit( p_obj, p_input );
     vlc_gc_init( p_input, input_ItemDestroy, (void *)p_obj );
 
     vlc_mutex_lock( &p_obj->p_libvlc->object_lock );
-    p_input->i_id = ++p_obj->p_libvlc->i_last_input_id;
-    ARRAY_APPEND( p_obj->p_libvlc->input_items, p_input );
+    p_input->i_id = ++priv->i_last_input_id;
+    ARRAY_APPEND( priv->input_items, p_input );
     vlc_mutex_unlock( &p_obj->p_libvlc->object_lock );
 
     p_input->b_fixed_name = false;
diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index 149b4d7..1c81ca7 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -720,8 +720,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     priv->p_stats_computer = NULL;
 
     /* Init the array that holds every input item */
-    ARRAY_INIT( p_libvlc->input_items );
-    p_libvlc->i_last_input_id = 0;
+    ARRAY_INIT( priv->input_items );
+    priv->i_last_input_id = 0;
 
     /*
      * Initialize hotkey handling
@@ -1003,13 +1003,13 @@ int libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
 #endif
 
     bool b_clean = true;
-    FOREACH_ARRAY( input_item_t *p_del, p_libvlc->input_items )
+    FOREACH_ARRAY( input_item_t *p_del, priv->input_items )
         msg_Err( p_libvlc, "input item %p has not been deleted properly: refcount %d, name %s",
             p_del, p_del->i_gc_refcount, p_del->psz_name ? p_del->psz_name : "(null)" );
         b_clean = false;
     FOREACH_END();
     assert( b_clean );
-    ARRAY_RESET( p_libvlc->input_items );
+    ARRAY_RESET( priv->input_items );
 
     msg_Dbg( p_libvlc, "removing stats" );
     vlc_mutex_destroy( &p_libvlc->p_stats->lock );
diff --git a/src/libvlc.h b/src/libvlc.h
index a359e52..c6c2917 100644
--- a/src/libvlc.h
+++ b/src/libvlc.h
@@ -212,6 +212,11 @@ typedef struct libvlc_priv_t
     vlc_mutex_t        config_lock; ///< config file lock
     char *             psz_configfile;   ///< location of config file
 
+    /* There is no real reason to keep a list of items, but not to break
+     * everything, let's keep it */
+    input_item_array_t input_items; ///< Array of all created input items
+    int                i_last_input_id ; ///< Last id of input item
+
     /* Messages */
     msg_bank_t         msg_bank;    ///< The message bank
     int                i_verbose;   ///< info messages




More information about the vlc-devel mailing list