[vlc-devel] [PATCH] config: generalize debug message for invalid config name
Alexandre Janniaux
ajanni at videolabs.io
Sun Nov 22 18:43:51 CET 2020
The commit a7d548dbdedc9669550a02121fa352f311e2cd19 introduced a debug
message when trying to access a unknown configuration item but was
limited to strings.
This commit refactor the debug code into a local function and use it at
similar places where the same kind of failure could happen.
---
src/config/core.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/config/core.c b/src/config/core.c
index 8110da4814..a3a2cb9f34 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -72,13 +72,24 @@ int config_GetType(const char *psz_name)
bool config_IsSafe( const char *name )
{
+
module_config_t *p_config = config_FindConfig( name );
return p_config != NULL && p_config->b_safe;
}
+static module_config_t * config_FindConfigChecked( const char *psz_name )
+{
+ module_config_t *p_config = config_FindConfig( psz_name );
+#ifndef NDEBUG
+ if (p_config == NULL)
+ fprintf(stderr, "Unknown vlc configuration variable named %s\n", psz_name);
+#endif
+ return p_config;
+}
+
int64_t config_GetInt(const char *psz_name)
{
- module_config_t *p_config = config_FindConfig( psz_name );
+ module_config_t *p_config = config_FindConfigChecked( psz_name );
/* sanity checks */
assert(p_config != NULL);
@@ -96,7 +107,7 @@ float config_GetFloat(const char *psz_name)
{
module_config_t *p_config;
- p_config = config_FindConfig( psz_name );
+ p_config = config_FindConfigChecked( psz_name );
/* sanity checks */
assert(p_config != NULL);
@@ -112,14 +123,7 @@ float config_GetFloat(const char *psz_name)
char *config_GetPsz(const char *psz_name)
{
- module_config_t *p_config;
-
- p_config = config_FindConfig( psz_name );
-
-#ifndef NDEBUG
- if (p_config == NULL)
- fprintf(stderr, "Unknown vlc configuration variable named %s\n", psz_name);
-#endif
+ module_config_t *p_config = config_FindConfigChecked( psz_name );
/* sanity checks */
assert(p_config != NULL);
@@ -135,8 +139,7 @@ char *config_GetPsz(const char *psz_name)
void config_PutPsz(const char *psz_name, const char *psz_value)
{
- module_config_t *p_config = config_FindConfig( psz_name );
-
+ module_config_t *p_config = config_FindConfigChecked( psz_name );
/* sanity checks */
assert(p_config != NULL);
@@ -159,7 +162,7 @@ void config_PutPsz(const char *psz_name, const char *psz_value)
void config_PutInt(const char *psz_name, int64_t i_value )
{
- module_config_t *p_config = config_FindConfig( psz_name );
+ module_config_t *p_config = config_FindConfigChecked( psz_name );
/* sanity checks */
assert(p_config != NULL);
@@ -178,7 +181,7 @@ void config_PutInt(const char *psz_name, int64_t i_value )
void config_PutFloat(const char *psz_name, float f_value)
{
- module_config_t *p_config = config_FindConfig( psz_name );
+ module_config_t *p_config = config_FindConfigChecked( psz_name );
/* sanity checks */
assert(p_config != NULL);
@@ -204,7 +207,7 @@ ssize_t config_GetIntChoices(const char *name,
*values = NULL;
*texts = NULL;
- module_config_t *cfg = config_FindConfig(name);
+ module_config_t *cfg = config_FindConfigChecked(name);
assert(cfg != NULL);
size_t count = cfg->list_count;
--
2.29.2
More information about the vlc-devel
mailing list