[vlc-commits] [Git][videolan/vlc][master] 8 commits: modules: change internal function return type
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Sat Nov 6 16:48:39 UTC 2021
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
fd57f0cd by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
modules: change internal function return type
(No functional changes.)
- - - - -
2ee36c2f by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
modules: use opaque structure type in descriptors
No effective functional or ABI changes.
- - - - -
6b327a73 by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
config: introduce vlc_param_Find()
- - - - -
31a94681 by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
config: use vlc_param_Find() in config_GetType()
- - - - -
19a0d2ac by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
config: use vlc_param_Find() in config_IsSafe()
- - - - -
d4904572 by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
config: use vlc_param_Find() in config_Get*Choices()
Also match the semantics of both functions.
- - - - -
82956e7b by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
config: use vlc_param_Find() in config_ChainParse()
- - - - -
52424a5e by Rémi Denis-Courmont at 2021-11-06T16:34:53+00:00
config: use vlc_param_Find() in config_LoadConfigFile()
- - - - -
6 changed files:
- include/vlc_plugin.h
- src/config/chain.c
- src/config/configuration.h
- src/config/core.c
- src/config/file.c
- src/modules/entry.c
Changes:
=====================================
include/vlc_plugin.h
=====================================
@@ -256,6 +256,8 @@ enum vlc_module_properties
# define DLL_SYMBOL
#endif
+struct vlc_param;
+
EXTERN_SYMBOL typedef int (*vlc_set_cb) (void *, void *, int, ...);
#define vlc_plugin_set(...) vlc_set (opaque, NULL, __VA_ARGS__)
@@ -282,7 +284,7 @@ EXTERN_SYMBOL DLL_SYMBOL \
int CDECL_SYMBOL VLC_SYMBOL(vlc_entry)(vlc_set_cb vlc_set, void *opaque) \
{ \
module_t *module; \
- module_config_t *config = NULL; \
+ struct vlc_param *config = NULL; \
if (vlc_plugin_set (VLC_MODULE_CREATE, &module)) \
goto error; \
if (vlc_module_set (VLC_MODULE_NAME, (MODULE_STRING))) \
=====================================
src/config/chain.c
=====================================
@@ -311,8 +311,6 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
vlc_value_t val;
bool b_yes = true;
bool b_once = false;
- module_config_t *p_conf;
- int i_type;
size_t i;
if( cfg->psz_name == NULL || *cfg->psz_name == '\0' )
@@ -354,35 +352,28 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
snprintf( name, sizeof (name), "%s%s", psz_prefix,
b_once ? (ppsz_options[i] + 1) : ppsz_options[i] );
- /* Check if the option is deprecated */
- p_conf = config_FindConfig( name );
+ const struct vlc_param *param = vlc_param_Find(name);
+ if (param == NULL)
+ {
+ msg_Warn(p_this, "unknown option %s", name);
+ continue;
+ }
+
+ /* Check if the option is deprecated */
/* This is basically cut and paste from src/misc/configuration.c
* with slight changes */
- if( p_conf )
+ if (param->obsolete)
{
- struct vlc_param *param = container_of(p_conf, struct vlc_param,
- item);
- if (param->obsolete)
- {
- msg_Err( p_this, "Option %s is not supported anymore.",
- name );
- /* TODO: this should return an error and end option parsing
- * ... but doing this would change the VLC API and all the
- * modules so i'll do it later */
- continue;
- }
+ msg_Err(p_this, "Option %s is not supported any longer.", name);
+ /* TODO: this should return an error and end option parsing
+ * ... but doing this would change the VLC API and all the
+ * modules so i'll do it later */
+ continue;
}
- /* </Check if the option is deprecated> */
/* get the type of the variable */
- i_type = config_GetType( psz_name );
- if( !i_type )
- {
- msg_Warn( p_this, "unknown option %s (value=%s)",
- cfg->psz_name, cfg->psz_value );
- continue;
- }
+ const int i_type = param->item.i_type;
if( i_type != VLC_VAR_BOOL && cfg->psz_value == NULL )
{
=====================================
src/config/configuration.h
=====================================
@@ -35,6 +35,13 @@ struct vlc_param {
struct module_config_t item;
};
+/**
+ * Looks up a configuration parameter by name.
+ *
+ * \return the configuration parameter, or NULL if not found
+ */
+struct vlc_param *vlc_param_Find(const char *name);
+
int config_AutoSaveConfigFile( vlc_object_t * );
void config_Free(struct vlc_param *, size_t);
=====================================
src/config/core.c
=====================================
@@ -45,17 +45,14 @@ static inline char *strdupnull (const char *src)
return src ? strdup (src) : NULL;
}
-int config_GetType(const char *psz_name)
+int config_GetType(const char *name)
{
- module_config_t *p_config = config_FindConfig(psz_name);
+ const struct vlc_param *param = vlc_param_Find(name);
- /* sanity checks */
- if( !p_config )
- {
+ if (param == NULL)
return 0;
- }
- switch( CONFIG_CLASS(p_config->i_type) )
+ switch (CONFIG_CLASS(param->item.i_type))
{
case CONFIG_ITEM_FLOAT:
return VLC_VAR_FLOAT;
@@ -72,13 +69,9 @@ int config_GetType(const char *psz_name)
bool config_IsSafe( const char *name )
{
- module_config_t *p_config = config_FindConfig( name );
- if (p_config == NULL)
- return false;
+ const struct vlc_param *param = vlc_param_Find(name);
- const struct vlc_param *param = container_of(p_config, struct vlc_param,
- item);
- return param->safe;
+ return (param != NULL) ? param->safe : false;
}
static module_config_t * config_FindConfigChecked( const char *psz_name )
@@ -211,10 +204,14 @@ ssize_t config_GetIntChoices(const char *name,
*values = NULL;
*texts = NULL;
- module_config_t *cfg = config_FindConfigChecked(name);
- assert(cfg != NULL);
+ struct vlc_param *param = vlc_param_Find(name);
+ if (param == NULL)
+ {
+ errno = ENOENT;
+ return -1;
+ }
- struct vlc_param *param = container_of(cfg, struct vlc_param, item);
+ module_config_t *cfg = ¶m->item;
size_t count = cfg->list_count;
if (count == 0)
{
@@ -318,15 +315,14 @@ ssize_t config_GetPszChoices(const char *name,
{
*values = *texts = NULL;
- module_config_t *cfg = config_FindConfig(name);
- if (cfg == NULL)
+ struct vlc_param *param = vlc_param_Find(name);
+ if (param == NULL)
{
errno = ENOENT;
return -1;
}
- struct vlc_param *param = container_of(cfg, struct vlc_param, item);
-
+ module_config_t *cfg = ¶m->item;
switch (cfg->i_type)
{
case CONFIG_ITEM_MODULE:
@@ -457,14 +453,23 @@ void config_UnsortConfig (void)
free (clist);
}
+struct vlc_param *vlc_param_Find(const char *name)
+{
+ struct vlc_param *const *p;
+
+ assert(name != NULL);
+ p = bsearch (name, config.list, config.count, sizeof (*p), confnamecmp);
+ return (p != NULL) ? *p : NULL;
+}
+
module_config_t *config_FindConfig(const char *name)
{
if (unlikely(name == NULL))
return NULL;
- struct vlc_param *const *p;
- p = bsearch (name, config.list, config.count, sizeof (*p), confnamecmp);
- return p ? &(*p)->item : NULL;
+ struct vlc_param *param = vlc_param_Find(name);
+
+ return (param != NULL) ? ¶m->item : NULL;
}
/**
=====================================
src/config/file.c
=====================================
@@ -201,11 +201,10 @@ int config_LoadConfigFile( vlc_object_t *p_this )
continue; /* syntax error */
*ptr = '\0';
- module_config_t *item = config_FindConfig(psz_option_name);
- if (item == NULL)
+ struct vlc_param *param = vlc_param_Find(psz_option_name);
+ if (param == NULL)
continue;
- struct vlc_param *param = container_of (item, struct vlc_param, item);
/* Reject values of options that are unsaveable */
if (param->unsaved)
continue;
@@ -213,6 +212,7 @@ int config_LoadConfigFile( vlc_object_t *p_this )
if (param->obsolete)
continue;
+ module_config_t *item = ¶m->item;
const char *psz_option_value = ptr + 1;
switch (CONFIG_CLASS(item->i_type))
{
=====================================
src/modules/entry.c
=====================================
@@ -137,7 +137,7 @@ void vlc_plugin_destroy(vlc_plugin_t *plugin)
free(plugin);
}
-static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
+static struct vlc_param *vlc_config_create(vlc_plugin_t *plugin, int type)
{
unsigned confsize = plugin->conf.size;
struct vlc_param *tab = plugin->conf.params;
@@ -178,7 +178,7 @@ static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
}
plugin->conf.size++;
- return item;
+ return param;
}
/**
@@ -191,7 +191,6 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
{
vlc_plugin_t *plugin = ctx;
module_t *module = tgt;
- module_config_t *item = tgt;
va_list ap;
int ret = 0;
@@ -226,15 +225,11 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
case VLC_CONFIG_CREATE:
{
int type = va_arg (ap, int);
- module_config_t **pp = va_arg (ap, module_config_t **);
+ struct vlc_param *param = vlc_config_create(plugin, type);
- item = vlc_config_create(plugin, type);
- if (unlikely(item == NULL))
- {
+ *va_arg(ap, struct vlc_param **)= param;
+ if (unlikely(param == NULL))
ret = -1;
- break;
- }
- *pp = item;
break;
}
@@ -318,16 +313,20 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
case VLC_CONFIG_NAME:
{
+ struct vlc_param *param = tgt;
const char *name = va_arg (ap, const char *);
assert (name != NULL);
- item->psz_name = name;
+ param->item.psz_name = name;
break;
}
case VLC_CONFIG_VALUE:
{
- if (IsConfigIntegerType (item->i_type)
+ struct vlc_param *param = tgt;
+ module_config_t *item = ¶m->item;
+
+ if (IsConfigIntegerType(item->i_type)
|| !CONFIG_ITEM(item->i_type))
{
item->orig.i =
@@ -351,6 +350,9 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
case VLC_CONFIG_RANGE:
{
+ struct vlc_param *param = tgt;
+ module_config_t *item = ¶m->item;
+
if (IsConfigFloatType (item->i_type))
{
item->min.f = va_arg (ap, double);
@@ -366,55 +368,65 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
case VLC_CONFIG_VOLATILE:
{
- struct vlc_param *param = container_of (item, struct vlc_param,
- item);
+ struct vlc_param *param = tgt;
+
param->unsaved = true;
break;
}
case VLC_CONFIG_PRIVATE:
{
- struct vlc_param *param = container_of (item, struct vlc_param,
- item);
+ struct vlc_param *param = tgt;
+
param->internal = true;
break;
}
case VLC_CONFIG_REMOVED:
{
- struct vlc_param *param = container_of (item, struct vlc_param,
- item);
+ struct vlc_param *param = tgt;
+
param->obsolete = true;
break;
}
case VLC_CONFIG_CAPABILITY:
- item->psz_type = va_arg (ap, const char *);
+ {
+ struct vlc_param *param = tgt;
+
+ param->item.psz_type = va_arg(ap, const char *);
break;
+ }
case VLC_CONFIG_SHORTCUT:
{
- struct vlc_param *param = container_of (item, struct vlc_param,
- item);
+ struct vlc_param *param = tgt;
+
param->shortname = va_arg(ap, int);
break;
}
case VLC_CONFIG_SAFE:
{
- struct vlc_param *param = container_of (item, struct vlc_param,
- item);
+ struct vlc_param *param = tgt;
+
param->safe = true;
break;
}
case VLC_CONFIG_DESC:
- item->psz_text = va_arg (ap, const char *);
- item->psz_longtext = va_arg (ap, const char *);
+ {
+ struct vlc_param *param = tgt;
+
+ param->item.psz_text = va_arg(ap, const char *);
+ param->item.psz_longtext = va_arg(ap, const char *);
break;
+ }
case VLC_CONFIG_LIST:
{
+ struct vlc_param *param = tgt;
+ module_config_t *item = ¶m->item;
size_t len = va_arg (ap, size_t);
assert (item->list_count == 0); /* cannot replace choices */
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/06a222e3b6366f391b1183641e3c88627ac16242...52424a5e24890561fec059c01127cf3fc48f56b6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/06a222e3b6366f391b1183641e3c88627ac16242...52424a5e24890561fec059c01127cf3fc48f56b6
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list