Commit 42bc82f4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Revert "Modules: use a dynamic array for the shortcuts (this save 40K of...

Revert "Modules: use a dynamic array for the shortcuts (this save 40K of memory on a 64bit system)."

This makes the cache loader crash (depending on the input file).

This reverts commit 3c396458.

Conflicts:

	src/modules/modules.h
parent aa4b22e8
......@@ -1423,15 +1423,15 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search )
( b_strict ? strcmp( psz_search, p_parser->psz_object_name )
: !strstr( p_parser->psz_object_name, psz_search ) ) )
{
char *const *pp_shortcuts = p_parser->pp_shortcuts;
int i;
for( i = 0; i < p_parser->i_shortcuts; i++ )
char *const *pp_shortcut = p_parser->pp_shortcuts;
while( *pp_shortcut )
{
if( b_strict ? !strcmp( psz_search, pp_shortcuts[i] )
: !!strstr( pp_shortcuts[i], psz_search ) )
if( b_strict ? !strcmp( psz_search, *pp_shortcut )
: !!strstr( *pp_shortcut, psz_search ) )
break;
pp_shortcut ++;
}
if( i == p_parser->i_shortcuts )
if( !*pp_shortcut )
continue;
}
......@@ -1861,18 +1861,19 @@ static void ListModules( libvlc_int_t *p_this, bool b_verbose )
if( b_verbose )
{
char *const *pp_shortcuts = p_parser->pp_shortcuts;
for( int i = 0; i < p_parser->i_shortcuts; i++ )
char *const *pp_shortcut = p_parser->pp_shortcuts;
while( *pp_shortcut )
{
if( strcmp( pp_shortcuts[i], p_parser->psz_object_name ) )
if( strcmp( *pp_shortcut, p_parser->psz_object_name ) )
{
if( b_color )
utf8_fprintf( stdout, CYAN" s %s\n"GRAY,
pp_shortcuts[i] );
*pp_shortcut );
else
utf8_fprintf( stdout, " s %s\n",
pp_shortcuts[i] );
*pp_shortcut );
}
pp_shortcut++;
}
if( p_parser->psz_capability )
{
......
......@@ -253,13 +253,10 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
LOAD_STRING( pp_cache[i]->p_module->psz_shortname );
LOAD_STRING( pp_cache[i]->p_module->psz_longname );
LOAD_STRING( pp_cache[i]->p_module->psz_help );
LOAD_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
pp_cache[i]->p_module->pp_shortcuts =
malloc( sizeof( char ** ) * pp_cache[i]->p_module->i_shortcuts );
for( j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++ )
LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
{
LOAD_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
}
LOAD_STRING( pp_cache[i]->p_module->psz_capability );
LOAD_IMMEDIATE( pp_cache[i]->p_module->i_score );
LOAD_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
......@@ -284,12 +281,10 @@ void CacheLoad( vlc_object_t *p_this, module_bank_t *p_bank, const char *dir )
LOAD_STRING( p_module->psz_shortname );
LOAD_STRING( p_module->psz_longname );
LOAD_STRING( p_module->psz_help );
LOAD_IMMEDIATE( p_module->i_shortcuts );
p_module->pp_shortcuts = malloc( sizeof( char ** ) * p_module->i_shortcuts );
for( j = 0; j < p_module->i_shortcuts; j++ )
LOAD_STRING( p_module->pp_shortcuts[j] );
for( j = 0; j < MODULE_SHORTCUT_MAX; j++ )
{
LOAD_STRING( p_module->pp_shortcuts[j] ); // FIX
}
LOAD_STRING( p_module->psz_capability );
LOAD_IMMEDIATE( p_module->i_score );
LOAD_IMMEDIATE( p_module->b_unloadable );
......@@ -550,10 +545,10 @@ static int CacheSaveBank (FILE *file, module_cache_t *const *pp_cache,
SAVE_STRING( pp_cache[i]->p_module->psz_shortname );
SAVE_STRING( pp_cache[i]->p_module->psz_longname );
SAVE_STRING( pp_cache[i]->p_module->psz_help );
SAVE_IMMEDIATE( pp_cache[i]->p_module->i_shortcuts );
for (unsigned j = 0; j < pp_cache[i]->p_module->i_shortcuts; j++)
SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] );
for (unsigned j = 0; j < MODULE_SHORTCUT_MAX; j++)
{
SAVE_STRING( pp_cache[i]->p_module->pp_shortcuts[j] ); // FIX
}
SAVE_STRING( pp_cache[i]->p_module->psz_capability );
SAVE_IMMEDIATE( pp_cache[i]->p_module->i_score );
SAVE_IMMEDIATE( pp_cache[i]->p_module->b_unloadable );
......@@ -595,9 +590,8 @@ static int CacheSaveSubmodule( FILE *file, const module_t *p_module )
SAVE_STRING( p_module->psz_shortname );
SAVE_STRING( p_module->psz_longname );
SAVE_STRING( p_module->psz_help );
SAVE_IMMEDIATE( p_module->i_shortcuts );
for( unsigned j = 0; j < p_module->i_shortcuts; j++ )
SAVE_STRING( p_module->pp_shortcuts[j] );
for( unsigned j = 0; j < MODULE_SHORTCUT_MAX; j++ )
SAVE_STRING( p_module->pp_shortcuts[j] ); // FIXME
SAVE_STRING( p_module->psz_capability );
SAVE_IMMEDIATE( p_module->i_score );
......
......@@ -37,7 +37,6 @@ static void vlc_module_destruct (gc_object_t *obj)
{
module_t *module = vlc_priv (obj, module_t);
free (module->pp_shortcuts);
free (module->psz_object_name);
free (module);
}
......@@ -60,8 +59,8 @@ module_t *vlc_module_create (vlc_object_t *obj)
module->psz_shortname = NULL;
module->psz_longname = (char*)default_name;
module->psz_help = NULL;
module->pp_shortcuts = NULL;
module->i_shortcuts = 0;
for (unsigned i = 0; i < MODULE_SHORTCUT_MAX; i++)
module->pp_shortcuts[i] = NULL;
module->psz_capability = (char*)"";
module->i_score = 1;
module->b_unloadable = true;
......@@ -86,7 +85,6 @@ module_t *vlc_module_create (vlc_object_t *obj)
static void vlc_submodule_destruct (gc_object_t *obj)
{
module_t *module = vlc_priv (obj, module_t);
free (module->pp_shortcuts);
free (module->psz_object_name);
free (module);
}
......@@ -107,9 +105,9 @@ module_t *vlc_submodule_create (module_t *module)
module->submodule_count++;
/* Muahahaha! Heritage! Polymorphism! Ugliness!! */
submodule->pp_shortcuts = malloc( sizeof( char ** ) );
submodule->pp_shortcuts[0] = module->pp_shortcuts[0]; /* object name */
submodule->i_shortcuts = 1;
for (unsigned i = 1; i < MODULE_SHORTCUT_MAX; i++)
submodule->pp_shortcuts[i] = NULL;
submodule->psz_object_name = strdup( module->psz_object_name );
submodule->psz_shortname = module->psz_shortname;
......@@ -181,9 +179,12 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
case VLC_MODULE_SHORTCUT:
{
const char *psz_new = va_arg (ap, char*);
module->pp_shortcuts = realloc (module->pp_shortcuts, sizeof( char ** ) * (module->i_shortcuts + 1));
module->pp_shortcuts[module->i_shortcuts++] = psz_new;
unsigned i;
for (i = 0; module->pp_shortcuts[i] != NULL; i++);
if (i >= (MODULE_SHORTCUT_MAX - 1))
break;
module->pp_shortcuts[i] = va_arg (ap, char *);
break;
}
......@@ -212,10 +213,7 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
const char *value = va_arg (ap, const char *);
free( module->psz_object_name );
module->psz_object_name = strdup( value );
module->pp_shortcuts = malloc( sizeof( char ** ) );
module->pp_shortcuts[0] = (char*)value; /* dooh! */
module->i_shortcuts = 1;
if (module->psz_longname == default_name)
module->psz_longname = (char*)value; /* dooh! */
break;
......
......@@ -481,7 +481,7 @@ module_t * module_need( vlc_object_t *p_this, const char *psz_capability,
for( unsigned i_short = i_shortcuts; i_short > 0; i_short-- )
{
for( unsigned i = 0; i < p_module->i_shortcuts; i++ )
for( unsigned i = 0; p_module->pp_shortcuts[i]; i++ )
{
char *c;
if( ( c = strchr( name, '@' ) )
......@@ -691,7 +691,9 @@ module_t *module_find_by_shortcut (const char *psz_shortcut)
for (size_t i = 0; (module = list[i]) != NULL; i++)
{
for (size_t j = 0; j < module->i_shortcuts; j++)
for (size_t j = 0;
(module->pp_shortcuts[j] != NULL) && (j < MODULE_SHORTCUT_MAX);
j++)
{
if (!strcmp (module->pp_shortcuts[j], psz_shortcut))
{
......@@ -1052,9 +1054,12 @@ static module_t * AllocatePlugin( vlc_object_t * p_this, const char *psz_file )
*****************************************************************************/
static void DupModule( module_t *p_module )
{
char **pp_shortcuts = p_module->pp_shortcuts;
for( unsigned i = 0; i < p_module->i_shortcuts; i++ )
pp_shortcuts[i] = strdup( p_module->pp_shortcuts[i] );
char **pp_shortcut;
for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
{
*pp_shortcut = strdup( *pp_shortcut );
}
/* We strdup() these entries so that they are still valid when the
* module is unloaded. */
......@@ -1077,13 +1082,15 @@ static void DupModule( module_t *p_module )
*****************************************************************************/
static void UndupModule( module_t *p_module )
{
char **pp_shortcuts = p_module->pp_shortcuts;
char **pp_shortcut;
for (module_t *subm = p_module->submodule; subm; subm = subm->next)
UndupModule (subm);
for( unsigned i = 0; i < p_module->i_shortcuts; i++ )
free( pp_shortcuts[i] );
for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
{
free( *pp_shortcut );
}
free( p_module->psz_capability );
FREENULL( p_module->psz_shortname );
......
......@@ -100,10 +100,6 @@ struct module_t
module_t *submodule;
unsigned submodule_count;
/** Shortcuts to the module */
int i_shortcuts;
char **pp_shortcuts;
/*
* Variables set by the module to identify itself
*/
......@@ -111,6 +107,9 @@ struct module_t
char *psz_longname; /**< Module descriptive name */
char *psz_help; /**< Long help string for "special" modules */
/** Shortcuts to the module */
char *pp_shortcuts[ MODULE_SHORTCUT_MAX ];
char *psz_capability; /**< Capability */
int i_score; /**< Score for the capability */
......
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