]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
dailymotion.lua: partially decode video title and description
[vlc] / src / modules / modules.c
index 26ca697807d3ad743cd686288d00a319f9579501..846b804dc5a48bbce69510bc36ea9f916702a9ae 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc_common.h>
-#include <vlc_plugin.h>
-#include <vlc_memory.h>
-#include <vlc_modules.h>
-#include "libvlc.h"
-
-#include <stdlib.h>                                      /* free(), strtol() */
-#include <stdio.h>                                              /* sprintf() */
-#include <string.h>                                              /* strdup() */
-#include <assert.h>
-
-#include <sys/types.h>
-#ifdef HAVE_SYS_STAT_H
-#   include <sys/stat.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#   include <unistd.h>
-#endif
+#include <stdlib.h>
+#include <string.h>
 #ifdef ENABLE_NLS
 # include <libintl.h>
 #endif
+#include <assert.h>
 
+#include <vlc_common.h>
+#include <vlc_modules.h>
+#include "libvlc.h"
 #include "config/configuration.h"
-
-#include <vlc_fs.h>
 #include "vlc_arrays.h"
-
 #include "modules/modules.h"
 
-static module_bank_t *p_module_bank = NULL;
-static vlc_mutex_t module_lock = VLC_STATIC_MUTEX;
-
-int vlc_entry__main( module_t * );
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-#ifdef HAVE_DYNAMIC_PLUGINS
-typedef enum { CACHE_USE, CACHE_RESET, CACHE_IGNORE } cache_mode_t;
-static void AllocateAllPlugins( vlc_object_t *, module_bank_t * );
-static void AllocatePluginPath( vlc_object_t *, module_bank_t *, const char *,
-                                cache_mode_t );
-static void AllocatePluginDir( vlc_object_t *, module_bank_t *, const char *,
-                               unsigned, cache_mode_t );
-static int  AllocatePluginFile( vlc_object_t *, module_bank_t *, const char *,
-                                const struct stat *, cache_mode_t );
-static module_t * AllocatePlugin( vlc_object_t *, const char *, bool );
-#endif
-static int  AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
-static void DeleteModule ( module_bank_t *, module_t * );
-#ifdef HAVE_DYNAMIC_PLUGINS
-static void   DupModule        ( module_t * );
-static void   UndupModule      ( module_t * );
-#endif
-
-#undef module_InitBank
-/**
- * Init bank
- *
- * Creates a module bank structure which will be filled later
- * on with all the modules found.
- * \param p_this vlc object structure
- * \return nothing
- */
-void module_InitBank( vlc_object_t *p_this )
-{
-    module_bank_t *p_bank = NULL;
-
-    vlc_mutex_lock( &module_lock );
-
-    if( p_module_bank == NULL )
-    {
-        p_bank = calloc (1, sizeof(*p_bank));
-        p_bank->i_usage = 1;
-        p_bank->i_cache = 0;
-        p_bank->pp_cache = NULL;
-        p_bank->head = NULL;
-
-        /* Everything worked, attach the object */
-        p_module_bank = p_bank;
-
-        /* Fills the module bank structure with the main module infos.
-         * This is very useful as it will allow us to consider the main
-         * library just as another module, and for instance the configuration
-         * options of main will be available in the module bank structure just
-         * as for every other module. */
-        AllocateBuiltinModule( p_this, vlc_entry__main );
-        vlc_rwlock_init (&config_lock);
-        config_SortConfig ();
-    }
-    else
-        p_module_bank->i_usage++;
-
-    /* We do retain the module bank lock until the plugins are loaded as well.
-     * This is ugly, this staged loading approach is needed: LibVLC gets
-     * some configuration parameters relevant to loading the plugins from
-     * the main (builtin) module. The module bank becomes shared read-only data
-     * once it is ready, so we need to fully serialize initialization.
-     * DO NOT UNCOMMENT the following line unless you managed to squeeze
-     * module_LoadPlugins() before you unlock the mutex. */
-    /*vlc_mutex_unlock( &module_lock );*/
-}
-
-#undef module_EndBank
-/**
- * Unloads all unused plugin modules and empties the module
- * bank in case of success.
- * \param p_this vlc object structure
- * \return nothing
- */
-void module_EndBank( vlc_object_t *p_this, bool b_plugins )
-{
-    module_bank_t *p_bank = p_module_bank;
-
-    assert (p_bank != NULL);
-
-    /* If plugins were _not_ loaded, then the caller still has the bank lock
-     * from module_InitBank(). */
-    if( b_plugins )
-        vlc_mutex_lock( &module_lock );
-    /*else
-        vlc_assert_locked( &module_lock ); not for static mutexes :( */
-
-    if( --p_bank->i_usage > 0 )
-    {
-        vlc_mutex_unlock( &module_lock );
-        return;
-    }
-
-    config_UnsortConfig ();
-    vlc_rwlock_destroy (&config_lock);
-    p_module_bank = NULL;
-    vlc_mutex_unlock( &module_lock );
-
-#ifdef HAVE_DYNAMIC_PLUGINS
-    while( p_bank->i_cache-- )
-    {
-        free( p_bank->pp_cache[p_bank->i_cache]->path );
-        free( p_bank->pp_cache[p_bank->i_cache] );
-    }
-    free( p_bank->pp_cache );
-#endif
-
-    while( p_bank->head != NULL )
-        DeleteModule( p_bank, p_bank->head );
-
-    free( p_bank );
-}
-
-#undef module_LoadPlugins
-/**
- * Loads module descriptions for all available plugins.
- * Fills the module bank structure with the plugin modules.
- *
- * \param p_this vlc object structure
- * \return nothing
- */
-void module_LoadPlugins( vlc_object_t * p_this )
-{
-    module_bank_t *p_bank = p_module_bank;
-
-    assert( p_bank );
-    /*vlc_assert_locked( &module_lock ); not for static mutexes :( */
-
-#ifdef HAVE_DYNAMIC_PLUGINS
-    if( p_bank->i_usage == 1 )
-    {
-        msg_Dbg( p_this, "checking plugin modules" );
-        AllocateAllPlugins( p_this, p_module_bank );
-        config_UnsortConfig ();
-        config_SortConfig ();
-    }
-#endif
-    vlc_mutex_unlock( &module_lock );
-}
-
 /**
  * Checks whether a module implements a capability.
  *
@@ -214,6 +52,8 @@ void module_LoadPlugins( vlc_object_t * p_this )
  */
 bool module_provides( const module_t *m, const char *cap )
 {
+    if (unlikely(m->psz_capability == NULL))
+        return false;
     return !strcmp( m->psz_capability, cap );
 }
 
