Commit 92290c9d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Attempt to fix C++ compilation

parent 51ae5f27
......@@ -30,7 +30,6 @@
/* Configuration hint types */
#define CONFIG_HINT_END 0x0001 /* End of config */
#define CONFIG_HINT_CATEGORY 0x0002 /* Start of new category */
#define CONFIG_HINT_SUBCATEGORY 0x0003 /* Start of sub-category */
#define CONFIG_HINT_SUBCATEGORY_END 0x0004 /* End of sub-category */
......@@ -227,11 +226,11 @@ VLC_EXPORT( void, __config_ResetAll, ( vlc_object_t * ) );
VLC_EXPORT( module_config_t *, config_FindConfig,( vlc_object_t *, const char * ) );
VLC_EXPORT( module_t *, config_FindModule,( vlc_object_t *, const char * ) );
VLC_EXPORT( void, config_Duplicate, ( module_t *, const module_config_t * ) );
VLC_EXPORT( int, config_Duplicate, ( module_t *, const module_config_t *, size_t ) );
void config_Free ( module_t * );
VLC_EXPORT( void, config_SetCallbacks, ( module_config_t *, module_config_t * ) );
VLC_EXPORT( void, config_UnsetCallbacks, ( module_config_t * ) );
VLC_EXPORT( void, config_SetCallbacks, ( module_config_t *, module_config_t *, size_t ) );
VLC_EXPORT( void, config_UnsetCallbacks, ( module_config_t *, size_t ) );
#define config_GetType(a,b) __config_GetType(VLC_OBJECT(a),b)
#define config_GetInt(a,b) __config_GetInt(VLC_OBJECT(a),b)
......
......@@ -112,6 +112,7 @@ struct module_t
* Variables set by the module to store its config options
*/
module_config_t *p_config; /* Module configuration structure */
size_t confsize; /* Number of module_config_t items */
unsigned int i_config_items; /* number of configuration items */
unsigned int i_bool_items; /* number of bool config items */
......
......@@ -102,10 +102,9 @@ E_(vlc_entry) ( module_t *p_module );
EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL \
__VLC_SYMBOL(vlc_entry) ( module_t *p_module ) \
{ \
int i_shortcut = 1, i_config = -1; \
int i_shortcut = 1; \
size_t i_config = (size_t)(-1); \
module_config_t *p_config = NULL; \
static const module_config_t config_end = { \
.i_type = CONFIG_HINT_END }; \
STORE_SYMBOLS; \
p_module->b_submodule = VLC_FALSE; \
p_module->b_unloadable = VLC_TRUE; \
......@@ -127,27 +126,21 @@ E_(vlc_entry) ( module_t *p_module );
#define vlc_module_end( ) \
p_submodule->pp_shortcuts[ i_shortcut ] = NULL; \
} \
if( p_config ) \
if (config_Duplicate( p_module, p_config, ++i_config )) \
return VLC_ENOMEM; \
for( size_t i = 0; i < i_config; i++ ) \
{ \
int i; \
p_config[ ++i_config ] = config_end; \
config_Duplicate( p_module, p_config ); \
for( i = 0; i < i_config; i++ ) \
if( p_config[ i ].i_action ) \
{ \
if( p_config[ i ].i_action ) \
{ \
free( p_config[ i ].ppf_action ); \
free( p_config[ i ].ppsz_action_text ); \
} \
free( p_config[ i ].ppf_action ); \
free( p_config[ i ].ppsz_action_text ); \
} \
free( p_config ); \
} \
else config_Duplicate( p_module, &config_end ); \
free( p_config ); \
if( p_module->p_config == NULL ) \
{ \
return VLC_EGENERIC; \
} \
return VLC_SUCCESS && i_shortcut; \
(void)i_shortcut; \
return VLC_SUCCESS; \
} \
struct _u_n_u_s_e_d_ /* the ; gets added */
......
......@@ -9,7 +9,6 @@
# ifdef HAVE_SHARED_LIBVLC
# error You are not supposed to include this file!
# endif
/*
* This is the big VLC API structure for plugins :
* Changing its layout breaks plugin's binary compatibility,
......@@ -71,9 +70,9 @@ struct module_symbols_t
void (*__config_ResetAll_inner) (vlc_object_t *);
module_config_t * (*config_FindConfig_inner) (vlc_object_t *, const char *);
module_t * (*config_FindModule_inner) (vlc_object_t *, const char *);
void (*config_Duplicate_inner) (module_t *, const module_config_t *);
void (*config_SetCallbacks_inner) (module_config_t *, module_config_t *);
void (*config_UnsetCallbacks_inner) (module_config_t *);
int (*config_Duplicate_inner) (module_t *, const module_config_t *, size_t);
void (*config_SetCallbacks_inner) (module_config_t *, module_config_t *, size_t);
void (*config_UnsetCallbacks_inner) (module_config_t *, size_t);
int (*__intf_Eject_inner) (vlc_object_t *, const char *);
const iso639_lang_t * (*GetLang_1_inner) (const char *);
const iso639_lang_t * (*GetLang_2T_inner) (const char *);
......
......@@ -333,7 +333,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
}
p_help_module->psz_object_name = "help";
p_help_module->psz_longname = N_("Help options");
config_Duplicate( p_help_module, p_help_config );
config_Duplicate( p_help_module, p_help_config,
sizeof (p_help_config) / sizeof (p_help_config[0]) );
vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
/* End hack */
......@@ -1346,7 +1347,6 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
#endif
vlc_list_t *p_list;
module_t *p_parser;
module_config_t *p_item;
char psz_spaces_text[PADDING_SPACES+LINE_START+1];
char psz_spaces_longtext[LINE_START+3];
char psz_format[sizeof(FORMAT_STRING)];
......@@ -1371,8 +1371,9 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
for( i_index = 0; i_index < p_list->i_count; i_index++ )
{
vlc_bool_t b_help_module;
p_parser = (module_t *)p_list->p_values[i_index].p_object ;
module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
module_config_t *p_item,
*p_end = p_parser->p_config + p_parser->confsize;
if( psz_module_name && strcmp( psz_module_name,
p_parser->psz_object_name ) )
......@@ -1390,13 +1391,12 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
if( !b_advanced )
{
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
p_item < p_end;
p_item++ )
{
if( (p_item->i_type & CONFIG_ITEM) &&
!p_item->b_advanced ) break;
}
if( p_item->i_type == CONFIG_HINT_END ) continue;
}
/* Print name of module */
......@@ -1407,7 +1407,7 @@ static void Usage( libvlc_int_t *p_this, char const *psz_module_name )
/* Print module options */
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
p_item < p_end;
p_item++ )
{
char *psz_text, *psz_spaces = psz_spaces_text;
......
......@@ -2213,8 +2213,7 @@ static module_config_t p_help_config[] =
.i_type = CONFIG_ITEM_BOOL,
.psz_name = "version",
.psz_text = N_("print version information")
},
{ .i_type = CONFIG_HINT_END }
}
};
/*****************************************************************************
......
......@@ -424,8 +424,6 @@ void __config_PutFloat( vlc_object_t *p_this,
module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
{
vlc_list_t *p_list;
module_t *p_parser;
module_config_t *p_item;
int i_index;
if( !psz_name ) return NULL;
......@@ -434,13 +432,14 @@ module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name )
for( i_index = 0; i_index < p_list->i_count; i_index++ )
{
p_parser = (module_t *)p_list->p_values[i_index].p_object ;
module_config_t *p_item, *p_end;
module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object;
if( !p_parser->i_config_items )
continue;
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
p_item < p_end;
p_item++ )
{
if( p_item->i_type & CONFIG_HINT )
......@@ -494,19 +493,18 @@ module_t *config_FindModule( vlc_object_t *p_this, const char *psz_name )
* this module might be unloaded from memory at any time (remember HideModule).
* This is why we need to create an exact copy of the config data.
*****************************************************************************/
void config_Duplicate( module_t *p_module, const module_config_t *p_orig )
int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
size_t n )
{
int i, j, i_lines = 1;
const module_config_t *p_item;
int j;
const module_config_t *p_item, *p_end = p_orig + n;
/* Calculate the structure length */
p_module->i_config_items = 0;
p_module->i_bool_items = 0;
for( p_item = p_orig; p_item->i_type != CONFIG_HINT_END; p_item++ )
for( p_item = p_orig; p_item < p_end; p_item++ )
{
i_lines++;
if( p_item->i_type & CONFIG_ITEM )
{
p_module->i_config_items++;
......@@ -519,16 +517,16 @@ void config_Duplicate( module_t *p_module, const module_config_t *p_orig )
}
/* Allocate memory */
p_module->p_config = (module_config_t *)malloc( sizeof(module_config_t)
* i_lines );
p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
if( p_module->p_config == NULL )
{
msg_Err( p_module, "config error: can't duplicate p_config" );
return;
return VLC_ENOMEM;
}
p_module->confsize = n;
/* Do the duplication job */
for( i = 0; i < i_lines ; i++ )
for( size_t i = 0; i < n ; i++ )
{
p_module->p_config[i] = p_orig[i];
......@@ -630,16 +628,12 @@ void config_Duplicate( module_t *p_module, const module_config_t *p_orig )
*****************************************************************************/
void config_Free( module_t *p_module )
{
module_config_t *p_item = p_module->p_config;
int i;
if( p_item == NULL )
for (size_t j = 0; j < p_module->confsize; j++)
{
return;
}
module_config_t *p_item = p_module->p_config + j;
for( ; p_item->i_type != CONFIG_HINT_END ; p_item++ )
{
if( p_item->psz_type )
free( p_item->psz_type );
......@@ -688,8 +682,11 @@ void config_Free( module_t *p_module )
}
}
free( p_module->p_config );
p_module->p_config = NULL;
if (p_module->p_config != NULL)
{
free (p_module->p_config);
p_module->p_config = NULL;
}
}
/*****************************************************************************
......@@ -699,9 +696,10 @@ void config_Free( module_t *p_module )
* this module might be unloaded from memory at any time (remember HideModule).
* This is why we need to duplicate callbacks each time we reload the module.
*****************************************************************************/
void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig )
void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig,
size_t n )
{
while( p_new->i_type != CONFIG_HINT_END )
for (size_t i = 0; i < n; i++)
{
p_new->pf_callback = p_orig->pf_callback;
p_new++;
......@@ -714,9 +712,9 @@ void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig )
*****************************************************************************
* We simply undo what we did in config_SetCallbacks.
*****************************************************************************/
void config_UnsetCallbacks( module_config_t *p_new )
void config_UnsetCallbacks( module_config_t *p_new, size_t n )
{
while( p_new->i_type != CONFIG_HINT_END )
for (size_t i = 0; i < n; i++)
{
p_new->pf_callback = NULL;
p_new++;
......@@ -728,7 +726,7 @@ void config_UnsetCallbacks( module_config_t *p_new )
*****************************************************************************/
void __config_ResetAll( vlc_object_t *p_this )
{
int i_index, i;
int i_index;
vlc_list_t *p_list;
module_t *p_module;
......@@ -742,7 +740,7 @@ void __config_ResetAll( vlc_object_t *p_this )
p_module = (module_t *)p_list->p_values[i_index].p_object ;
if( p_module->b_submodule ) continue;
for( i = 0; p_module->p_config[i].i_type != CONFIG_HINT_END; i++ )
for (size_t i = 0; i < p_module->confsize; i++ )
{
if (IsConfigIntegerType (p_module->p_config[i].i_type))
p_module->p_config[i].value.i = p_module->p_config[i].orig.i;
......@@ -868,7 +866,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
while( fgets( line, 1024, file ) )
{
const char *psz_option_name, *psz_option_value;
module_config_t *p_item;
module_config_t *p_item, *p_end;
if( line[0] == '[' ) break; /* end of section */
......@@ -895,8 +893,8 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
}
/* try to match this option with one of the module's options */
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
p_item < p_end;
p_item++ )
{
if( p_item->i_type & CONFIG_HINT )
......@@ -1018,7 +1016,6 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
{
module_t *p_parser;
vlc_list_t *p_list;
module_config_t *p_item;
FILE *file;
char p_line[1024], *p_index2;
int i_sizebuf = 0;
......@@ -1175,6 +1172,7 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
/* Look for the selected module, if NULL then save everything */
for( i_index = 0; i_index < p_list->i_count; i_index++ )
{
module_config_t *p_item, *p_end;
p_parser = (module_t *)p_list->p_values[i_index].p_object ;
if( psz_module_name && strcmp( psz_module_name,
......@@ -1194,8 +1192,8 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
else
fprintf( file, "\n\n" );
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
p_item < p_end;
p_item++ )
{
char *psz_key;
......@@ -1309,8 +1307,6 @@ static int SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name,
int config_AutoSaveConfigFile( vlc_object_t *p_this )
{
vlc_list_t *p_list;
module_t *p_parser;
module_config_t *p_item;
int i_index, i_count;
/* Check if there's anything to save */
......@@ -1319,17 +1315,18 @@ int config_AutoSaveConfigFile( vlc_object_t *p_this )
i_count = p_list->i_count;
for( i_index = 0; i_index < i_count; i_index++ )
{
p_parser = (module_t *)p_list->p_values[i_index].p_object ;
module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ;
module_config_t *p_item, *p_end;
if( !p_parser->i_config_items ) continue;
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
p_item < p_end;
p_item++ )
{
if( p_item->b_autosave && p_item->b_dirty ) break;
}
if( p_item->i_type != CONFIG_HINT_END ) break;
break;
}
vlc_list_release( p_list );
vlc_mutex_unlock( &p_this->p_libvlc->config_lock );
......@@ -1358,7 +1355,6 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0;
module_t *p_parser;
vlc_list_t *p_list;
module_config_t *p_item;
struct option *p_longopts;
int i_modules_index;
......@@ -1456,13 +1452,14 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[],
for( i_modules_index = 0; i_modules_index < p_list->i_count;
i_modules_index++ )
{
module_config_t *p_item, *p_end;
p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ;
if( !p_parser->i_config_items )
continue;
for( p_item = p_parser->p_config;
p_item->i_type != CONFIG_HINT_END;
for( p_item = p_parser->p_config, p_end = p_item + p_parser->confsize;
p_item < p_end;
p_item++ )
{
/* Ignore hints */
......
......@@ -1014,7 +1014,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
}
else
{
module_config_t *p_item;
module_config_t *p_item, *p_end;
p_module = p_cache_entry->p_module;
p_module->b_loaded = VLC_FALSE;
......@@ -1022,8 +1022,8 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
/* For now we force loading if the module's config contains
* callbacks or actions.
* Could be optimized by adding an API call.*/
for( p_item = p_module->p_config;
p_item->i_type != CONFIG_HINT_END; p_item++ )
for( p_item = p_module->p_config, p_end = p_item + p_module->confsize;
p_item < p_end; p_item++ )
{
if( p_item->pf_callback || p_item->i_action )
p_module = AllocatePlugin( p_this, psz_file );
......@@ -1809,12 +1809,15 @@ int CacheLoadConfig( module_t *p_module, FILE *file )
LOAD_IMMEDIATE( i_lines );
/* Allocate memory */
p_module->p_config =
(module_config_t *)malloc( sizeof(module_config_t) * (i_lines + 1));
if( p_module->p_config == NULL )
if (i_lines)
{
msg_Err( p_module, "config error: can't duplicate p_config" );
return VLC_ENOMEM;
p_module->p_config =
(module_config_t *)calloc( i_lines, sizeof(module_config_t) );
if( p_module->p_config == NULL )
{
msg_Err( p_module, "config error: can't duplicate p_config" );
return VLC_ENOMEM;
}
}
/* Do the duplication job */
......@@ -1901,8 +1904,6 @@ int CacheLoadConfig( module_t *p_module, FILE *file )
LOAD_IMMEDIATE( p_module->p_config[i].pf_callback );
}
p_module->p_config[i].i_type = CONFIG_HINT_END;
return VLC_SUCCESS;
error:
......@@ -2078,13 +2079,14 @@ static void CacheSave( vlc_object_t *p_this )
void CacheSaveConfig( module_t *p_module, FILE *file )
{
int i, j, i_lines = 0;
module_config_t *p_item;
module_config_t *p_item, *p_end;
uint16_t i_size;
SAVE_IMMEDIATE( p_module->i_config_items );
SAVE_IMMEDIATE( p_module->i_bool_items );
for( p_item = p_module->p_config; p_item->i_type != CONFIG_HINT_END;
for( p_item = p_module->p_config, p_end = p_item + p_module->confsize;
p_item < p_end;
p_item++ ) i_lines++;
SAVE_IMMEDIATE( i_lines );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment