[vlc-commits] config: assert that option exists

Rémi Denis-Courmont git at videolan.org
Wed Feb 28 19:12:00 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb 28 19:04:17 2018 +0200| [0f69e188d4c7c130db30707c9fd3b70c0bc10fa2] | committer: Rémi Denis-Courmont

config: assert that option exists

We already assert that the type is correct. Only one call site actually
checks for the error return value, and even this, it is debatable
(that is var_Create(VLC_VAR_BOOL)). So an assertion makes more sense
that printing an error.

In some cases (e.g. Lua), we use config_GetType() ahead to check for
errors though - that still works fine.

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

 src/config/core.c | 42 ++++++------------------------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

diff --git a/src/config/core.c b/src/config/core.c
index 6b4f6d97dc..255f3c7ab8 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -83,12 +83,7 @@ int64_t config_GetInt( vlc_object_t *p_this, const char *psz_name )
     module_config_t *p_config = config_FindConfig( psz_name );
 
     /* sanity checks */
-    if( !p_config )
-    {
-        msg_Err( p_this, "option %s does not exist", psz_name );
-        return -1;
-    }
-
+    assert(p_config != NULL);
     assert(IsConfigIntegerType(p_config->i_type));
 
     int64_t val;
@@ -107,12 +102,7 @@ float config_GetFloat( vlc_object_t *p_this, const char *psz_name )
     p_config = config_FindConfig( psz_name );
 
     /* sanity checks */
-    if( !p_config )
-    {
-        msg_Err( p_this, "option %s does not exist", psz_name );
-        return -1;
-    }
-
+    assert(p_config != NULL);
     assert(IsConfigFloatType(p_config->i_type));
 
     float val;
@@ -131,12 +121,7 @@ char * config_GetPsz( vlc_object_t *p_this, const char *psz_name )
     p_config = config_FindConfig( psz_name );
 
     /* sanity checks */
-    if( !p_config )
-    {
-        msg_Err( p_this, "option %s does not exist", psz_name );
-        return NULL;
-    }
-
+    assert(p_config != NULL);
     assert(IsConfigStringType (p_config->i_type));
 
     /* return a copy of the string */
@@ -155,12 +140,7 @@ void config_PutPsz( vlc_object_t *p_this,
 
 
     /* sanity checks */
-    if( !p_config )
-    {
-        msg_Warn( p_this, "option %s does not exist", psz_name );
-        return;
-    }
-
+    assert(p_config != NULL);
     assert(IsConfigStringType(p_config->i_type));
 
     char *str, *oldstr;
@@ -185,12 +165,7 @@ void config_PutInt( vlc_object_t *p_this, const char *psz_name,
     module_config_t *p_config = config_FindConfig( psz_name );
 
     /* sanity checks */
-    if( !p_config )
-    {
-        msg_Warn( p_this, "option %s does not exist", psz_name );
-        return;
-    }
-
+    assert(p_config != NULL);
     assert(IsConfigIntegerType(p_config->i_type));
 
     if (i_value < p_config->min.i)
@@ -211,12 +186,7 @@ void config_PutFloat( vlc_object_t *p_this,
     module_config_t *p_config = config_FindConfig( psz_name );
 
     /* sanity checks */
-    if( !p_config )
-    {
-        msg_Warn( p_this, "option %s does not exist", psz_name );
-        return;
-    }
-
+    assert(p_config != NULL);
     assert(IsConfigFloatType(p_config->i_type));
 
     /* if f_min == f_max == 0, then do not use them */



More information about the vlc-commits mailing list