@@ -225,7 +65,9 @@ bool module_provides( const module_t *m, const char *cap )
  */
 const char *module_get_object( const module_t *m )
 {
-    return m->psz_object_name;
+    if (unlikely(m->i_shortcuts == 0))
+        return "unnamed";
+    return m->pp_shortcuts[0];
 }
 
 /**
@@ -240,7 +82,9 @@ const char *module_get_name( const module_t *m, bool long_name )
     if( long_name && ( m->psz_longname != NULL) )
         return m->psz_longname;
 
-    return m->psz_shortname ? m->psz_shortname : m->psz_object_name;
+    if (m->psz_shortname != NULL)
+        return m->psz_shortname;
+    return module_get_object (m);
 }
 
 /**
@@ -285,30 +129,21 @@ int module_get_score( const module_t *m )
  */
 const char *module_gettext (const module_t *m, const char *str)
 {
-#ifdef ENABLE_NLS
-    const char *domain = m->domain ? m->domain : PACKAGE_NAME;
+    if (m->parent != NULL)
+        m = m->parent;
     if (unlikely(str == NULL || *str == '\0'))
         return "";
-    return dgettext (domain, str);
+#ifdef ENABLE_NLS
+    const char *domain = m->domain;
+    return dgettext ((domain != NULL) ? domain : PACKAGE_NAME, str);
 #else
     (void)m;
     return str;
 #endif
 }
 
-module_t *module_hold (module_t *m)
-{
-    vlc_hold (&m->vlc_gc_data);
-    return m;
-}
-
-void module_release (module_t *m)
-{
-    vlc_release (&m->vlc_gc_data);
-}
-
 #undef module_start
-int module_start (vlc_object_t *obj, module_t *m)
+int module_start (vlc_object_t *obj, const module_t *m)
 {
    int (*activate) (vlc_object_t *) = m->pf_activate;
 
@@ -316,7 +151,7 @@ int module_start (vlc_object_t *obj, module_t *m)
 }
 
 #undef module_stop
