[vlc-commits] modules: move configuration items into vlc_plugin_t
Rémi Denis-Courmont
git at videolan.org
Thu Oct 27 09:51:33 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 27 00:10:53 2016 +0300| [17276385f0cfa19254d40986a1ffa4c4fb34540b] | committer: Rémi Denis-Courmont
modules: move configuration items into vlc_plugin_t
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=17276385f0cfa19254d40986a1ffa4c4fb34540b
---
src/config/cmdline.c | 35 ++++++------------------------
src/config/core.c | 29 ++++++++-----------------
src/config/file.c | 13 +++++------
src/config/help.c | 27 +++++++++--------------
src/modules/bank.c | 26 +++++++++++-----------
src/modules/cache.c | 60 ++++++++++++++++++++++++++++-----------------------
src/modules/entry.c | 27 ++++++++++++-----------
src/modules/modules.c | 13 +++++++++--
src/modules/modules.h | 24 ++++++++++++++-------
9 files changed, 119 insertions(+), 135 deletions(-)
diff --git a/src/config/cmdline.c b/src/config/cmdline.c
index 5f1e390..376f736 100644
--- a/src/config/cmdline.c
+++ b/src/config/cmdline.c
@@ -64,40 +64,28 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
#define b_ignore_errors (pindex == NULL)
/* Short options */
- module_config_t *pp_shortopts[256];
+ const module_config_t *pp_shortopts[256];
char *psz_shortopts;
- /* List all modules */
- size_t count;
- module_t **list = module_list_get (&count);
-
/*
* Generate the longopts and shortopts structures used by getopt_long
*/
i_opts = 0;
- for (size_t i = 0; i < count; i++)
- {
+ for (const vlc_plugin_t *p = vlc_plugins; p != NULL; p = p->next)
/* count the number of exported configuration options (to allocate
* longopts). We also need to allocate space for two options when
* dealing with boolean to allow for --foo and --no-foo */
- module_t *p_parser = list[i];
-
- i_opts += p_parser->i_config_items + 2 * p_parser->i_bool_items;
- }
+ i_opts += p->conf.count + 2 * p->conf.booleans;
p_longopts = malloc( sizeof(*p_longopts) * (i_opts + 1) );
if( p_longopts == NULL )
- {
- module_list_free (list);
return -1;
- }
psz_shortopts = malloc( 2 * i_opts + 1 );
if( psz_shortopts == NULL )
{
free( p_longopts );
- module_list_free (list);
return -1;
}
@@ -111,7 +99,6 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
{
free( psz_shortopts );
free( p_longopts );
- module_list_free (list);
return -1;
}
memcpy( argv_copy, ppsz_argv, i_argc * sizeof(char *) );
@@ -126,17 +113,12 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
/* Fill the p_longopts and psz_shortopts structures */
i_index = 0;
- for (size_t i = 0; i < count; i++)
+ for (const vlc_plugin_t *p = vlc_plugins; p != NULL; p = p->next)
{
- module_t *p_parser = list[i];
- module_config_t *p_item, *p_end;
-
- if( !p_parser->i_config_items )
- continue;
-
- for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
+ for (const module_config_t *p_item = p->conf.items,
+ *p_end = p_item + p->conf.size;
p_item < p_end;
- p_item++ )
+ p_item++)
{
/* Ignore hints */
if( !CONFIG_ITEM(p_item->i_type) )
@@ -191,9 +173,6 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
}
}
- /* We don't need the module list anymore */
- module_list_free( list );
-
/* Close the longopts and shortopts structures */
memset( &p_longopts[i_index], 0, sizeof(*p_longopts) );
psz_shortopts[i_shortopts] = '\0';
diff --git a/src/config/core.c b/src/config/core.c
index f6285bf..f1fc516 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -511,26 +511,22 @@ static struct
*/
int config_SortConfig (void)
{
- size_t nmod, nconf = 0;
- module_t **mlist = module_list_get (&nmod);
+ vlc_plugin_t *p;
+ size_t nconf = 0;
- for (size_t i = 0; i < nmod; i++)
- nconf += mlist[i]->confsize;
+ for (p = vlc_plugins; p != NULL; p = p->next)
+ nconf += p->conf.size;
module_config_t **clist = malloc (sizeof (*clist) * nconf);
if (unlikely(clist == NULL))
- {
- module_list_free (mlist);
return VLC_ENOMEM;
- }
nconf = 0;
- for (size_t i = 0; i < nmod; i++)
+ for (p = vlc_plugins; p != NULL; p = p->next)
{
- module_t *parser = mlist[i];
module_config_t *item, *end;
- for (item = parser->p_config, end = item + parser->confsize;
+ for (item = p->conf.items, end = item + p->conf.size;
item < end;
item++)
{
@@ -539,7 +535,6 @@ int config_SortConfig (void)
clist[nconf++] = item;
}
}
- module_list_free (mlist);
qsort (clist, nconf, sizeof (*clist), confcmp);
@@ -606,17 +601,12 @@ void config_Free (module_config_t *tab, size_t confsize)
*****************************************************************************/
void config_ResetAll( vlc_object_t *p_this )
{
- size_t count;
- module_t **list = module_list_get (&count);
-
vlc_rwlock_wrlock (&config_lock);
- for (size_t j = 0; j < count; j++)
+ for (vlc_plugin_t *p = vlc_plugins; p != NULL; p = p->next)
{
- module_t *p_module = list[j];
-
- for (size_t i = 0; i < p_module->confsize; i++ )
+ for (size_t i = 0; i < p->conf.size; i++ )
{
- module_config_t *p_config = p_module->p_config + i;
+ module_config_t *p_config = p->conf.items + i;
if (IsConfigIntegerType (p_config->i_type))
p_config->value.i = p_config->orig.i;
@@ -634,6 +624,5 @@ void config_ResetAll( vlc_object_t *p_this )
}
vlc_rwlock_unlock (&config_lock);
- module_list_free (list);
VLC_UNUSED(p_this);
}
diff --git a/src/config/file.c b/src/config/file.c
index c897769..50240ee 100644
--- a/src/config/file.c
+++ b/src/config/file.c
@@ -421,14 +421,12 @@ int config_SaveConfigFile (vlc_object_t *p_this)
vlc_rwlock_rdlock (&config_lock);*/
/* Look for the selected module, if NULL then save everything */
- size_t count;
- module_t **list = module_list_get (&count);
- for (size_t i = 0; i < count; i++)
+ for (vlc_plugin_t *p = vlc_plugins; p != NULL; p = p->next)
{
- module_t *p_parser = list[i];
+ module_t *p_parser = p->module;
module_config_t *p_item, *p_end;
- if( !p_parser->i_config_items )
+ if (p->conf.count == 0)
continue;
fprintf( file, "[%s]", module_get_object (p_parser) );
@@ -437,9 +435,9 @@ int config_SaveConfigFile (vlc_object_t *p_this)
else
fprintf( file, "\n\n" );
- for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
+ for (p_item = p->conf.items, p_end = p_item + p->conf.size;
p_item < p_end;
- p_item++ )
+ p_item++)
{
if (!CONFIG_ITEM(p_item->i_type) /* ignore hint */
|| p_item->b_removed /* ignore deprecated option */
@@ -480,7 +478,6 @@ int config_SaveConfigFile (vlc_object_t *p_this)
}
vlc_rwlock_unlock (&config_lock);
- module_list_free (list);
if (loc != (locale_t)0)
{
uselocale (baseloc);
diff --git a/src/config/help.c b/src/config/help.c
index 5723a40..5298f15 100644
--- a/src/config/help.c
+++ b/src/config/help.c
@@ -537,11 +537,11 @@ static bool module_match(const module_t *m, const char *pattern, bool strict)
return false;
}
-static bool module_show(const module_t *m, bool advanced)
+static bool plugin_show(const vlc_plugin_t *plugin, bool advanced)
{
- for (size_t i = 0; i < m->confsize; i++)
+ for (size_t i = 0; i < plugin->conf.size; i++)
{
- const module_config_t *item = m->p_config + i;
+ const module_config_t *item = plugin->conf.items + i;
if (!CONFIG_ITEM(item->i_type))
continue;
@@ -576,25 +576,21 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
const bool desc = var_InheritBool(p_this, "help-verbose");
const bool advanced = var_InheritBool(p_this, "advanced");
- /* List all modules */
- size_t count;
- module_t **list = module_list_get (&count);
-
/* Enumerate the config for each module */
- for (size_t i = 0; i < count; i++)
+ for (const vlc_plugin_t *p = vlc_plugins; p != NULL; p = p->next)
{
- const module_t *m = list[i];
+ const module_t *m = p->module;
const module_config_t *section = NULL;
const char *objname = module_get_object(m);
- if (m->i_config_items == 0)
+ if (p->conf.count == 0)
continue; /* Ignore modules without config options */
if (!module_match(m, psz_search, strict))
continue;
found = true;
- if (!module_show(m, advanced))
- { /* Ignore modules with only advanced config options if requested */
+ if (!plugin_show(p, advanced))
+ { /* Ignore plugins with only advanced config options if requested */
i_only_advanced++;
continue;
}
@@ -607,9 +603,9 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
module_gettext(m, m->psz_help));
/* Print module options */
- for (size_t j = 0; j < m->confsize; j++)
+ for (size_t j = 0; j < p->conf.size; j++)
{
- const module_config_t *item = m->p_config + j;
+ const module_config_t *item = p->conf.items + j;
if (item->b_removed)
continue; /* Skip removed options */
@@ -638,9 +634,6 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
printf(color ? "\n" WHITE "%s" GRAY "\n" : "\n%s\n",
_("No matching module found. Use --list or "
"--list-verbose to list available modules."));
-
- /* Release the module list */
- module_list_free (list);
}
/*****************************************************************************
diff --git a/src/modules/bank.c b/src/modules/bank.c
index c6b33a5..1bdbaf6 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -49,16 +49,17 @@
static struct
{
vlc_mutex_t lock;
- vlc_plugin_t *libs;
block_t *caches;
unsigned usage;
-} modules = { VLC_STATIC_MUTEX, NULL, NULL, 0 };
+} modules = { VLC_STATIC_MUTEX, NULL, 0 };
+
+vlc_plugin_t *vlc_plugins = NULL;
static void module_StoreBank(vlc_plugin_t *lib)
{
/*vlc_assert_locked (&modules.lock);*/
- lib->next = modules.libs;
- modules.libs = lib;
+ lib->next = vlc_plugins;
+ vlc_plugins = lib;
}
/**
@@ -211,10 +212,11 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
/* For now we force loading if the module's config contains callbacks.
* Could be optimized by adding an API call.*/
- for (size_t n = module->confsize, i = 0; i < n; i++)
+ for (size_t i = 0; i < plugin->conf.size; i++)
if (!module->b_loaded
- && module->p_config[i].list_count == 0
- && (module->p_config[i].list.psz_cb != NULL || module->p_config[i].list.i_cb != NULL))
+ && plugin->conf.items[i].list_count == 0
+ && (plugin->conf.items[i].list.psz_cb != NULL
+ || plugin->conf.items[i].list.i_cb != NULL))
{
/* !unloadable not allowed for plugins with callbacks */
vlc_plugin_destroy(plugin);
@@ -459,9 +461,9 @@ void module_EndBank (bool b_plugins)
if (--modules.usage == 0)
{
config_UnsortConfig ();
- libs = modules.libs;
+ libs = vlc_plugins;
caches = modules.caches;
- modules.libs = NULL;
+ vlc_plugins = NULL;
modules.caches = NULL;
}
vlc_mutex_unlock (&modules.lock);
@@ -540,7 +542,7 @@ module_t **module_list_get (size_t *n)
assert (n != NULL);
- for (vlc_plugin_t *lib = modules.libs; lib != NULL; lib = lib->next)
+ for (vlc_plugin_t *lib = vlc_plugins; lib != NULL; lib = lib->next)
{
module_t *mod = lib->module;
assert(mod != NULL);
@@ -586,7 +588,7 @@ ssize_t module_list_cap (module_t ***restrict list, const char *cap)
assert (list != NULL);
- for (vlc_plugin_t *lib = modules.libs; lib != NULL; lib = lib->next)
+ for (vlc_plugin_t *lib = vlc_plugins; lib != NULL; lib = lib->next)
{
module_t *mod = lib->module;
assert(mod != NULL);
@@ -603,7 +605,7 @@ ssize_t module_list_cap (module_t ***restrict list, const char *cap)
if (unlikely(tab == NULL))
return -1;
- for (vlc_plugin_t *lib = modules.libs; lib != NULL; lib = lib->next)
+ for (vlc_plugin_t *lib = vlc_plugins; lib != NULL; lib = lib->next)
{
module_t *mod = lib->module;
assert(mod != NULL);
diff --git a/src/modules/cache.c b/src/modules/cache.c
index 95473df..07901a3 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -179,7 +179,7 @@ static int vlc_cache_load_align(size_t align, block_t *file)
if (vlc_cache_load_align(alignof(t), file)) \
goto error
-static int CacheLoadConfig(module_config_t *cfg, block_t *file)
+static int vlc_cache_load_config(module_config_t *cfg, block_t *file)
{
LOAD_IMMEDIATE (cfg->i_type);
LOAD_IMMEDIATE (cfg->i_short);
@@ -244,7 +244,7 @@ error:
return -1; /* FIXME: leaks */
}
-static int CacheLoadModuleConfig(module_t *module, block_t *file)
+static int vlc_cache_load_plugin_config(vlc_plugin_t *plugin, block_t *file)
{
uint16_t lines;
@@ -254,30 +254,31 @@ static int CacheLoadModuleConfig(module_t *module, block_t *file)
/* Allocate memory */
if (lines)
{
- module->p_config = calloc (1, lines * sizeof (module_config_t));
- if (unlikely(module->p_config == NULL))
+ plugin->conf.items = calloc(sizeof (module_config_t), lines);
+ if (unlikely(plugin->conf.items == NULL))
{
- module->confsize = 0;
+ plugin->conf.size = 0;
return -1;
}
}
else
- module->p_config = NULL;
- module->confsize = lines;
+ plugin->conf.items = NULL;
+
+ plugin->conf.size = lines;
/* Do the duplication job */
for (size_t i = 0; i < lines; i++)
- if (CacheLoadConfig (module->p_config + i, file))
+ {
+ module_config_t *item = plugin->conf.items + i;
+
+ if (vlc_cache_load_config(item, file))
return -1;
- for (size_t i = 0; i < lines; i++)
- {
- unsigned type = module->p_config[i].i_type;
- if (CONFIG_ITEM(type))
+ if (CONFIG_ITEM(item->i_type))
{
- module->i_config_items++;
- if (type == CONFIG_ITEM_BOOL)
- module->i_bool_items++;
+ plugin->conf.count++;
+ if (item->i_type == CONFIG_ITEM_BOOL)
+ plugin->conf.booleans++;
}
}
@@ -343,10 +344,6 @@ static module_t *vlc_cache_load_module(vlc_plugin_t *plugin, block_t *file)
LOAD_IMMEDIATE(submodule->i_score);
}
- /* Config stuff */
- if (CacheLoadModuleConfig(module, file) != VLC_SUCCESS)
- goto error;
-
return module;
error:
vlc_module_destroy(module);
@@ -360,9 +357,17 @@ static vlc_plugin_t *vlc_cache_load_plugin(block_t *file)
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;
+ if (vlc_cache_load_plugin_config(plugin, file))
+ goto error;
+
const char *path;
LOAD_STRING(path);
if (path == NULL)
@@ -574,14 +579,14 @@ error:
return -1;
}
-static int CacheSaveModuleConfig (FILE *file, const module_t *module)
+static int CacheSaveModuleConfig(FILE *file, const vlc_plugin_t *plugin)
{
- uint16_t lines = module->confsize;
+ uint16_t lines = plugin->conf.size;
SAVE_IMMEDIATE (lines);
for (size_t i = 0; i < lines; i++)
- if (CacheSaveConfig (file, module->p_config + i))
+ if (CacheSaveConfig(file, plugin->conf.items + i))
goto error;
return 0;
@@ -635,7 +640,8 @@ static int CacheSaveBank(FILE *file, vlc_plugin_t *const *cache, size_t n)
for (size_t i = 0; i < n; i++)
{
- const module_t *module = cache[i]->module;
+ const vlc_plugin_t *plugin = cache[i];
+ const module_t *module = plugin->module;
uint32_t i_submodule;
/* Save additional infos */
@@ -658,13 +664,13 @@ static int CacheSaveBank(FILE *file, vlc_plugin_t *const *cache, size_t n)
goto error;
/* Config stuff */
- if (CacheSaveModuleConfig (file, module))
+ if (CacheSaveModuleConfig(file, plugin))
goto error;
/* Save common info */
- SAVE_STRING(cache[i]->path);
- SAVE_IMMEDIATE(cache[i]->mtime);
- SAVE_IMMEDIATE(cache[i]->size);
+ SAVE_STRING(plugin->path);
+ SAVE_IMMEDIATE(plugin->mtime);
+ SAVE_IMMEDIATE(plugin->size);
}
if (fflush (file)) /* flush libc buffers */
diff --git a/src/modules/entry.c b/src/modules/entry.c
index ad66676..b77bd6b 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -67,10 +67,6 @@ module_t *vlc_module_create(vlc_plugin_t *plugin)
module->b_unloadable = parent == NULL;
module->pf_activate = NULL;
module->pf_deactivate = NULL;
- module->p_config = NULL;
- module->confsize = 0;
- module->i_config_items = 0;
- module->i_bool_items = 0;
/*module->handle = garbage */
module->psz_filename = NULL;
module->domain = NULL;
@@ -90,7 +86,6 @@ void vlc_module_destroy (module_t *module)
vlc_module_destroy (m);
}
- config_Free (module->p_config, module->confsize);
free (module->psz_filename);
free (module->pp_shortcuts);
free (module);
@@ -108,14 +103,15 @@ void vlc_plugin_destroy(vlc_plugin_t *plugin)
if (plugin->module != NULL)
vlc_module_destroy(plugin->module);
+ config_Free(plugin->conf.items, plugin->conf.size);
free(plugin->path);
free(plugin);
}
-static module_config_t *vlc_config_create (module_t *module, int type)
+static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
{
- unsigned confsize = module->confsize;
- module_config_t *tab = module->p_config;
+ unsigned confsize = plugin->conf.size;
+ module_config_t *tab = plugin->conf.items;
if ((confsize & 0xf) == 0)
{
@@ -123,7 +119,7 @@ static module_config_t *vlc_config_create (module_t *module, int type)
if (tab == NULL)
return NULL;
- module->p_config = tab;
+ plugin->conf.items = tab;
}
memset (tab + confsize, 0, sizeof (tab[confsize]));
@@ -141,12 +137,12 @@ static module_config_t *vlc_config_create (module_t *module, int type)
if (CONFIG_ITEM(type))
{
- module->i_config_items++;
+ plugin->conf.count++;
if (type == CONFIG_ITEM_BOOL)
- module->i_bool_items++;
+ plugin->conf.booleans++;
}
- module->confsize++;
+ plugin->conf.size++;
return tab + confsize;
}
@@ -198,7 +194,7 @@ static int vlc_plugin_setter(void *ctx, void *tgt, int propid, ...)
int type = va_arg (ap, int);
module_config_t **pp = va_arg (ap, module_config_t **);
- item = vlc_config_create(plugin->module, type);
+ item = vlc_config_create(plugin, type);
if (unlikely(item == NULL))
{
ret = -1;
@@ -439,6 +435,11 @@ vlc_plugin_t *vlc_plugin_describe(vlc_plugin_cb entry)
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.c b/src/modules/modules.c
index a8decee..4f72e59 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -422,8 +422,17 @@ bool module_exists (const char * psz_name)
*/
module_config_t *module_config_get( const module_t *module, unsigned *restrict psize )
{
+ const vlc_plugin_t *plugin = module->plugin;
+
+ if (plugin->module != NULL)
+ { /* For backward compatibility, pretend non-first modules have no
+ * configuration items. */
+ *psize = 0;
+ return NULL;
+ }
+
unsigned i,j;
- unsigned size = module->confsize;
+ size_t size = plugin->conf.size;
module_config_t *config = malloc( size * sizeof( *config ) );
assert( psize != NULL );
@@ -434,7 +443,7 @@ module_config_t *module_config_get( const module_t *module, unsigned *restrict p
for( i = 0, j = 0; i < size; i++ )
{
- const module_config_t *item = module->p_config + i;
+ const module_config_t *item = plugin->conf.items + i;
if( item->b_internal /* internal option */
|| item->b_removed /* removed option */ )
continue;
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 1dc9b76..bee8824 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -24,6 +24,7 @@
#ifndef LIBVLC_MODULES_H
# define LIBVLC_MODULES_H 1
+/** VLC plugin */
typedef struct vlc_plugin_t
{
struct vlc_plugin_t *next;
@@ -33,8 +34,23 @@ typedef struct vlc_plugin_t
off_t size; /**< File size */
module_t *module;
+
+ /**
+ * Variables set by the module to store its config options
+ */
+ struct
+ {
+ module_config_t *items; /**< Table of configuration parameters */
+ size_t size; /**< Size of items table */
+ size_t count; /**< Number of configuration items */
+ size_t booleans; /**< Number of booleal config items */
+ } conf;
} vlc_plugin_t;
+/**
+ * List of all plug-ins.
+ */
+extern struct vlc_plugin_t *vlc_plugins;
#define MODULE_SHORTCUT_MAX 20
@@ -79,14 +95,6 @@ struct module_t
void *pf_deactivate;
/*
- * Variables set by the module to store its config options
- */
- module_config_t *p_config; /* Module configuration structure */
- size_t confsize; /* Number of module_config_t items */
- unsigned int i_config_items; /* number of configuration items */
- unsigned int i_bool_items; /* number of bool config items */
-
- /*
* Variables used internally by the module manager
*/
/* Plugin-specific stuff */
More information about the vlc-commits
mailing list