X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fvariables.c;h=355f30e30b3ea9660958ec260e0093567551c1d6;hb=4ad5f907099fde048ad49d2b83695eac93e4b008;hp=74e99f89c7385888d975be50e05901a9d5aaa531;hpb=fc43e13f0710d1c48d00983d77d87117756323a9;p=vlc diff --git a/src/misc/variables.c b/src/misc/variables.c index 74e99f89c7..355f30e30b 100644 --- a/src/misc/variables.c +++ b/src/misc/variables.c @@ -29,11 +29,11 @@ #endif #include +#include #include "variables.h" #include "libvlc.h" -#include "vlc_interface.h" #include /***************************************************************************** @@ -182,6 +182,9 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) int i_new; variable_t *p_var; static vlc_list_t dummy_null_list = {0, NULL, NULL}; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -195,7 +198,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) if( i_new >= 0 ) { /* If the types differ, variable creation failed. */ - if( (i_type & VLC_VAR_TYPE) != (p_priv->p_vars[i_new].i_type & VLC_VAR_TYPE) ) + if( (i_type & VLC_VAR_CLASS) != (p_priv->p_vars[i_new].i_type & VLC_VAR_CLASS) ) { msg_Err( p_this, "Variable '%s' (0x%04x) already exist but with a different type (0x%04x)", psz_name, p_priv->p_vars[i_new].i_type, i_type ); @@ -214,7 +217,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) if( (p_priv->i_vars & 15) == 15 ) { - p_priv->p_vars = realloc( p_priv->p_vars, + p_priv->p_vars = xrealloc( p_priv->p_vars, (p_priv->i_vars+17) * sizeof(variable_t) ); } @@ -336,6 +339,9 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) { int i_var, i; variable_t *p_var; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -372,10 +378,7 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) } /* Free callbacks if needed */ - if( p_var->p_entries ) - { - free( p_var->p_entries ); - } + free( p_var->p_entries ); free( p_var->psz_name ); free( p_var->psz_text ); @@ -386,8 +389,10 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) if( (p_priv->i_vars & 15) == 0 ) { - p_priv->p_vars = realloc( p_priv->p_vars, - (p_priv->i_vars) * sizeof( variable_t ) ); + variable_t *p_vars = realloc( p_priv->p_vars, + (p_priv->i_vars) * sizeof( variable_t ) ); + if( p_vars ) + p_priv->p_vars = p_vars; } p_priv->i_vars--; @@ -412,6 +417,9 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, int i_var, i; variable_t *p_var; vlc_value_t oldval; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -616,11 +624,8 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, p_var->psz_text = NULL; break; case VLC_VAR_GETTEXT: - p_val->psz_string = NULL; - if( p_var->psz_text ) - { - p_val->psz_string = strdup( p_var->psz_text ); - } + p_val->psz_string = p_var->psz_text ? strdup( p_var->psz_text ) + : NULL; break; case VLC_VAR_INHERITVALUE: { @@ -681,6 +686,9 @@ int __var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action, int i_ret = VLC_SUCCESS; variable_t *p_var; vlc_value_t oldval; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -738,6 +746,9 @@ int __var_GetAndSet( vlc_object_t *p_this, const char *psz_name, int i_action, int __var_Type( vlc_object_t *p_this, const char *psz_name ) { int i_var, i_type; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -764,6 +775,9 @@ int var_SetChecked( vlc_object_t *p_this, const char *psz_name, int i_ret = VLC_SUCCESS; variable_t *p_var; vlc_value_t oldval; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -776,7 +790,7 @@ int var_SetChecked( vlc_object_t *p_this, const char *psz_name, } p_var = &p_priv->p_vars[i_var]; - assert( (p_var->i_type & VLC_VAR_CLASS) == 0 || expected_type == 0 || + assert( expected_type == 0 || (p_var->i_type & VLC_VAR_CLASS) == expected_type ); /* Duplicate data if needed */ @@ -819,6 +833,8 @@ int __var_Set( vlc_object_t *p_this, const char *psz_name, vlc_value_t val ) int var_GetChecked( vlc_object_t *p_this, const char *psz_name, int expected_type, vlc_value_t *p_val ) { + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); int i_var, err = VLC_SUCCESS; @@ -829,7 +845,7 @@ int var_GetChecked( vlc_object_t *p_this, const char *psz_name, { variable_t *p_var = &p_priv->p_vars[i_var]; - assert( (p_var->i_type & VLC_VAR_CLASS) == 0 || expected_type == 0 || + assert( expected_type == 0 || (p_var->i_type & VLC_VAR_CLASS) == expected_type ); /* Really get the variable */ @@ -886,6 +902,9 @@ int __var_AddCallback( vlc_object_t *p_this, const char *psz_name, int i_var; variable_t *p_var; callback_entry_t entry; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); entry.pf_callback = pf_callback; @@ -896,6 +915,10 @@ int __var_AddCallback( vlc_object_t *p_this, const char *psz_name, i_var = GetUnused( p_this, psz_name ); if( i_var < 0 ) { +#ifndef NDEBUG + msg_Warn( p_this, "Failed to add a callback to the non-existing " + "variable '%s'", psz_name ); +#endif vlc_mutex_unlock( &p_priv->var_lock ); return i_var; } @@ -923,6 +946,12 @@ int __var_DelCallback( vlc_object_t *p_this, const char *psz_name, { int i_entry, i_var; variable_t *p_var; +#ifndef NDEBUG + bool b_found_similar = false; +#endif + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -945,15 +974,18 @@ int __var_DelCallback( vlc_object_t *p_this, const char *psz_name, } #ifndef NDEBUG else if( p_var->p_entries[i_entry].pf_callback == pf_callback ) - { - msg_Warn( p_this, "Calling var_DelCallback for '%s' with the same " - "function but not the same data.", psz_name ); - } + b_found_similar = true; #endif } if( i_entry < 0 ) { +#ifndef NDEBUG + if( b_found_similar ) + fprintf( stderr, "Calling var_DelCallback for '%s' with the same " + "function but not the same data.", psz_name ); + assert( 0 ); +#endif vlc_mutex_unlock( &p_priv->var_lock ); return VLC_EGENERIC; } @@ -976,6 +1008,9 @@ int __var_TriggerCallback( vlc_object_t *p_this, const char *psz_name ) int i_var; int i_ret = VLC_SUCCESS; variable_t *p_var; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); vlc_mutex_lock( &p_priv->var_lock ); @@ -1090,7 +1125,7 @@ void var_OptionParse( vlc_object_t *p_obj, const char *psz_option, break; case VLC_VAR_FLOAT: - val.f_float = atof( psz_value ); + val.f_float = us_atof( psz_value ); break; case VLC_VAR_STRING: @@ -1134,7 +1169,7 @@ void var_OptionParse( vlc_object_t *p_obj, const char *psz_option, goto cleanup; } - var_Set( p_obj, psz_name, val ); + __var_Set( p_obj, psz_name, val ); /* If that's a list, remove all elements allocated */ if( i_type == VLC_VAR_LIST ) @@ -1155,6 +1190,8 @@ cleanup: *****************************************************************************/ static int GetUnused( vlc_object_t *p_this, const char *psz_name ) { + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); while( true ) @@ -1497,6 +1534,9 @@ static int TriggerCallback( vlc_object_t *p_this, variable_t **pp_var, int i_var; int i_entries = (*pp_var)->i_entries; callback_entry_t *p_entries = (*pp_var)->p_entries; + + assert( p_this ); + vlc_object_internals_t *p_priv = vlc_internals( p_this ); (*pp_var)->b_incallback = true; @@ -1559,7 +1599,7 @@ int __var_Command( vlc_object_t *p_this, const char *psz_name, i_ret = var_SetInteger( p_obj, psz_cmd, atoi( psz_arg ) ); break; case VLC_VAR_FLOAT: - i_ret = var_SetFloat( p_obj, psz_cmd, atof( psz_arg ) ); + i_ret = var_SetFloat( p_obj, psz_cmd, us_atof( psz_arg ) ); break; case VLC_VAR_STRING: i_ret = var_SetString( p_obj, psz_cmd, psz_arg );