-void module_stop (vlc_object_t *obj, module_t *m)
+void module_stop (vlc_object_t *obj, const module_t *m)
 {
    void (*deactivate) (vlc_object_t *) = m->pf_deactivate;
 
@@ -324,57 +159,6 @@ void module_stop (vlc_object_t *obj, module_t *m)
         deactivate (obj);
 }
 
-/**
- * Frees the flat list of VLC modules.
- * @param list list obtained by module_list_get()
- * @param length number of items on the list
- * @return nothing.
- */
-void module_list_free (module_t **list)
-{
-    if (list == NULL)
-        return;
-
-    for (size_t i = 0; list[i] != NULL; i++)
-         module_release (list[i]);
-    free (list);
-}
-
-/**
- * Gets the flat list of VLC modules.
- * @param n [OUT] pointer to the number of modules or NULL
- * @return NULL-terminated table of module pointers
- *         (release with module_list_free()), or NULL in case of error.
- */
-module_t **module_list_get (size_t *n)
-{
-    /* TODO: this whole module lookup is quite inefficient */
-    /* Remove this and improve module_need */
-    module_t **tab = NULL;
-    size_t i = 0;
-
-    assert (p_module_bank);
-    for (module_t *mod = p_module_bank->head; mod; mod = mod->next)
-    {
-         module_t **nt;
-         nt  = realloc (tab, (i + 2 + mod->submodule_count) * sizeof (*tab));
-         if (nt == NULL)
-         {
-             module_list_free (tab);
-             return NULL;
-         }
-
-         tab = nt;
-         tab[i++] = module_hold (mod);
-         for (module_t *subm = mod->submodule; subm; subm = subm->next)
-             tab[i++] = module_hold (subm);
-         tab[i] = NULL;
-    }
-    if (n != NULL)
-        *n = i;
-    return tab;
-}
-
 typedef struct module_list_t
 {
     module_t *p_module;
@@ -525,7 +309,7 @@ module_t *vlc_module_load(vlc_object_t *p_this, const char *psz_capability,
 
 found_shortcut:
         /* Store this new module */
-        p_list[count].p_module = module_hold (p_module);
+        p_list[count].p_module = p_module;
         p_list[count].i_score = p_module->i_score + i_shortcut_bonus;
         p_list[count].b_force = i_shortcut_bonus && b_strict;
         count++;
@@ -548,24 +332,9 @@ found_shortcut:
     for (size_t i = 0; (i < count) && (p_module == NULL); i++)
     {
         module_t *p_cand = p_list[i].p_module;
-#ifdef HAVE_DYNAMIC_PLUGINS
-        /* Make sure the module is loaded in mem */
-        module_t *p_real = p_cand->parent ? p_cand->parent : p_cand;
 
-        if( !p_real->b_builtin && !p_real->b_loaded )
-        {
-            module_t *p_new_module =
-                AllocatePlugin( p_this, p_real->psz_filename, false );
-            if( p_new_module == NULL )
-            {   /* Corrupted module */
-                msg_Err( p_this, "possibly corrupt module cache" );
-                module_release( p_cand );
-                continue;
-            }
-            CacheMerge( p_this, p_real, p_new_module );
-            DeleteModule( p_module_bank, p_new_module );
-        }
-#endif
+        if (module_Map (p_this, p_cand))
+            continue;
         p_this->b_force = p_list[i].b_force;
 
         int ret;
@@ -590,17 +359,11 @@ found_shortcut:
 
         case VLC_ETIMEOUT:
             /* good module, but aborted */
-            module_release( p_cand );
             break;
 
         default: /* bad module */
-            module_release( p_cand );
             continue;
         }
-
-        /* Release the remaining modules */
-        while (++i < count)
-            module_release (p_list[i].p_module);
     }
 
     va_end (args);
@@ -610,9 +373,9 @@ found_shortcut:
     if( p_module != NULL )
     {
         msg_Dbg( p_this, "using %s module \"%s\"",
-                 psz_capability, p_module->psz_object_name );
+                 psz_capability, module_get_object(p_module) );
         vlc_object_set_name( p_this, psz_alias ? psz_alias
-                                               : p_module->psz_object_name );
+                                               : module_get_object(p_module) );
     }
     else if( count == 0 )
         msg_Dbg( p_this, "no %s module matched \"%s\"",
@@ -648,7 +411,6 @@ void vlc_module_unload(module_t *module, vlc_deactivate_t deinit, ...)
         deinit(module->pf_deactivate, ap);
         va_end(ap);
     }
