[vlc-commits] modules: move modules count to plugin and simplify

Rémi Denis-Courmont git at videolan.org
Thu Oct 27 22:04:44 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 27 23:03:46 2016 +0300| [570b0e82ff5c806692d16d0fd7eed451b0c48f2f] | committer: Rémi Denis-Courmont

modules: move modules count to plugin and simplify

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

 src/modules/bank.c    | 11 +++--------
 src/modules/cache.c   | 44 +++++++++++++++-----------------------------
 src/modules/entry.c   | 10 +++++-----
 src/modules/modules.h |  3 +--
 4 files changed, 24 insertions(+), 44 deletions(-)

diff --git a/src/modules/bank.c b/src/modules/bank.c
index 30051db..0d0cda8 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -590,11 +590,7 @@ module_t **module_list_get (size_t *n)
 
     for (vlc_plugin_t *lib = vlc_plugins; lib != NULL; lib = lib->next)
     {
-        module_t *mod = lib->module;
-        assert(mod != NULL);
-
-         module_t **nt;
-         nt  = realloc (tab, (i + 1 + mod->submodule_count) * sizeof (*tab));
+        module_t **nt = realloc(tab, (i + lib->modules_count) * sizeof (*tab));
          if (unlikely(nt == NULL))
          {
              free (tab);
@@ -603,9 +599,8 @@ module_t **module_list_get (size_t *n)
          }
 
          tab = nt;
-         tab[i++] = mod;
-         for (module_t *subm = mod->next; subm != NULL; subm = subm->next)
-             tab[i++] = subm;
+        for (module_t *m = lib->module; m != NULL; m = m->next)
+            tab[i++] = m;
     }
     *n = i;
     return tab;
diff --git a/src/modules/cache.c b/src/modules/cache.c
index fd8adaa..6e4f711 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -57,7 +57,7 @@
 #ifdef HAVE_DYNAMIC_PLUGINS
 /* Sub-version number
  * (only used to avoid breakage in dev version when cache structure changes) */
-#define CACHE_SUBVERSION_NUM 32
+#define CACHE_SUBVERSION_NUM 33
 
 /* Cache filename */
 #define CACHE_NAME "plugins.dat"
@@ -288,8 +288,12 @@ error:
     return -1; /* FIXME: leaks */
 }
 
-static int vlc_cache_load_module(module_t *module, block_t *file)
+static int vlc_cache_load_module(vlc_plugin_t *plugin, block_t *file)
 {
+    module_t *module = vlc_module_create(plugin);
+    if (unlikely(module == NULL))
+        return -1;
+
     LOAD_STRING(module->psz_shortname);
     LOAD_STRING(module->psz_longname);
     LOAD_STRING(module->psz_help);
@@ -320,27 +324,12 @@ static vlc_plugin_t *vlc_cache_load_plugin(block_t *file)
     if (unlikely(plugin == NULL))
         return NULL;
 
-    module_t *module = vlc_module_create(plugin);
-    if (unlikely(module == NULL))
-        goto error;
+    uint32_t modules;
+    LOAD_IMMEDIATE(modules);
 
-    plugin->module = module;
-
-    if (vlc_cache_load_module(module, file))
-        goto error;
-
-    uint32_t submodules;
-    LOAD_IMMEDIATE(submodules);
-
-    for (size_t i = 0; i < submodules; i++)
-    {
-        module = vlc_module_create(plugin);
-        if (unlikely(module == NULL))
-            goto error;
-
-        if (vlc_cache_load_module(module, file))
+    for (size_t i = 0; i < modules; i++)
+        if (vlc_cache_load_module(plugin, file))
             goto error;
-    }
 
     if (vlc_cache_load_plugin_config(plugin, file))
         goto error;
@@ -631,16 +620,13 @@ static int CacheSaveBank(FILE *file, vlc_plugin_t *const *cache, size_t n)
     for (size_t i = 0; i < n; i++)
     {
         const vlc_plugin_t *plugin = cache[i];
-        const module_t *module = plugin->module;
-        uint32_t i_submodule;
-
-        if (CacheSaveModule(file, module))
-            goto error;
+        uint32_t count = plugin->modules_count;
 
-        i_submodule = module->submodule_count;
-        SAVE_IMMEDIATE( i_submodule );
+        SAVE_IMMEDIATE(count);
 
-        for (module = module->next; module != NULL; module = module->next)
+        for (module_t *module = plugin->module;
+             module != NULL;
+             module = module->next)
             if (CacheSaveModule(file, module))
                 goto error;
 
diff --git a/src/modules/entry.c b/src/modules/entry.c
index e269897..36af1f2 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -50,16 +50,18 @@ module_t *vlc_module_create(vlc_plugin_t *plugin)
      * entries is irrelevant. */
     module_t *parent = plugin->module;
     if (parent == NULL)
+    {
         module->next = NULL;
+        plugin->module = module;
+    }
     else
     {
         module->next = parent->next;
         parent->next = module;
-        parent->submodule_count++;
     }
 
+    plugin->modules_count++;
     module->plugin = plugin;
-    module->submodule_count = 0;
 
     module->psz_shortname = NULL;
     module->psz_longname = NULL;
@@ -96,6 +98,7 @@ vlc_plugin_t *vlc_plugin_create(void)
     if (unlikely(plugin == NULL))
         return NULL;
 
+    plugin->modules_count = 0;
     plugin->textdomain = NULL;
     plugin->conf.items = NULL;
     plugin->conf.size = 0;
@@ -201,10 +204,7 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
 
             *(va_arg (ap, module_t **)) = submodule;
             if (module == NULL)
-            {
-                plugin->module = submodule;
                 break;
-            }
 
             /* Inheritance. Ugly!! */
             submodule->pp_shortcuts = xmalloc (sizeof ( *submodule->pp_shortcuts ));
diff --git a/src/modules/modules.h b/src/modules/modules.h
index bf04563..72c711a 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -33,8 +33,8 @@ typedef void *module_handle_t;
 typedef struct vlc_plugin_t
 {
     struct vlc_plugin_t *next;
-
     module_t *module;
+    unsigned modules_count;
 
     const char *textdomain; /**< gettext domain (or NULL) */
 
@@ -79,7 +79,6 @@ struct module_t
 {
     vlc_plugin_t *plugin; /**< Plug-in/library containing the module */
     module_t   *next;
-    unsigned    submodule_count;
 
     /** Shortcuts to the module */
     unsigned    i_shortcuts;



More information about the vlc-commits mailing list