Commit 21e31e34 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Copy strings from plugin descriptor, remove (D|Und)upModules()

parent 6e70470e
...@@ -34,6 +34,11 @@ ...@@ -34,6 +34,11 @@
#include "config/configuration.h" #include "config/configuration.h"
#include "libvlc.h" #include "libvlc.h"
static char *strdup_null (const char *str)
{
return (str != NULL) ? strdup (str) : NULL;
}
module_t *vlc_module_create (void) module_t *vlc_module_create (void)
{ {
module_t *module = malloc (sizeof (*module)); module_t *module = malloc (sizeof (*module));
...@@ -69,7 +74,13 @@ module_t *vlc_module_create (void) ...@@ -69,7 +74,13 @@ module_t *vlc_module_create (void)
void vlc_module_destroy (module_t *module) void vlc_module_destroy (module_t *module)
{ {
for (unsigned i = 0; i < module->i_shortcuts; i++)
free (module->pp_shortcuts[i]);
free (module->pp_shortcuts); free (module->pp_shortcuts);
free (module->psz_capability);
free (module->psz_help);
free (module->psz_longname);
free (module->psz_shortname);
free (module); free (module);
} }
...@@ -89,14 +100,13 @@ module_t *vlc_submodule_create (module_t *module) ...@@ -89,14 +100,13 @@ module_t *vlc_submodule_create (module_t *module)
submodule->submodule = NULL; submodule->submodule = NULL;
submodule->submodule_count = 0; submodule->submodule_count = 0;
submodule->pp_shortcuts = xmalloc (sizeof (char **)); submodule->pp_shortcuts = NULL;
submodule->pp_shortcuts[0] = module->pp_shortcuts[0]; /* object name */ submodule->i_shortcuts = 0;
submodule->i_shortcuts = 1;
submodule->psz_shortname = module->psz_shortname; submodule->psz_shortname = NULL;
submodule->psz_longname = module->psz_longname; submodule->psz_longname = NULL;
submodule->psz_help = NULL; submodule->psz_help = NULL;
submodule->psz_capability = module->psz_capability; submodule->psz_capability = NULL;
submodule->i_score = module->i_score; submodule->i_score = module->i_score;
submodule->b_builtin = false; submodule->b_builtin = false;
submodule->b_loaded = false; submodule->b_loaded = false;
...@@ -158,12 +168,26 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -158,12 +168,26 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
case VLC_SUBMODULE_CREATE: case VLC_SUBMODULE_CREATE:
{ {
module_t **pp = va_arg (ap, module_t **); module_t **pp = va_arg (ap, module_t **);
*pp = vlc_submodule_create (module); module_t *submodule = vlc_submodule_create (module);
if (*pp == NULL)
if (unlikely(submodule == NULL))
{
ret = -1; ret = -1;
break; break;
} }
/* Inheritance. Ugly!! */
submodule->pp_shortcuts = xmalloc (sizeof (char **));
submodule->pp_shortcuts[0] = strdup_null (module->pp_shortcuts[0]);
submodule->i_shortcuts = 1; /* object name */
submodule->psz_shortname = strdup_null (module->psz_shortname);
submodule->psz_longname = strdup_null (module->psz_longname);
submodule->psz_capability = strdup_null (module->psz_capability);
*pp = submodule;
break;
}
case VLC_CONFIG_CREATE: case VLC_CONFIG_CREATE:
{ {
int type = va_arg (ap, int); int type = va_arg (ap, int);
...@@ -191,12 +215,15 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -191,12 +215,15 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
} }
module->pp_shortcuts = pp; module->pp_shortcuts = pp;
module->i_shortcuts = index + i_shortcuts; module->i_shortcuts = index + i_shortcuts;
memcpy (pp + index, tab, sizeof (pp[0]) * i_shortcuts); pp += index;
for (unsigned i = 0; i < i_shortcuts; i++)
pp[i] = strdup (tab[i]);
break; break;
} }
case VLC_MODULE_CAPABILITY: case VLC_MODULE_CAPABILITY:
module->psz_capability = va_arg (ap, char *); free (module->psz_capability);
module->psz_capability = strdup (va_arg (ap, char *));
break; break;
case VLC_MODULE_SCORE: case VLC_MODULE_SCORE:
...@@ -222,30 +249,36 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -222,30 +249,36 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
assert (module->i_shortcuts == 0); assert (module->i_shortcuts == 0);
module->pp_shortcuts = malloc( sizeof( char ** ) ); module->pp_shortcuts = malloc( sizeof( char ** ) );
module->pp_shortcuts[0] = (char*)value; /* dooh! */ module->pp_shortcuts[0] = strdup (value);
module->i_shortcuts = 1; module->i_shortcuts = 1;
if (module->psz_longname == NULL) assert (module->psz_longname == NULL);
module->psz_longname = (char*)value; /* dooh! */ module->psz_longname = strdup (value);
break; break;
} }
case VLC_MODULE_SHORTNAME: case VLC_MODULE_SHORTNAME:
module->psz_shortname = va_arg (ap, char *); assert (module->psz_shortname == NULL || module->parent != NULL);
free (module->psz_shortname);
module->psz_shortname = strdup (va_arg (ap, char *));
break; break;
case VLC_MODULE_DESCRIPTION: case VLC_MODULE_DESCRIPTION:
module->psz_longname = va_arg (ap, char *); // TODO: do not set this in VLC_MODULE_NAME
free (module->psz_longname);
module->psz_longname = strdup (va_arg (ap, char *));
break; break;
case VLC_MODULE_HELP: case VLC_MODULE_HELP:
assert (module->parent == NULL); assert (module->parent == NULL);
assert (module->psz_help == NULL); assert (module->psz_help == NULL);
module->psz_help = va_arg (ap, char *); module->psz_help = strdup (va_arg (ap, char *));
break; break;
case VLC_MODULE_TEXTDOMAIN: case VLC_MODULE_TEXTDOMAIN:
module->domain = va_arg (ap, char *); assert (module->parent == NULL);
assert (module->domain == NULL);
module->domain = strdup (va_arg (ap, char *));
break; break;
case VLC_CONFIG_NAME: case VLC_CONFIG_NAME:
......
...@@ -84,10 +84,6 @@ static module_t * AllocatePlugin( vlc_object_t *, const char *, bool ); ...@@ -84,10 +84,6 @@ static module_t * AllocatePlugin( vlc_object_t *, const char *, bool );
#endif #endif
static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) ); static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
static void DeleteModule (module_t **, module_t *); static void DeleteModule (module_t **, module_t *);
#ifdef HAVE_DYNAMIC_PLUGINS
static void DupModule ( module_t * );
static void UndupModule ( module_t * );
#endif
#undef module_InitBank #undef module_InitBank
/** /**
...@@ -1017,7 +1013,6 @@ static module_t *AllocatePlugin( vlc_object_t * p_this, const char *psz_file, ...@@ -1017,7 +1013,6 @@ static module_t *AllocatePlugin( vlc_object_t * p_this, const char *psz_file,
goto error; goto error;
} }
DupModule( p_module );
assert( !p_module->b_builtin ); assert( !p_module->b_builtin );
return p_module; return p_module;
error: error:
...@@ -1026,56 +1021,6 @@ error: ...@@ -1026,56 +1021,6 @@ error:
module_Unload( handle ); module_Unload( handle );
return NULL; return NULL;
} }
/*****************************************************************************
* DupModule: make a plugin module standalone.
*****************************************************************************
* This function duplicates all strings in the module, so that the dynamic
* object can be unloaded. It acts recursively on submodules.
*****************************************************************************/
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] );
/* We strdup() these entries so that they are still valid when the
* module is unloaded. */
p_module->psz_capability =
p_module->psz_capability ? strdup( p_module->psz_capability ) : NULL;
p_module->psz_shortname = p_module->psz_shortname ?
strdup( p_module->psz_shortname ) : NULL;
p_module->psz_longname = strdup( p_module->psz_longname );
p_module->psz_help = p_module->psz_help ? strdup( p_module->psz_help )
: NULL;
p_module->domain = p_module->domain ? strdup( p_module->domain ) : NULL;
for (module_t *subm = p_module->submodule; subm; subm = subm->next)
DupModule (subm);
}
/*****************************************************************************
* UndupModule: free a duplicated module.
*****************************************************************************
* This function frees the allocations done in DupModule().
*****************************************************************************/
static void UndupModule( module_t *p_module )
{
char **pp_shortcuts = p_module->pp_shortcuts;
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] );
free( p_module->psz_capability );
FREENULL( p_module->psz_shortname );
free( p_module->psz_longname );
FREENULL( p_module->psz_help );
free( p_module->domain );
}
#endif /* HAVE_DYNAMIC_PLUGINS */ #endif /* HAVE_DYNAMIC_PLUGINS */
/***************************************************************************** /*****************************************************************************
...@@ -1140,7 +1085,6 @@ static void DeleteModule (module_t **head, module_t *p_module) ...@@ -1140,7 +1085,6 @@ static void DeleteModule (module_t **head, module_t *p_module)
{ {
module_Unload( p_module->handle ); module_Unload( p_module->handle );
} }
UndupModule( p_module );
free( p_module->psz_filename ); free( p_module->psz_filename );
} }
#endif #endif
......
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