]> git.sesse.net Git - vlc/blobdiff - src/misc/objects.c
p_module_bank: move out of vlc_global
[vlc] / src / misc / objects.c
index 58140dd3c8bf8e82ec4f4c02b9d0e81b821c1682..790a126df57e3bfa3b671bc3a776699bdd486ce9 100644 (file)
@@ -142,25 +142,20 @@ void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
         return NULL;
     }
 
-    libvlc_global_data_t *p_libvlc_global;
     if( p_this == NULL )
     {
-        /* Only the global root object is created out of the blue */
-        p_libvlc_global = (libvlc_global_data_t *)p_new;
-        p_new->p_libvlc = NULL;
-
-        object_counter = 0; /* reset */
-        p_priv->next = p_priv->prev = p_new;
-        vlc_mutex_init( &structure_lock );
-    }
-    else
-    {
-        p_libvlc_global = vlc_global();
         if( i_type == VLC_OBJECT_LIBVLC )
             p_new->p_libvlc = (libvlc_int_t*)p_new;
         else
-            p_new->p_libvlc = p_this->p_libvlc;
+        {
+            p_new->p_libvlc = NULL;
+            vlc_mutex_init( &structure_lock );
+        }
+
+        p_this = p_priv->next = p_priv->prev = p_new;
     }
+    else
+        p_new->p_libvlc = p_this->p_libvlc;
 
     vlc_spin_init( &p_priv->ref_spin );
     p_priv->i_refcount = 1;
@@ -179,10 +174,10 @@ void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
     vlc_spin_init( &p_priv->spin );
     p_priv->pipes[0] = p_priv->pipes[1] = -1;
 
-    p_priv->next = VLC_OBJECT (p_libvlc_global);
+    p_priv->next = p_this;
     vlc_mutex_lock( &structure_lock );
-    p_priv->prev = vlc_internals (p_libvlc_global)->prev;
-    vlc_internals (p_libvlc_global)->prev = p_new;
+    p_priv->prev = vlc_internals (p_this)->prev;
+    vlc_internals (p_this)->prev = p_new;
     vlc_internals (p_priv->prev)->next = p_new;
     p_new->i_object_id = object_counter++; /* fetch THEN increment */
     vlc_mutex_unlock( &structure_lock );
@@ -312,40 +307,33 @@ static void vlc_object_destroy( vlc_object_t *p_this )
 
     free( p_this->psz_header );
 
-    if( p_this->p_libvlc == NULL )
-    {
 #ifndef NDEBUG
-        libvlc_global_data_t *p_global = (libvlc_global_data_t *)p_this;
-
-        assert( p_global == vlc_global() );
+    if( VLC_OBJECT(p_this->p_libvlc) == p_this )
+    {
         /* Test for leaks */
-        if (p_priv->next != p_this)
+        vlc_object_t *leaked = p_priv->next;
+        while( leaked != p_this )
         {
-            vlc_object_t *leaked = p_priv->next, *first = leaked;
-            do
-            {
-                /* We are leaking this object */
-                fprintf( stderr,
-                         "ERROR: leaking object (id:%i, type:%s, name:%s)\n",
-                         leaked->i_object_id, leaked->psz_object_type,
-                         leaked->psz_object_name );
-                /* Dump libvlc object to ease debugging */
-                vlc_object_dump( leaked );
-                fflush(stderr);
-                leaked = vlc_internals (leaked)->next;
-            }
-            while (leaked != first);
+            /* We are leaking this object */
+            fprintf( stderr,
+                     "ERROR: leaking object (id:%i, type:%s, name:%s)\n",
+                     leaked->i_object_id, leaked->psz_object_type,
+                     leaked->psz_object_name );
+            /* Dump object to ease debugging */
+            vlc_object_dump( leaked );
+            fflush(stderr);
+            leaked = vlc_internals (leaked)->next;
+        }
 
-            /* Dump global object to ease debugging */
+        if( p_priv->next != p_this )
+            /* Dump libvlc object to ease debugging */
             vlc_object_dump( p_this );
-            /* Strongly abort, cause we want these to be fixed */
-            abort();
-        }
+    }
 #endif
 
+    if( p_this->p_libvlc == NULL )
         /* We are the global object ... no need to lock. */
         vlc_mutex_destroy( &structure_lock );
-    }
 
     FREENULL( p_this->psz_object_name );
 
@@ -589,9 +577,8 @@ void __vlc_object_kill( vlc_object_t *p_this )
  * vlc_object_yield(), use the pointer as your reference, and call
  * vlc_object_release() when you're done.
  */
-void * vlc_object_get( int i_id )
+void * vlc_object_get( libvlc_int_t *p_anchor, int i_id )
 {
-    libvlc_global_data_t *p_libvlc_global = vlc_global();
     vlc_object_t *obj = NULL;
 #ifndef NDEBUG
     int canc = vlc_savecancel ();
@@ -600,8 +587,8 @@ void * vlc_object_get( int i_id )
 #endif
     vlc_mutex_lock( &structure_lock );
 
-    for( obj = vlc_internals (p_libvlc_global)->next;
-         obj != VLC_OBJECT (p_libvlc_global);
+    for( obj = vlc_internals (p_anchor)->next;
+         obj != VLC_OBJECT (p_anchor);
          obj = vlc_internals (obj)->next )
     {
         if( obj->i_object_id == i_id )
@@ -887,7 +874,7 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
          * not be shared across LibVLC instances. In the mean time, this ugly
          * hack is brought to you by Courmisch. */
         if (i_type == VLC_OBJECT_MODULE)
-            return vlc_list_find ((vlc_object_t *)vlc_global ()->p_module_bank,
+            return vlc_list_find ((vlc_object_t *)p_module_bank,
                                   i_type, FIND_CHILD);
         return vlc_list_find (p_this->p_libvlc, i_type, FIND_CHILD);
 
@@ -950,10 +937,12 @@ vlc_list_t *__vlc_list_children( vlc_object_t *obj )
 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
+    libvlc_int_t *p_libvlc = p_this->p_libvlc;
+
     (void)oldval; (void)p_data;
     if( *psz_cmd == 'l' )
     {
-        vlc_object_t *root = VLC_OBJECT (vlc_global ()), *cur = root;
+        vlc_object_t *cur = VLC_OBJECT (p_libvlc);
 
         vlc_mutex_lock( &structure_lock );
         do
@@ -961,7 +950,7 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
             PrintObject (cur, "");
             cur = vlc_internals (cur)->next;
         }
-        while (cur != root);
+        while (cur != VLC_OBJECT(p_libvlc));
         vlc_mutex_unlock( &structure_lock );
     }
     else
@@ -972,8 +961,8 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
         {
             char *end;
             int i_id = strtol( newval.psz_string, &end, 0 );
-            if( end != newval.psz_string )
-                p_object = vlc_object_get( i_id );
+            if( !*end )
+                p_object = vlc_object_get( p_libvlc, i_id );
             else
                 /* try using the object's name to find it */
                 p_object = vlc_object_find_name( p_this, newval.psz_string,
@@ -992,7 +981,7 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
             char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
 
             if( !p_object )
-                p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this;
+                p_object = VLC_OBJECT(p_this->p_libvlc);
 
             psz_foo[0] = '|';
             DumpStructure( p_object, 0, psz_foo );