[vlc-commits] module: store callback names rather than address

Rémi Denis-Courmont git at videolan.org
Thu Oct 27 18:46:15 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 27 19:03:34 2016 +0300| [488c9310319abde68ed387a8fe3bf1f8650102c6] | committer: Rémi Denis-Courmont

module: store callback names rather than address

Storing a relocatable pointer in the plugins cache made little sense.
In practice, it was only usable for comparison with NULL.

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

 include/vlc_configuration.h |  1 +
 src/modules/bank.c          |  4 +---
 src/modules/cache.c         | 18 +++++++++++-------
 src/modules/entry.c         |  8 +++++---
 src/modules/modules.h       |  2 ++
 5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index 84499c1..853cf85 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -87,6 +87,7 @@ struct module_config_t
         vlc_integer_list_cb i_cb;
     } list;
     const char **list_text;                /* Friendly names for list values */
+    const char *list_cb_name;
 };
 
 /*****************************************************************************
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 49ab87f..36f3fcf 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -207,9 +207,7 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
      * Could be optimized by adding an API call.*/
     for (size_t i = 0; i < plugin->conf.size; i++)
          if (!atomic_load_explicit(&plugin->loaded, memory_order_relaxed)
-          && plugin->conf.items[i].list_count == 0
-          && (plugin->conf.items[i].list.psz_cb != NULL
-           || plugin->conf.items[i].list.i_cb != NULL))
+          && plugin->conf.items[i].list_cb_name != NULL)
          {
              /* !unloadable not allowed for plugins with callbacks */
              vlc_plugin_destroy(plugin);
diff --git a/src/modules/cache.c b/src/modules/cache.c
index a90fb6a..8a6c77e 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 31
+#define CACHE_SUBVERSION_NUM 32
 
 /* Cache filename */
 #define CACHE_NAME "plugins.dat"
@@ -203,8 +203,8 @@ static int vlc_cache_load_config(module_config_t *cfg, block_t *file)
 
         if (cfg->list_count)
             cfg->list.psz = xmalloc (cfg->list_count * sizeof (char *));
-        else /* TODO: fix config_GetPszChoices() instead of this hack: */
-            LOAD_IMMEDIATE(cfg->list.psz_cb);
+        else
+            LOAD_STRING(cfg->list_cb_name);
         for (unsigned i = 0; i < cfg->list_count; i++)
         {
             LOAD_STRING (cfg->list.psz[i]);
@@ -224,8 +224,8 @@ static int vlc_cache_load_config(module_config_t *cfg, block_t *file)
         {
             LOAD_ALIGNOF(*cfg->list.i);
         }
-        else /* TODO: fix config_GetPszChoices() instead of this hack: */
-            LOAD_IMMEDIATE(cfg->list.i_cb);
+        else
+            LOAD_IMMEDIATE(cfg->list_cb_name);
 
         LOAD_ARRAY(cfg->list.i, cfg->list_count);
     }
@@ -304,6 +304,8 @@ static int vlc_cache_load_module(module_t *module, block_t *file)
             LOAD_STRING(module->pp_shortcuts[j]);
     }
 
+    LOAD_STRING(module->activate_name);
+    LOAD_STRING(module->deactivate_name);
     LOAD_STRING(module->psz_capability);
     LOAD_IMMEDIATE(module->i_score);
     return 0;
@@ -531,7 +533,7 @@ static int CacheSaveConfig (FILE *file, const module_config_t *cfg)
     {
         SAVE_STRING (cfg->orig.psz);
         if (cfg->list_count == 0)
-            SAVE_IMMEDIATE (cfg->list.psz_cb); /* XXX: see CacheLoadConfig() */
+            SAVE_STRING(cfg->list_cb_name);
 
         for (unsigned i = 0; i < cfg->list_count; i++)
             SAVE_STRING (cfg->list.psz[i]);
@@ -547,7 +549,7 @@ static int CacheSaveConfig (FILE *file, const module_config_t *cfg)
             SAVE_ALIGNOF(*cfg->list.i);
         }
         else
-            SAVE_IMMEDIATE (cfg->list.i_cb); /* XXX: see CacheLoadConfig() */
+            SAVE_IMMEDIATE (cfg->list_cb_name);
 
         for (unsigned i = 0; i < cfg->list_count; i++)
              SAVE_IMMEDIATE (cfg->list.i[i]);
@@ -585,6 +587,8 @@ static int CacheSaveModule(FILE *file, const module_t *module)
     for (size_t j = 0; j < module->i_shortcuts; j++)
          SAVE_STRING(module->pp_shortcuts[j]);
 
+    SAVE_STRING(module->activate_name);
+    SAVE_STRING(module->deactivate_name);
     SAVE_STRING(module->psz_capability);
     SAVE_IMMEDIATE(module->i_score);
     return 0;
diff --git a/src/modules/entry.c b/src/modules/entry.c
index db50668..4166b0c 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -63,6 +63,8 @@ module_t *vlc_module_create(vlc_plugin_t *plugin)
     module->i_shortcuts = 0;
     module->psz_capability = NULL;
     module->i_score = (parent != NULL) ? parent->i_score : 1;
+    module->activate_name = NULL;
+    module->deactivate_name = NULL;
     module->pf_activate = NULL;
     module->pf_deactivate = NULL;
     return module;
@@ -252,12 +254,12 @@ static int vlc_plugin_setter(void *ctx, void *tgt, int propid, ...)
             break;
 
         case VLC_MODULE_CB_OPEN:
-            va_arg(ap, const char *);
+            module->activate_name = va_arg(ap, const char *);
             module->pf_activate = va_arg (ap, void *);
             break;
 
         case VLC_MODULE_CB_CLOSE:
-            va_arg(ap, const char *);
+            module->deactivate_name = va_arg(ap, const char *);
             module->pf_deactivate = va_arg (ap, void *);
             break;
 
@@ -420,7 +422,7 @@ static int vlc_plugin_setter(void *ctx, void *tgt, int propid, ...)
         {
             void *cb;
 
-            va_arg(ap, const char *);
+            item->list_cb_name = va_arg(ap, const char *);
             cb = va_arg(ap, void *);
 
             if (IsConfigIntegerType (item->i_type))
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 387ab62..9bd717e 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -97,6 +97,8 @@ struct module_t
     int      i_score;                          /**< Score for the capability */
 
     /* Callbacks */
+    const char *activate_name;
+    const char *deactivate_name;
     void *pf_activate;
     void *pf_deactivate;
 };



More information about the vlc-commits mailing list