variables: inline var_FreeList() in simple loops

This works like config choices.
This commit is contained in:
Rémi Denis-Courmont 2018-06-10 11:36:33 +03:00
parent 5d31da4eca
commit 7048874668
7 changed files with 59 additions and 35 deletions

View File

@ -1138,14 +1138,12 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
msg_rc( "+----[ %s ]", name );
for ( size_t i = 0; i < count; i++ )
{
if ( i_value == val.p_values[i].i_int )
msg_rc( "| %"PRId64" - %s *", val.p_values[i].i_int,
text[i] );
else
msg_rc( "| %"PRId64" - %s", val.p_values[i].i_int,
text[i] );
msg_rc( "| %"PRId64" - %s%s", val.p_values[i].i_int, text[i],
(i_value == val.p_values[i].i_int) ? " *" : "" );
free(text[i]);
}
var_FreeList( &val, &text );
free(text);
free(val.p_values);
msg_rc( "+----[ end of %s ]", name );
}
free( name );
@ -1593,25 +1591,25 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
{
for ( size_t i = 0; i < count; i++ )
{
if ( f_value == val.p_values[i].f_float )
msg_rc( "| %f - %s *", val.p_values[i].f_float, text[i] );
else
msg_rc( "| %f - %s", val.p_values[i].f_float, text[i] );
msg_rc( "| %f - %s%s", val.p_values[i].f_float, text[i],
f_value == val.p_values[i].f_float ? " *" : "" );
free(text[i]);
}
}
else
{
for ( size_t i = 0; i < count; i++ )
{
if ( !strcmp( psz_value, val.p_values[i].psz_string ) )
msg_rc( "| %s - %s *", val.p_values[i].psz_string,
text[i] );
else
msg_rc( "| %s - %s", val.p_values[i].psz_string, text[i] );
msg_rc( "| %s - %s%s", val.p_values[i].psz_string, text[i],
strcmp(psz_value, val.p_values[i].psz_string)
? "" : " *" );
free(text[i]);
free(val.p_values[i].psz_string);
}
free( psz_value );
}
var_FreeList( &val, &text );
free(text);
free(val.p_values);
msg_rc( "+----[ end of %s ]", name );
free( name );
@ -1692,12 +1690,12 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd,
msg_rc( "+----[ %s ]", cmd );
for ( size_t i = 0; i < count; i++ )
{
if ( i_value == val.p_values[i].i_int )
msg_rc( "| %"PRId64" - %s *", val.p_values[i].i_int, text[i] );
else
msg_rc( "| %"PRId64" - %s", val.p_values[i].i_int, text[i] );
msg_rc( "| %"PRId64" - %s%s", val.p_values[i].i_int, text[i],
i_value == val.p_values[i].i_int ? " *" : "" );
free(text[i]);
}
var_FreeList( &val, &text );
free(text);
free(val.p_values);
msg_rc( "+----[ end of %s ]", cmd );
}
else

View File

@ -1527,6 +1527,8 @@
if (!strcmp(val.psz_string, val_list.p_values[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
[lmi setState: TRUE ];
free(text_list[i]);
free(val_list.p_values[i].psz_string);
break;
case VLC_VAR_INTEGER:
@ -1542,6 +1544,8 @@
if (val_list.p_values[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
[lmi setState: TRUE ];
free(text_list[i]);
break;
default:
@ -1551,7 +1555,8 @@
/* clean up everything */
if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
var_FreeList(&val_list, &text_list);
free(text);
free(val_list.p_values);
}
- (void)toggleVar:(id)sender

View File

@ -285,10 +285,15 @@ void AspectRatioComboBox::updateRatios()
var_Change( p_vout, "aspect-ratio", VLC_VAR_GETCHOICES,
&count, &val_list, &text_list );
for( size_t i = 0; i < count; i++ )
{
addItem( qfu( text_list[i] ),
QString( val_list.p_values[i].psz_string ) );
free(text_list[i]);
free(val_list.p_values[i].psz_string);
}
setEnabled( true );
var_FreeList( &val_list, &text_list );
free(text_list);
free(val_list.p_values);
vlc_object_release( p_vout );
}

View File

@ -672,14 +672,17 @@ void ExtV4l2::Refresh( void )
for( size_t i = 0; i < count; i++ )
{
char *vartext;
const char *psz_var = text[i];
char *vartext, *psz_var = text[i];
QString name;
if( var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext ) )
continue;
if( !var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &vartext ) )
{
name = qtr(vartext);
free(vartext);
}
else
name = qfu(psz_var);
QString name = qtr( vartext );
free( vartext );
msg_Dbg( p_intf, "v4l2 control \"%" PRIx64 "\": %s (%s)",
val.p_values[i].i_int, psz_var, qtu( name ) );
@ -709,8 +712,10 @@ void ExtV4l2::Refresh( void )
qlonglong( val2.p_values[j].i_int) );
if( i_val == val2.p_values[j].i_int )
combobox->setCurrentIndex( j );
free(text2[j]);
}
var_FreeList( &val2, &text2 );
free(text2);
free(val2.p_values);
CONNECT( combobox, currentIndexChanged( int ), this,
ValueChange( int ) );
@ -774,8 +779,10 @@ void ExtV4l2::Refresh( void )
msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
break;
}
free(psz_var);
}
var_FreeList( &val, &text );
free(text);
free(val.p_values);
vlc_object_release( p_obj );
}
else

View File

@ -1426,6 +1426,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
val.psz_string && !strcmp( val.psz_string, CURVAL.psz_string ) );
free( val.psz_string );
free(CURVAL.psz_string);
break;
case VLC_VAR_INTEGER:
@ -1450,11 +1451,13 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
default:
break;
}
free(CURTEXT);
}
currentGroup = NULL;
/* clean up everything */
var_FreeList( &val_list, &text_list );
free(text_list);
free(val_list.p_values);
#undef RADIO_OR_COMMAND
#undef CURVAL

View File

@ -238,6 +238,8 @@ static int vlclua_var_get_list( lua_State *L )
if( !vlclua_pushvalue( L, val.i_type, val.p_values[i] ) )
lua_pushnil( L );
lua_settable( L, -3 );
if( (val.i_type & VLC_VAR_CLASS) == VLC_VAR_STRING )
free(val.p_values[i].psz_string);
}
lua_createtable( L, count, 0 );
@ -246,9 +248,11 @@ static int vlclua_var_get_list( lua_State *L )
lua_pushinteger( L, i + 1 );
lua_pushstring( L, text[i] );
lua_settable( L, -3 );
free(text[i]);
}
var_FreeList( &val, &text );
free(text);
free(val.p_values);
return 2;
}

View File

@ -343,7 +343,9 @@ static void test_choices( libvlc_int_t *p_libvlc )
var_Change( p_libvlc, "bla", VLC_VAR_GETCHOICES, &count, &vals, &texts );
assert( count == 1 && vals.i_count == 1 && vals.p_values[0].i_int == 1 &&
!strcmp( texts[0], "one" ) );
var_FreeList( &vals, &texts );
free(texts[0]);
free(texts);
free(vals.p_values);
var_Change( p_libvlc, "bla", VLC_VAR_CLEARCHOICES );
assert( var_CountChoices( p_libvlc, "bla" ) == 0 );