[vlc-commits] modules: factor vlc_plugin_t creation

Rémi Denis-Courmont git at videolan.org
Thu Oct 27 09:51:34 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 27 10:12:49 2016 +0300| [ca6e171352299e2de2540268bbeb4b913bc04275] | committer: Rémi Denis-Courmont

modules: factor vlc_plugin_t creation

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

 src/modules/cache.c   |  8 +-------
 src/modules/entry.c   | 27 ++++++++++++++++++---------
 src/modules/modules.h |  1 +
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index 07901a3..a7d2538 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -352,16 +352,10 @@ error:
 
 static vlc_plugin_t *vlc_cache_load_plugin(block_t *file)
 {
-    vlc_plugin_t *plugin = malloc(sizeof (*plugin));
+    vlc_plugin_t *plugin = vlc_plugin_create();
     if (unlikely(plugin == NULL))
         return NULL;
 
-    plugin->module = NULL;
-    plugin->conf.items = NULL;
-    plugin->conf.size = 0;
-    plugin->conf.count = 0;
-    plugin->conf.booleans = 0;
-
     if (vlc_cache_load_module(plugin, file) == NULL)
         goto error;
 
diff --git a/src/modules/entry.c b/src/modules/entry.c
index b77bd6b..52a0468 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -91,6 +91,23 @@ void vlc_module_destroy (module_t *module)
     free (module);
 }
 
+vlc_plugin_t *vlc_plugin_create(void)
+{
+    vlc_plugin_t *plugin = malloc(sizeof (*plugin));
+    if (unlikely(plugin == NULL))
+        return NULL;
+
+    plugin->path = NULL;
+    plugin->module = NULL;
+
+    plugin->conf.items = NULL;
+    plugin->conf.size = 0;
+    plugin->conf.count = 0;
+    plugin->conf.booleans = 0;
+
+    return plugin;
+}
+
 /**
  * Destroys a plug-in.
  * @warning If the plug-in was dynamically loaded in memory, the library handle
@@ -428,18 +445,10 @@ static int vlc_plugin_setter(void *ctx, void *tgt, int propid, ...)
  */
 vlc_plugin_t *vlc_plugin_describe(vlc_plugin_cb entry)
 {
-    vlc_plugin_t *plugin = malloc(sizeof (*plugin));
+    vlc_plugin_t *plugin = vlc_plugin_create();
     if (unlikely(plugin == NULL))
         return NULL;
 
-    plugin->path = NULL;
-    plugin->module = NULL;
-
-    plugin->conf.items = NULL;
-    plugin->conf.size = 0;
-    plugin->conf.count = 0;
-    plugin->conf.booleans = 0;
-
     if (entry(vlc_plugin_setter, plugin) != 0)
     {
         vlc_plugin_destroy(plugin); /* partially initialized plug-in... */
diff --git a/src/modules/modules.h b/src/modules/modules.h
index bee8824..a586e0b 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -103,6 +103,7 @@ struct module_t
     const char *        domain;                            /* gettext domain */
 };
 
+vlc_plugin_t *vlc_plugin_create(void);
 vlc_plugin_t *vlc_plugin_describe(vlc_plugin_cb);
 void vlc_plugin_destroy(vlc_plugin_t *);
 module_t *vlc_module_create(vlc_plugin_t *);



More information about the vlc-commits mailing list