From 215c1a851ceb2a32c721381954ffa0b68c547432 Mon Sep 17 00:00:00 2001 From: Gildas Bazin Date: Sat, 14 Dec 2002 19:34:07 +0000 Subject: [PATCH] * src/misc/objects.c: implemented the FIND_CHILD mode for vlc_list_find(). vlc_object_get() now increments the refcount of the object so you'll need to release the object at some point. * src/misc/variables.c, ALL: var_Change() with VLC_VAR_GETLIST now returns a vlc_value_t which points to a vlc_list_t. --- include/variables.h | 5 +- include/vlc/vlc.h | 3 +- modules/control/rc/rc.c | 17 +++---- modules/gui/macosx/intf.m | 15 ++---- modules/misc/testsuite/test4.c | 12 ++--- src/libvlc.c | 39 +++++++++++++-- src/misc/objects.c | 86 ++++++++++++++++++++++++++++++---- src/misc/variables.c | 71 ++++++++++++++-------------- 8 files changed, 171 insertions(+), 77 deletions(-) diff --git a/include/variables.h b/include/variables.h index 275de0dec1..84febb153d 100644 --- a/include/variables.h +++ b/include/variables.h @@ -2,7 +2,7 @@ * variables.h: variables handling ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: variables.h,v 1.10 2002/12/13 01:56:29 gbazin Exp $ + * $Id: variables.h,v 1.11 2002/12/14 19:34:07 gbazin Exp $ * * Authors: Samuel Hocevar * @@ -51,8 +51,7 @@ struct variable_t /* If the variable is to be chosen in a list */ int i_default; - int i_choices; - vlc_value_t *pp_choices; + vlc_list_t choices; /* Set to TRUE if the variable is in a callback */ vlc_bool_t b_incallback; diff --git a/include/vlc/vlc.h b/include/vlc/vlc.h index adff93cac6..ebab90e8b9 100644 --- a/include/vlc/vlc.h +++ b/include/vlc/vlc.h @@ -2,7 +2,7 @@ * vlc.h: global header for vlc ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN - * $Id: vlc.h,v 1.19 2002/12/13 01:56:29 gbazin Exp $ + * $Id: vlc.h,v 1.20 2002/12/14 19:34:07 gbazin Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,7 @@ typedef union char * psz_string; void * p_address; vlc_object_t * p_object; + vlc_list_t * p_list; /* Make sure the structure is at least 64bits */ struct { char a, b, c, d, e, f, g, h; } padding; diff --git a/modules/control/rc/rc.c b/modules/control/rc/rc.c index 22c9fe9c30..db9a118183 100644 --- a/modules/control/rc/rc.c +++ b/modules/control/rc/rc.c @@ -2,7 +2,7 @@ * rc.c : remote control stdin/stdout plugin for vlc ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: rc.c,v 1.16 2002/12/07 23:50:30 massiot Exp $ + * $Id: rc.c,v 1.17 2002/12/14 19:34:06 gbazin Exp $ * * Authors: Peter Surda * @@ -735,9 +735,8 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd, { /* Retrieve all registered ***. */ vlc_value_t val; - int i, i_vals; - vlc_value_t * p_vals; - const char * psz_value; + int i; + char * psz_value; if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 ) { @@ -755,14 +754,12 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd, } printf( "+----[ %s ]\n", psz_name ); - i_vals = ((vlc_value_t *)val.p_address)[0].i_int; - p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */ - for ( i = 0; i < i_vals; i++ ) + for ( i = 0; i < val.p_list->i_count; i++ ) { - if ( !strcmp( psz_value, p_vals[i].psz_string ) ) - printf( "| %s *\n", p_vals[i].psz_string ); + if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) ) + printf( "| %s *\n", val.p_list->p_values[i].psz_string ); else - printf( "| %s\n", p_vals[i].psz_string ); + printf( "| %s\n", val.p_list->p_values[i].psz_string ); } var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST, &val ); diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m index 1c0df640c9..5b2a35529a 100644 --- a/modules/gui/macosx/intf.m +++ b/modules/gui/macosx/intf.m @@ -2,7 +2,7 @@ * intf.m: MacOS X interface plugin ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: intf.m,v 1.9 2002/12/08 23:38:02 massiot Exp $ + * $Id: intf.m,v 1.10 2002/12/14 19:34:06 gbazin Exp $ * * Authors: Jon Lech Johansen * Christophe Massiot @@ -839,8 +839,6 @@ static void Run( intf_thread_t *p_intf ) int i, i_nb_items; NSMenu * o_menu = [o_mi submenu]; vlc_value_t val; - int i_vals; - vlc_value_t * p_vals; char * psz_value; /* remove previous items */ @@ -863,18 +861,15 @@ static void Run( intf_thread_t *p_intf ) return; } - i_vals = ((vlc_value_t *)val.p_address)[0].i_int; - p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */ - /* make (un)sensitive */ - [o_mi setEnabled: (i_vals > 0)]; + [o_mi setEnabled: (val.p_list->i_count > 0)]; - for ( i = 0; i < i_vals; i++ ) + for ( i = 0; i < val.p_list->i_count; i++ ) { NSMenuItem * o_lmi; NSString * o_title; - o_title = [NSString stringWithCString: p_vals[i].psz_string]; + o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string]; o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""]; /* FIXME: this isn't 64-bit clean ! */ @@ -883,7 +878,7 @@ static void Run( intf_thread_t *p_intf ) [NSValue valueWithPointer: p_object]]; [o_lmi setTarget: o_controls]; - if ( !strcmp( psz_value, p_vals[i].psz_string ) ) + if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) ) [o_lmi setState: NSOnState]; } diff --git a/modules/misc/testsuite/test4.c b/modules/misc/testsuite/test4.c index e30a439f41..8063d16d2b 100644 --- a/modules/misc/testsuite/test4.c +++ b/modules/misc/testsuite/test4.c @@ -2,7 +2,7 @@ * test4.c : Miscellaneous stress tests module for vlc ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: test4.c,v 1.5 2002/12/07 15:25:26 gbazin Exp $ + * $Id: test4.c,v 1.6 2002/12/14 19:34:06 gbazin Exp $ * * Authors: Samuel Hocevar * @@ -82,8 +82,7 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { vlc_value_t val; - int i, i_vals; - vlc_value_t *p_vals; + int i; var_Create( p_this, "honk", VLC_VAR_STRING | VLC_VAR_HASCHOICE ); @@ -113,11 +112,9 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd, var_Get( p_this, "honk", &val ); printf( "value: %s\n", val.psz_string ); var_Change( p_this, "honk", VLC_VAR_GETLIST, &val ); - i_vals = ((vlc_value_t*)val.p_address)[0].i_int; - p_vals = &((vlc_value_t*)val.p_address)[1]; - for( i = 0 ; i < i_vals ; i++ ) + for( i = 0 ; i < val.p_list->i_count ; i++ ) { - printf( "value %i: %s\n", i, p_vals[i].psz_string ); + printf( "value %i: %s\n", i, val.p_list->p_values[i].psz_string ); } var_Change( p_this, "honk", VLC_VAR_FREELIST, &val ); @@ -307,6 +304,7 @@ static int Stress( vlc_object_t *p_this, char const *psz_cmd, { int id = (int) (MAXOBJ * i_level * 1.0 * rand() / (RAND_MAX)); vlc_object_get( p_this, pp_objects[id]->i_object_id ); + vlc_object_release( p_this ); } printf( " - destroying the objects (LIFO)\n" ); diff --git a/src/libvlc.c b/src/libvlc.c index 3642b79812..f4c34f2ecf 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -2,7 +2,7 @@ * libvlc.c: main libvlc source ***************************************************************************** * Copyright (C) 1998-2002 VideoLAN - * $Id: libvlc.c,v 1.51 2002/12/13 01:56:30 gbazin Exp $ + * $Id: libvlc.c,v 1.52 2002/12/14 19:34:06 gbazin Exp $ * * Authors: Vincent Seguin * Samuel Hocevar @@ -255,6 +255,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) if( p_help_module == NULL ) { //module_EndBank( p_vlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EGENERIC; } p_help_module->psz_object_name = "help"; @@ -268,6 +269,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) config_Free( p_help_module ); vlc_object_destroy( p_help_module ); //module_EndBank( p_vlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EGENERIC; } @@ -298,6 +300,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) config_Free( p_help_module ); vlc_object_destroy( p_help_module ); //module_EndBank( p_vlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EEXIT; } @@ -345,6 +348,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) if( b_exit ) { //module_EndBank( p_vlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EEXIT; } @@ -367,6 +371,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) getchar(); #endif //module_EndBank( p_vlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EGENERIC; } @@ -462,6 +467,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) config_PutInt( p_vlc, "network-channel", VLC_FALSE ); } + msg_Err( p_vlc, "SIZEOF: %i", sizeof(vlc_list_t) ); + msg_Err( p_vlc, "SIZEOF: %i", sizeof(vlc_value_t) ); + /* * Initialize playlist and get commandline files */ @@ -474,6 +482,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) module_Unneed( p_vlc, p_vlc->p_memcpy_module ); } //module_EndBank( p_vlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EGENERIC; } @@ -482,6 +491,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) */ GetFilenames( p_vlc, i_argc, ppsz_argv ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -528,6 +538,7 @@ int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block ) if( p_intf == NULL ) { msg_Err( p_vlc, "interface initialization failed" ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_EGENERIC; } @@ -538,9 +549,11 @@ int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block ) { vlc_object_detach( p_intf ); intf_Destroy( p_intf ); + if( i_object ) vlc_object_release( p_vlc ); return i_err; } + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -604,6 +617,7 @@ int VLC_Destroy( int i_object ) /* Stop thread system: last one out please shut the door! */ vlc_threads_end( &libvlc ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -626,6 +640,7 @@ int VLC_Die( int i_object ) p_vlc->b_die = VLC_TRUE; + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -657,6 +672,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos ) if( p_playlist == NULL ) { + if( i_object ) vlc_object_release( p_vlc ); return VLC_EGENERIC; } @@ -667,6 +683,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos ) vlc_object_release( p_playlist ); + if( i_object ) vlc_object_release( p_vlc ); return i_err; } @@ -678,6 +695,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos ) int VLC_Set( int i_object, char const *psz_var, vlc_value_t value ) { vlc_t *p_vlc; + int i_ret; p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc; @@ -712,11 +730,15 @@ int VLC_Set( int i_object, char const *psz_var, vlc_value_t value ) config_PutPsz( p_vlc, psz_newvar, value.psz_string ); break; } + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } } - return var_Set( p_vlc, psz_var, value ); + i_ret = var_Set( p_vlc, psz_var, value ); + + if( i_object ) vlc_object_release( p_vlc ); + return i_ret; } /***************************************************************************** @@ -727,6 +749,7 @@ int VLC_Set( int i_object, char const *psz_var, vlc_value_t value ) int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value ) { vlc_t *p_vlc; + int i_ret; p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc; @@ -735,7 +758,10 @@ int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value ) return VLC_ENOOBJ; } - return var_Get( p_vlc, psz_var, p_value ); + i_ret = var_Get( p_vlc, psz_var, p_value ); + + if( i_object ) vlc_object_release( p_vlc ); + return i_ret; } /* FIXME: temporary hacks */ @@ -769,6 +795,7 @@ int VLC_Play( int i_object ) if( !p_playlist ) { + if( i_object ) vlc_object_release( p_vlc ); return VLC_ENOOBJ; } @@ -785,6 +812,7 @@ int VLC_Play( int i_object ) vlc_object_release( p_playlist ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -853,6 +881,7 @@ int VLC_Stop( int i_object ) aout_Delete( p_aout ); } + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -875,12 +904,14 @@ int VLC_Pause( int i_object ) if( !p_input ) { + if( i_object ) vlc_object_release( p_vlc ); return VLC_ENOOBJ; } input_SetStatus( p_input, INPUT_STATUS_PAUSE ); vlc_object_release( p_input ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } @@ -903,12 +934,14 @@ int VLC_FullScreen( int i_object ) if( !p_vout ) { + if( i_object ) vlc_object_release( p_vlc ); return VLC_ENOOBJ; } p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; vlc_object_release( p_vout ); + if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; } diff --git a/src/misc/objects.c b/src/misc/objects.c index f6ae50bde1..4aa379213a 100644 --- a/src/misc/objects.c +++ b/src/misc/objects.c @@ -2,7 +2,7 @@ * objects.c: vlc_object_t handling ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: objects.c,v 1.32 2002/12/13 01:56:30 gbazin Exp $ + * $Id: objects.c,v 1.33 2002/12/14 19:34:06 gbazin Exp $ * * Authors: Samuel Hocevar * @@ -60,6 +60,8 @@ static void SetAttachment ( vlc_object_t *, vlc_bool_t ); static vlc_list_t NewList ( int ); static void ListReplace ( vlc_list_t *, vlc_object_t *, int ); static void ListAppend ( vlc_list_t *, vlc_object_t * ); +static int CountChildren ( vlc_object_t *, int ); +static void ListChildren ( vlc_list_t *, vlc_object_t *, int ); /***************************************************************************** * Local structure lock @@ -351,6 +353,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id ) if( pp_objects[i_middle+1]->i_object_id == i_id ) { vlc_mutex_unlock( &structure_lock ); + pp_objects[i_middle+1]->i_refcount++; return pp_objects[i_middle+1]; } break; @@ -359,6 +362,7 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id ) else { vlc_mutex_unlock( &structure_lock ); + pp_objects[i_middle]->i_refcount++; return pp_objects[i_middle]; } @@ -490,15 +494,15 @@ void __vlc_object_detach( vlc_object_t *p_this ) vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode ) { vlc_list_t list; + vlc_object_t **pp_current, **pp_end; + int i_count = 0, i_index = 0; vlc_mutex_lock( &structure_lock ); /* Look for the objects */ - if( (i_mode & 0x000f) == FIND_ANYWHERE ) + switch( i_mode & 0x000f ) { - vlc_object_t **pp_current, **pp_end; - int i_count = 0, i_index = 0; - + case FIND_ANYWHERE: pp_current = p_this->p_libvlc->pp_objects; pp_end = pp_current + p_this->p_libvlc->i_objects; @@ -523,11 +527,28 @@ vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode ) if( i_index < i_count ) i_index++; } } - } - else - { + break; + + case FIND_CHILD: + i_count = CountChildren( p_this, i_type ); + list = NewList( i_count ); + + /* Check allocation was successful */ + if( list.i_count != i_count ) + { + msg_Err( p_this, "list allocation failed!" ); + list.i_count = 0; + break; + } + + list.i_count = 0; + ListChildren( &list, p_this, i_type ); + break; + + default: msg_Err( p_this, "unimplemented!" ); list = NewList( 0 ); + break; } vlc_mutex_unlock( &structure_lock ); @@ -570,6 +591,11 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd, DumpStructure( p_object, 0, psz_foo ); vlc_mutex_unlock( &structure_lock ); + + if( *newval.psz_string ) + { + vlc_object_release( p_this ); + } } else if( *psz_cmd == 'l' ) { @@ -915,3 +941,47 @@ static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object ) return; } + +static int CountChildren( vlc_object_t *p_this, int i_type ) +{ + vlc_object_t *p_tmp; + int i, i_count = 0; + + for( i = 0; i < p_this->i_children; i++ ) + { + p_tmp = p_this->pp_children[i]; + + if( p_tmp->i_object_type == i_type ) + { + i_count++; + } + + if( p_tmp->i_children ) + { + i_count += CountChildren( p_tmp, i_type ); + } + } + + return i_count; +} + +static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type ) +{ + vlc_object_t *p_tmp; + int i; + + for( i = 0; i < p_this->i_children; i++ ) + { + p_tmp = p_this->pp_children[i]; + + if( p_tmp->i_object_type == i_type ) + { + ListReplace( p_list, p_tmp, p_list->i_count++ ); + } + + if( p_tmp->i_children ) + { + ListChildren( p_list, p_tmp, i_type ); + } + } +} diff --git a/src/misc/variables.c b/src/misc/variables.c index c789e148ee..9ba88b853a 100644 --- a/src/misc/variables.c +++ b/src/misc/variables.c @@ -2,7 +2,7 @@ * variables.c: routines for object variables handling ***************************************************************************** * Copyright (C) 2002 VideoLAN - * $Id: variables.c,v 1.17 2002/12/10 18:22:01 gbazin Exp $ + * $Id: variables.c,v 1.18 2002/12/14 19:34:06 gbazin Exp $ * * Authors: Samuel Hocevar * @@ -132,8 +132,8 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type ) p_var->i_usage = 1; p_var->i_default = -1; - p_var->i_choices = 0; - p_var->pp_choices = NULL; + p_var->choices.i_count = 0; + p_var->choices.p_values = NULL; p_var->b_incallback = VLC_FALSE; p_var->i_entries = 0; @@ -220,13 +220,13 @@ int __var_Destroy( vlc_object_t *p_this, const char *psz_name ) p_var->pf_free( &p_var->val ); /* Free choice list if needed */ - if( p_var->pp_choices ) + if( p_var->choices.i_count ) { - for( i = 0 ; i < p_var->i_choices ; i++ ) + for( i = 0 ; i < p_var->choices.i_count ; i++ ) { - p_var->pf_free( &p_var->pp_choices[i] ); + p_var->pf_free( &p_var->choices.p_values[i] ); } - free( p_var->pp_choices ); + free( p_var->choices.p_values ); } /* Free callbacks if needed */ @@ -309,12 +309,11 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, p_var->pf_dup( &p_var->step ); CheckValue( p_var, &p_var->val ); break; - case VLC_VAR_ADDCHOICE: /* FIXME: the list is sorted, dude. Use something cleverer. */ - for( i = p_var->i_choices ; i-- ; ) + for( i = p_var->choices.i_count ; i-- ; ) { - if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) < 0 ) + if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) < 0 ) { break; } @@ -328,22 +327,23 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, p_var->i_default++; } - INSERT_ELEM( p_var->pp_choices, p_var->i_choices, i, *p_val ); - p_var->pf_dup( &p_var->pp_choices[i] ); + INSERT_ELEM( p_var->choices.p_values, p_var->choices.i_count, + i, *p_val ); + p_var->pf_dup( &p_var->choices.p_values[i] ); CheckValue( p_var, &p_var->val ); break; case VLC_VAR_DELCHOICE: /* FIXME: the list is sorted, dude. Use something cleverer. */ - for( i = 0 ; i < p_var->i_choices ; i++ ) + for( i = 0 ; i < p_var->choices.i_count ; i++ ) { - if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) == 0 ) + if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 ) { break; } } - if( i == p_var->i_choices ) + if( i == p_var->choices.i_count ) { /* Not found */ vlc_mutex_unlock( &p_this->var_lock ); @@ -359,22 +359,22 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, p_var->i_default = -1; } - p_var->pf_free( &p_var->pp_choices[i] ); - REMOVE_ELEM( p_var->pp_choices, p_var->i_choices, i ); + p_var->pf_free( &p_var->choices.p_values[i] ); + REMOVE_ELEM( p_var->choices.p_values, p_var->choices.i_count, i ); CheckValue( p_var, &p_var->val ); break; case VLC_VAR_SETDEFAULT: /* FIXME: the list is sorted, dude. Use something cleverer. */ - for( i = 0 ; i < p_var->i_choices ; i++ ) + for( i = 0 ; i < p_var->choices.i_count ; i++ ) { - if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) == 0 ) + if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 ) { break; } } - if( i == p_var->i_choices ) + if( i == p_var->choices.i_count ) { /* Not found */ break; @@ -385,21 +385,23 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name, break; case VLC_VAR_GETLIST: - p_val->p_address = malloc( (1 + p_var->i_choices) - * sizeof(vlc_value_t) ); - ((vlc_value_t*)p_val->p_address)[0].i_int = p_var->i_choices; - for( i = 0 ; i < p_var->i_choices ; i++ ) + p_val->p_list = malloc( sizeof(vlc_list_t) ); + p_val->p_list->p_values = malloc( p_var->choices.i_count + * sizeof(vlc_value_t) ); + p_val->p_list->i_count = p_var->choices.i_count; + for( i = 0 ; i < p_var->choices.i_count ; i++ ) { - ((vlc_value_t*)p_val->p_address)[i+1] = p_var->pp_choices[i]; - p_var->pf_dup( &((vlc_value_t*)p_val->p_address)[i+1] ); + p_val->p_list->p_values[i] = p_var->choices.p_values[i]; + p_var->pf_dup( &p_val->p_list->p_values[i] ); } break; case VLC_VAR_FREELIST: - for( i = ((vlc_value_t*)p_val->p_address)[0].i_int ; i-- ; ) + for( i = p_val->p_list->i_count ; i-- ; ) { - p_var->pf_free( &((vlc_value_t*)p_val->p_address)[i+1] ); + p_var->pf_free( &p_val->p_list->p_values[i] ); } - free( p_val->p_address ); + free( p_val->p_list->p_values ); + free( p_val->p_list ); break; default: @@ -836,14 +838,14 @@ static int LookupInner( variable_t *p_vars, int i_count, uint32_t i_hash ) static void CheckValue ( variable_t *p_var, vlc_value_t *p_val ) { /* Check that our variable is in the list */ - if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->i_choices ) + if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->choices.i_count ) { int i; /* FIXME: the list is sorted, dude. Use something cleverer. */ - for( i = p_var->i_choices ; i-- ; ) + for( i = p_var->choices.i_count ; i-- ; ) { - if( p_var->pf_cmp( *p_val, p_var->pp_choices[i] ) == 0 ) + if( p_var->pf_cmp( *p_val, p_var->choices.p_values[i] ) == 0 ) { break; } @@ -854,8 +856,8 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val ) { /* Free the old variable, get the new one, dup it */ p_var->pf_free( p_val ); - *p_val = p_var->pp_choices[p_var->i_default >= 0 - ? p_var->i_default : 0 ]; + *p_val = p_var->choices.p_values[p_var->i_default >= 0 + ? p_var->i_default : 0 ]; p_var->pf_dup( p_val ); } } @@ -907,4 +909,3 @@ static void CheckValue ( variable_t *p_var, vlc_value_t *p_val ) break; } } -