-    module_release(module);
 }
 
 
@@ -678,33 +440,31 @@ module_t *module_need(vlc_object_t *obj, const char *cap, const char *name,
 #undef module_unneed
 void module_unneed(vlc_object_t *obj, module_t *module)
 {
-    msg_Dbg(obj, "removing module \"%s\"", module->psz_object_name);
+    msg_Dbg(obj, "removing module \"%s\"", module_get_object(module));
     vlc_module_unload(module, generic_stop, obj);
 }
 
 /**
  * Get a pointer to a module_t given it's name.
  *
- * \param psz_name the name of the module
+ * \param name the name of the module
  * \return a pointer to the module or NULL in case of a failure
  */
-module_t *module_find( const char * psz_name )
+module_t *module_find (const char *name)
 {
     module_t **list, *module;
 
+    assert (name != NULL);
     list = module_list_get (NULL);
     if (!list)
         return NULL;
 
     for (size_t i = 0; (module = list[i]) != NULL; i++)
     {
-        const char *psz_module_name = module->psz_object_name;
-
-        if( psz_module_name && !strcmp( psz_module_name, psz_name ) )
-        {
-            module_hold (module);
+        if (unlikely(module->i_shortcuts == 0))
+            continue;
+        if (!strcmp (module->pp_shortcuts[0], name))
             break;
-        }
     }
     module_list_free (list);
     return module;
@@ -718,10 +478,7 @@ module_t *module_find( const char * psz_name )
  */
 bool module_exists (const char * psz_name)
 {
-    module_t *p_module = module_find (psz_name);
-    if( p_module )
-        module_release (p_module);
-    return p_module != NULL;
+    return module_find (psz_name) != NULL;
 }
 
 /**
@@ -742,16 +499,9 @@ module_t *module_find_by_shortcut (const char *psz_shortcut)
         return NULL;
 
     for (size_t i = 0; (module = list[i]) != NULL; i++)
-    {
         for (size_t j = 0; j < module->i_shortcuts; j++)
-        {
             if (!strcmp (module->pp_shortcuts[j], psz_shortcut))
-            {
-                module_hold (module);
                 goto out;
-             }
-        }
-    }
 out:
     module_list_free (list);
     return module;
@@ -801,417 +551,3 @@ void module_config_free( module_config_t *config )
 {
     free( config );
 }
-
-/*****************************************************************************
- * Following functions are local.
- *****************************************************************************/
-
-char *psz_vlcpath = NULL;
-
-#ifdef HAVE_DYNAMIC_PLUGINS
-
-/*****************************************************************************
- * AllocateAllPlugins: load all plugin modules we can find.
- *****************************************************************************/
-static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
-{
-    const char *vlcpath = psz_vlcpath;
-    char *paths;
-    cache_mode_t mode;
-
-    if( !var_InheritBool( p_this, "plugins-cache" ) )
-        mode = CACHE_IGNORE;
-    else if( var_InheritBool( p_this, "reset-plugins-cache" ) )
-        mode = CACHE_RESET;
-    else
-        mode = CACHE_USE;
-
-    /* Contruct the special search path for system that have a relocatable
-     * executable. Set it to <vlc path>/plugins. */
-    assert( vlcpath );
-
-    if( asprintf( &paths, "%s" DIR_SEP "plugins", vlcpath ) != -1 )
-    {
-        AllocatePluginPath( p_this, p_bank, paths, mode );
-        free( paths );
-    }
-
-    /* If the user provided a plugin path, we add it to the list */
-    paths = getenv( "VLC_PLUGIN_PATH" );
-    if( paths == NULL )
-        return;
-
-    paths = strdup( paths ); /* don't harm the environment ! :) */
-    if( unlikely(paths == NULL) )
-        return;
-
-    for( char *buf, *path = strtok_r( paths, PATH_SEP, &buf );
-         path != NULL;
-         path = strtok_r( NULL, PATH_SEP, &buf ) )
-        AllocatePluginPath( p_this, p_bank, path, mode );
-
-    free( paths );
-}
-
-static void AllocatePluginPath( vlc_object_t *p_this, module_bank_t *p_bank,
-                                const char *path, cache_mode_t mode )
-{
-    module_cache_t **cache;
-    size_t count = 0;
-    size_t offset = p_module_bank->i_cache;
-
-    switch( mode )
-    {
-        case CACHE_USE:
-            count = CacheLoad( p_this, path, &cache );
-            break;
-        case CACHE_RESET:
-            CacheDelete( p_this, path );
-            break;
-        case CACHE_IGNORE:
-            msg_Dbg( p_this, "ignoring plugins cache file" );
-    }
-
-    msg_Dbg( p_this, "recursively browsing `%s'", path );
-
-    /* TODO: pass as argument, remove this hack */
-    p_bank->pp_loaded_cache = cache;
-    p_bank->i_loaded_cache = count;
-    /* Don't go deeper than 5 subdirectories */
-    AllocatePluginDir( p_this, p_bank, path, 5, mode );
-
-    switch( mode )
-    {
-        case CACHE_USE:
-            for( size_t i = 0; i < count; i++ )
-                if( likely(cache[i] != NULL) )
-                {
-                    if( cache[i]->p_module != NULL )
-                       DeleteModule( p_bank, cache[i]->p_module );
-                    free( cache[i]->path );
-                    free( cache[i] );
-                }
-            free( cache );
-        case CACHE_RESET:
-            CacheSave( p_this, path, p_bank->pp_cache + offset,
-                       p_bank->i_cache - offset );
-        case CACHE_IGNORE:
-            break;
-    }
-}
-
-/*****************************************************************************
- * AllocatePluginDir: recursively parse a directory to look for plugins
- *****************************************************************************/
-static void AllocatePluginDir( vlc_object_t *p_this, module_bank_t *p_bank,
-                               const char *psz_dir, unsigned i_maxdepth,
-                               cache_mode_t mode )
-{
-    if( i_maxdepth == 0 )
-        return;
-
-    DIR *dh = vlc_opendir (psz_dir);
-    if (dh == NULL)
-        return;
-
-    /* Parse the directory and try to load all files it contains. */
-    for (;;)
-    {
-        char *file = vlc_readdir (dh), *path;
-        struct stat st;
-
-        if (file == NULL)
-            break;
-
-        /* Skip ".", ".." */
-        if (!strcmp (file, ".") || !strcmp (file, ".."))
-        {
-            free (file);
-            continue;
-        }
-
-        const int pathlen = asprintf (&path, "%s"DIR_SEP"%s", psz_dir, file);
-        free (file);
-        if (pathlen == -1 || vlc_stat (path, &st))
-            continue;
-
-        if (S_ISDIR (st.st_mode))
-            /* Recurse into another directory */
-            AllocatePluginDir (p_this, p_bank, path, i_maxdepth - 1, mode);
-        else
-        if (S_ISREG (st.st_mode)
-         && strncmp (path, "lib", 3)
-         && ((size_t)pathlen >= sizeof ("_plugin"LIBEXT))
-         && !strncasecmp (path + pathlen - strlen ("_plugin"LIBEXT),
-                          "_plugin"LIBEXT, strlen ("_plugni"LIBEXT)))
-            /* ^^ We only load files matching "lib*_plugin"LIBEXT */
-            AllocatePluginFile (p_this, p_bank, path, &st, mode);
-
-        free (path);
-    }
-    closedir (dh);
-}
-
-/*****************************************************************************
- * AllocatePluginFile: load a module into memory and initialize it.
- *****************************************************************************
- * This function loads a dynamically loadable module and allocates a structure
- * for its information data. The module can then be handled by module_need
- * and module_unneed. It can be removed by DeleteModule.
- *****************************************************************************/
-static int AllocatePluginFile( vlc_object_t * p_this, module_bank_t *p_bank,
-                               const char *path, const struct stat *st,
-                               cache_mode_t mode )
-{
-    module_t * p_module = NULL;
-
-    /* msg_Dbg( p_this, "plugin \"%s\", %s",
-                p_module->psz_object_name, p_module->psz_longname ); */
-    /* Check our plugins cache first then load plugin if needed */
-    if( mode == CACHE_USE )
-        p_module = CacheFind( p_bank, path, st );
-    if( p_module == NULL )
-        p_module = AllocatePlugin( p_this, path, true );
-    if( p_module == NULL )
-        return -1;
-
-    /* We have not already scanned and inserted this module */
-    assert( p_module->next == NULL );
-
-    /* Unload plugin until we really need it */
-    assert( !p_module->b_builtin );
-    if( p_module->b_loaded && p_module->b_unloadable )
-    {
-        module_Unload( p_module->handle );
-        p_module->b_loaded = false;
-    }
-
-    /* For now we force loading if the module's config contains
-     * callbacks or actions.
-     * Could be optimized by adding an API call.*/
-    for( size_t n = p_module->confsize, i = 0; i < n; i++ )
-         if( p_module->p_config[i].i_action )
-         {
-             /* !unloadable not allowed for plugins with callbacks */
-             assert( !p_module->b_loaded );
-             DeleteModule( p_bank, p_module );
-             p_module = AllocatePlugin( p_this, path, false );
-             break;
-         }
-
-    p_module->next = p_bank->head;
-    p_bank->head = p_module;
-
-    if( mode == CACHE_IGNORE )
-        return 0;
-
-    /* Add entry to cache */
-    module_cache_t **pp_cache = p_bank->pp_cache;
-
-    pp_cache = realloc_or_free( pp_cache, (p_bank->i_cache + 1) * sizeof(void *) );
-    if( pp_cache == NULL )
-        return -1;
-    pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) );
-    if( pp_cache[p_bank->i_cache] == NULL )
-        return -1;
-    pp_cache[p_bank->i_cache]->path = strdup( path );
-    pp_cache[p_bank->i_cache]->mtime = st->st_mtime;
-    pp_cache[p_bank->i_cache]->size = st->st_size;
-    pp_cache[p_bank->i_cache]->p_module = p_module;
-    p_bank->pp_cache = pp_cache;
-    p_bank->i_cache++;
-    return  0;
-}
-
-/*****************************************************************************
- * AllocatePlugin: load a module into memory and initialize it.
- *****************************************************************************
- * This function loads a dynamically loadable module and allocates a structure
- * for its information data. The module can then be handled by module_need
- * and module_unneed. It can be removed by DeleteModule.
- *****************************************************************************/
-static module_t *AllocatePlugin( vlc_object_t * p_this, const char *psz_file,
-                                 bool fast )
-{
-    module_t * p_module = NULL;
-    module_handle_t handle;
-
-    if( module_Load( p_this, psz_file, &handle, fast ) )
-        return NULL;
-
-    /* Now that we have successfully loaded the module, we can
-     * allocate a structure for it */
-    p_module = vlc_module_create();
-    if( p_module == NULL )
-    {
-        module_Unload( handle );
-        return NULL;
-    }
-
-    p_module->psz_filename = strdup( psz_file );
-    p_module->handle = handle;
-    p_module->b_loaded = true;
-
-    /* Initialize the module: fill p_module, default config */
-    static const char entry[] = "vlc_entry" MODULE_SUFFIX;
-
-    /* Try to resolve the symbol */
-    int (*pf_symbol)(module_t * p_module)
-        = (int (*)(module_t *)) module_Lookup( p_module->handle,entry );
-    if( pf_symbol == NULL )
-    {
-        msg_Warn( p_this, "cannot find symbol \"%s\" in plugin `%s'",
-                  entry, psz_file );
-        goto error;
-    }
-    else
-    /* We can now try to call the symbol */
-    if( pf_symbol( p_module ) != 0 )
-    {
-        /* With a well-written module we shouldn't have to print an
-         * additional error message here, but just make sure. */
-        msg_Err( p_this, "cannot initialize plugin `%s'", psz_file );
-        goto error;
-    }
-
-    DupModule( p_module );
-    assert( !p_module->b_builtin );
-    return p_module;
-error:
-    free( p_module->psz_filename );
-    module_release( p_module );
-    module_Unload( handle );
-    return NULL;
-}
-
-/*****************************************************************************
- * DupModule: make a plugin module standalone.
- *****************************************************************************
- * This function duplicates all strings in the module, so that the dynamic
- * object can be unloaded. It acts recursively on submodules.
- *****************************************************************************/
-static void DupModule( module_t *p_module )
-{
-    char **pp_shortcuts = p_module->pp_shortcuts;
-    for( unsigned i = 0; i < p_module->i_shortcuts; i++ )
-        pp_shortcuts[i] = strdup( p_module->pp_shortcuts[i] );
-
-    /* We strdup() these entries so that they are still valid when the
-     * module is unloaded. */
-    p_module->psz_capability = strdup( p_module->psz_capability );
-    p_module->psz_shortname = p_module->psz_shortname ?
-                                 strdup( p_module->psz_shortname ) : NULL;
-    p_module->psz_longname = strdup( p_module->psz_longname );
-    p_module->psz_help = p_module->psz_help ? strdup( p_module->psz_help )
-                                            : NULL;
-    p_module->domain = p_module->domain ? strdup( p_module->domain ) : NULL;
-
-    for (module_t *subm = p_module->submodule; subm; subm = subm->next)
-        DupModule (subm);
-}
-
-/*****************************************************************************
- * UndupModule: free a duplicated module.
- *****************************************************************************
- * This function frees the allocations done in DupModule().
- *****************************************************************************/
-static void UndupModule( module_t *p_module )
-{
-    char **pp_shortcuts = p_module->pp_shortcuts;
-
-    for (module_t *subm = p_module->submodule; subm; subm = subm->next)
-        UndupModule (subm);
-
-    for( unsigned i = 0; i < p_module->i_shortcuts; i++ )
-        free( pp_shortcuts[i] );
-
-    free( p_module->psz_capability );
-    FREENULL( p_module->psz_shortname );
-    free( p_module->psz_longname );
-    FREENULL( p_module->psz_help );
-    free( p_module->domain );
-}
-
-#endif /* HAVE_DYNAMIC_PLUGINS */
-
-/*****************************************************************************
- * AllocateBuiltinModule: initialize a builtin module.
- *****************************************************************************
- * This function registers a builtin module and allocates a structure
- * for its information data. The module can then be handled by module_need
- * and module_unneed. It can be removed by DeleteModule.
- *****************************************************************************/
-static int AllocateBuiltinModule( vlc_object_t * p_this,
-                                  int ( *pf_entry ) ( module_t * ) )
-{
-    module_t * p_module;
-
-    /* Now that we have successfully loaded the module, we can
-     * allocate a structure for it */
-    p_module = vlc_module_create();
-    if( p_module == NULL )
-        return -1;
-
-    /* Initialize the module : fill p_module->psz_object_name, etc. */
-    if( pf_entry( p_module ) != 0 )
-    {
-        /* With a well-written module we shouldn't have to print an
-         * additional error message here, but just make sure. */
-        msg_Err( p_this, "failed calling entry point in builtin module" );
-        module_release( p_module );
-        return -1;
-    }
-
-    /* Everything worked fine ! The module is ready to be added to the list. */
-    p_module->b_builtin = true;
-    /* LOCK */
-    p_module->next = p_module_bank->head;
-    p_module_bank->head = p_module;
-    /* UNLOCK */
-
-    /* msg_Dbg( p_this, "builtin \"%s\", %s",
-                p_module->psz_object_name, p_module->psz_longname ); */
-
-    return 0;
-}
-
-/*****************************************************************************
- * DeleteModule: delete a module and its structure.
- *****************************************************************************
- * This function can only be called if the module isn't being used.
- *****************************************************************************/
-static void DeleteModule( module_bank_t *p_bank, module_t * p_module )
-{
-    assert( p_module );
-
-    /* Unlist the module (if it is in the list) */
-    module_t **pp_self = &p_bank->head;
-    while (*pp_self != NULL && *pp_self != p_module)
-        pp_self = &((*pp_self)->next);
-    if (*pp_self)
-        *pp_self = p_module->next;
-
-    /* We free the structures that we strdup()ed in Allocate*Module(). */
-#ifdef HAVE_DYNAMIC_PLUGINS
-    if( !p_module->b_builtin )
-    {
-        if( p_module->b_loaded && p_module->b_unloadable )
-        {
-            module_Unload( p_module->handle );
-        }
-        UndupModule( p_module );
-        free( p_module->psz_filename );
-    }
-#endif
-
-    /* Free and detach the object's children */
-    while (p_module->submodule)
-    {
-        module_t *submodule = p_module->submodule;
-        p_module->submodule = submodule->next;
-        module_release (submodule);
-    }
-
-    config_Free( p_module );
-    module_release( p_module );
-}