[vlc-commits] [Git][videolan/vlc][master] 7 commits: config: remove C++ guards

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Oct 30 07:28:16 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
4dea4a3b by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: remove C++ guards

Private core headers don't need this.

- - - - -
b8e7e225 by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: introduce private struct vlc_param type

This paves the way to split private and public properties from
module_config_t.

- - - - -
489ab089 by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: privatise short name

Note that this now uses `unsigned char` rather than `char`, consistent
with the expectation for the `%c` format string specifier. This also
avoids using a signed value to index an array.

- - - - -
0fad2161 by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: privatise the internal flag

- - - - -
c83869fb by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: privatise the safe flag

- - - - -
eac961bf by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: privatise the obsolete flag

- - - - -
4bb18364 by Rémi Denis-Courmont at 2021-10-30T07:11:37+00:00
config: privatise the owner field and make it type-safe

- - - - -


11 changed files:

- include/vlc_configuration.h
- src/config/chain.c
- src/config/cmdline.c
- src/config/configuration.h
- src/config/core.c
- src/config/file.c
- src/config/help.c
- src/modules/cache.c
- src/modules/entry.c
- src/modules/modules.c
- src/modules/modules.h


Changes:

=====================================
include/vlc_configuration.h
=====================================
@@ -75,11 +75,6 @@ typedef int (*vlc_integer_list_cb)(const char *, int64_t **, char ***);
 struct module_config_t
 {
     uint8_t     i_type; /**< Configuration type */
-    char        i_short; /**< Optional short option name */
-    unsigned    b_internal:1; /**< Hidden from preferences and help */
-    unsigned    b_unsaveable:1; /**< Not stored in configuration */
-    unsigned    b_safe:1; /**< Safe for web plugins and playlist files */
-    unsigned    b_removed:1; /**< Obsolete */
 
     const char *psz_type; /**< Configuration subtype */
     const char *psz_name; /**< Option name */
@@ -99,7 +94,6 @@ struct module_config_t
         const int  *i; /**< Table of possible integer choices */
     } list; /**< Possible choices */
     const char **list_text; /**< Human-readable names for list values */
-    void *owner; /**< Origin run-time linker module handle */
 };
 
 /**


=====================================
src/config/chain.c
=====================================
@@ -361,7 +361,9 @@ void config_ChainParse( vlc_object_t *p_this, const char *psz_prefix,
          * with slight changes */
         if( p_conf )
         {
-            if( p_conf->b_removed )
+            struct vlc_param *param = container_of(p_conf, struct vlc_param,
+                                                   item);
+            if (param->obsolete)
             {
                 msg_Err( p_this, "Option %s is not supported anymore.",
                          name );


=====================================
src/config/cmdline.c
=====================================
@@ -116,7 +116,8 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
     {
         for (size_t i = 0; i < p->conf.size; i++)
         {
-            const module_config_t *p_item = p->conf.items + i;
+            const struct vlc_param *param = p->conf.params + i;
+            const module_config_t *p_item = &param->item;
 
             /* Ignore hints */
             if( !CONFIG_ITEM(p_item->i_type) )
@@ -156,13 +157,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
             i_index++;
 
             /* If item also has a short option, add it */
-            if( p_item->i_short )
+            if (param->shortname)
             {
-                pp_shortopts[(int)p_item->i_short] = p_item;
-                psz_shortopts[i_shortopts] = p_item->i_short;
-                i_shortopts++;
+                pp_shortopts[param->shortname] = p_item;
+                psz_shortopts[i_shortopts++] = param->shortname;
+
                 if( p_item->i_type != CONFIG_ITEM_BOOL
-                 && p_item->i_short != 'v' )
+                 && param->shortname != 'v' )
                 {
                     psz_shortopts[i_shortopts] = ':';
                     i_shortopts++;
@@ -199,8 +200,10 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
             p_conf = config_FindConfig( psz_name );
             if( p_conf )
             {
+                struct vlc_param *param = container_of(p_conf,
+                                                       struct vlc_param, item);
                 /* Check if the option is deprecated */
-                if( p_conf->b_removed )
+                if (param->obsolete)
                 {
                     fprintf(stderr,
                             "Warning: option --%s no longer exists.\n",


=====================================
src/config/configuration.h
=====================================
@@ -21,15 +21,23 @@
 #ifndef LIBVLC_CONFIGURATION_H
 # define LIBVLC_CONFIGURATION_H 1
 
-# ifdef __cplusplus
-extern "C" {
-# endif
-
 /* Internal configuration prototypes and structures */
 
+struct vlc_plugin_t;
+
+struct vlc_param {
+    struct vlc_plugin_t *owner;
+    unsigned char shortname; /**< Optional short option name */
+    unsigned internal:1; /**< Hidden from preferences and help */
+    unsigned unsaved:1; /**< Not stored in persistent configuration */
+    unsigned safe:1; /**< Safe for untrusted provisioning (playlists) */
+    unsigned obsolete:1; /**< Ignored for backward compatibility */
+    struct module_config_t item;
+};
+
 int  config_AutoSaveConfigFile( vlc_object_t * );
 
-void config_Free (module_config_t *, size_t);
+void config_Free(struct vlc_param *, size_t);
 
 int config_LoadCmdLine   ( vlc_object_t *, int, const char *[], int * );
 int config_LoadConfigFile( vlc_object_t * );
@@ -58,7 +66,4 @@ char *config_GetLibDir(void) VLC_USED VLC_MALLOC;
 /* The configuration file */
 #define CONFIG_FILE                     "vlcrc"
 
-# ifdef __cplusplus
-}
-# endif
 #endif


=====================================
src/config/core.c
=====================================
@@ -73,7 +73,12 @@ int config_GetType(const char *psz_name)
 bool config_IsSafe( const char *name )
 {
     module_config_t *p_config = config_FindConfig( name );
-    return p_config != NULL && p_config->b_safe;
+    if (p_config == NULL)
+        return false;
+
+    const struct vlc_param *param = container_of(p_config, struct vlc_param,
+                                                 item);
+    return param->safe;
 }
 
 static module_config_t * config_FindConfigChecked( const char *psz_name )
@@ -209,12 +214,13 @@ ssize_t config_GetIntChoices(const char *name,
     module_config_t *cfg = config_FindConfigChecked(name);
     assert(cfg != NULL);
 
+    struct vlc_param *param = container_of(cfg, struct vlc_param, item);
     size_t count = cfg->list_count;
     if (count == 0)
     {
         int (*cb)(const char *, int64_t **, char ***);
 
-        cb = vlc_plugin_Symbol(NULL, cfg->owner, "vlc_entry_cfg_int_enum");
+        cb = vlc_plugin_Symbol(NULL, param->owner, "vlc_entry_cfg_int_enum");
         if (cb == NULL)
             return 0;
 
@@ -319,6 +325,8 @@ ssize_t config_GetPszChoices(const char *name,
         return -1;
     }
 
+    struct vlc_param *param = container_of(cfg, struct vlc_param, item);
+
     switch (cfg->i_type)
     {
         case CONFIG_ITEM_MODULE:
@@ -337,7 +345,7 @@ ssize_t config_GetPszChoices(const char *name,
     {
         int (*cb)(const char *, char ***, char ***);
 
-        cb = vlc_plugin_Symbol(NULL, cfg->owner, "vlc_entry_cfg_str_enum");
+        cb = vlc_plugin_Symbol(NULL, param->owner, "vlc_entry_cfg_str_enum");
         if (cb == NULL)
             return 0;
 
@@ -383,21 +391,21 @@ error:
 
 static int confcmp (const void *a, const void *b)
 {
-    const module_config_t *const *ca = a, *const *cb = b;
+    const struct vlc_param *const *ca = a, *const *cb = b;
 
-    return strcmp ((*ca)->psz_name, (*cb)->psz_name);
+    return strcmp ((*ca)->item.psz_name, (*cb)->item.psz_name);
 }
 
 static int confnamecmp (const void *key, const void *elem)
 {
-    const module_config_t *const *conf = elem;
+    const struct vlc_param *const *conf = elem;
 
-    return strcmp (key, (*conf)->psz_name);
+    return strcmp (key, (*conf)->item.psz_name);
 }
 
 static struct
 {
-    module_config_t **list;
+    struct vlc_param **list;
     size_t count;
 } config = { NULL, 0 };
 
@@ -412,7 +420,7 @@ int config_SortConfig (void)
     for (p = vlc_plugins; p != NULL; p = p->next)
         nconf += p->conf.count;
 
-    module_config_t **clist = vlc_alloc (nconf, sizeof (*clist));
+    struct vlc_param **clist = vlc_alloc(nconf, sizeof (*clist));
     if (unlikely(clist == NULL))
         return VLC_ENOMEM;
 
@@ -421,12 +429,13 @@ int config_SortConfig (void)
     {
         for (size_t i = 0; i < p->conf.size; i++)
         {
-            module_config_t *item = p->conf.items + i;
+            struct vlc_param *param = p->conf.params + i;
+            module_config_t *item = &param->item;
 
             if (!CONFIG_ITEM(item->i_type))
                 continue; /* ignore hints */
             assert(index < nconf);
-            clist[index++] = item;
+            clist[index++] = param;
         }
     }
 
@@ -439,7 +448,7 @@ int config_SortConfig (void)
 
 void config_UnsortConfig (void)
 {
-    module_config_t **clist;
+    struct vlc_param **clist;
 
     clist = config.list;
     config.list = NULL;
@@ -453,9 +462,9 @@ module_config_t *config_FindConfig(const char *name)
     if (unlikely(name == NULL))
         return NULL;
 
-    module_config_t *const *p;
+    struct vlc_param *const *p;
     p = bsearch (name, config.list, config.count, sizeof (*p), confnamecmp);
-    return p ? *p : NULL;
+    return p ? &(*p)->item : NULL;
 }
 
 /**
@@ -463,11 +472,11 @@ module_config_t *config_FindConfig(const char *name)
  * \param config start of array of items
  * \param confsize number of items in the array
  */
-void config_Free (module_config_t *tab, size_t confsize)
+void config_Free(struct vlc_param *tab, size_t confsize)
 {
     for (size_t j = 0; j < confsize; j++)
     {
-        module_config_t *p_item = &tab[j];
+        module_config_t *p_item = &tab[j].item;
 
         if (IsConfigStringType (p_item->i_type))
         {
@@ -489,7 +498,8 @@ void config_ResetAll(void)
     {
         for (size_t i = 0; i < p->conf.size; i++ )
         {
-            module_config_t *p_config = p->conf.items + i;
+            struct vlc_param *param = p->conf.params + i;
+            module_config_t *p_config = &param->item;
 
             if (IsConfigIntegerType (p_config->i_type))
                 p_config->value.i = p_config->orig.i;


=====================================
src/config/file.c
=====================================
@@ -205,11 +205,12 @@ int config_LoadConfigFile( vlc_object_t *p_this )
         if (item == NULL)
             continue;
 
+        struct vlc_param *param = container_of (item, struct vlc_param, item);
         /* Reject values of options that are unsaveable */
-        if (item->b_unsaveable)
+        if (param->unsaved)
             continue;
         /* Ignore options that are obsolete */
-        if (item->b_removed)
+        if (param->obsolete)
             continue;
 
         const char *psz_option_value = ptr + 1;
@@ -427,7 +428,6 @@ int config_SaveConfigFile (vlc_object_t *p_this)
     for (vlc_plugin_t *p = vlc_plugins; p != NULL; p = p->next)
     {
         module_t *p_parser = p->module;
-        module_config_t *p_item, *p_end;
 
         if (p->conf.count == 0)
             continue;
@@ -438,13 +438,16 @@ int config_SaveConfigFile (vlc_object_t *p_this)
         else
             fprintf( file, "\n\n" );
 
-        for (p_item = p->conf.items, p_end = p_item + p->conf.size;
-             p_item < p_end;
-             p_item++)
+        for (struct vlc_param *param = p->conf.params,
+                              *end = param + p->conf.size;
+             param < end;
+             param++)
         {
+            module_config_t *p_item = &param->item;
+
             if (!CONFIG_ITEM(p_item->i_type)   /* ignore hint */
-             || p_item->b_removed              /* ignore deprecated option */
-             || p_item->b_unsaveable)          /* ignore volatile option */
+             || param->obsolete                /* ignore deprecated option */
+             || param->unsaved)                /* ignore volatile option */
                 continue;
 
             if (IsConfigIntegerType (p_item->i_type))


=====================================
src/config/help.c
=====================================
@@ -343,9 +343,10 @@ static int vlc_swidth(const char *str)
     }
 }
 
-static void print_item(const module_t *m, const module_config_t *item,
+static void print_item(const module_t *m, const struct vlc_param *param,
                        const module_config_t **section, bool color, bool desc)
 {
+    const module_config_t *item = &param->item;
 #ifndef _WIN32
 # define OPTION_VALUE_SEP " "
 #else
@@ -495,8 +496,8 @@ static void print_item(const module_t *m, const module_config_t *item,
 
     /* Add short option if any */
     char shortopt[4];
-    if (item->i_short != '\0')
-        sprintf(shortopt, "-%c,", item->i_short);
+    if (param->shortname != '\0')
+        sprintf(shortopt, "-%c,", param->shortname);
     else
         strcpy(shortopt, "   ");
 
@@ -566,11 +567,12 @@ static bool plugin_show(const vlc_plugin_t *plugin)
 {
     for (size_t i = 0; i < plugin->conf.size; i++)
     {
-        const module_config_t *item = plugin->conf.items + i;
+        const struct vlc_param *param = plugin->conf.params + i;
+        const module_config_t *item = &param->item;
 
         if (!CONFIG_ITEM(item->i_type))
             continue;
-        if (item->b_removed)
+        if (param->obsolete)
             continue;
         return true;
     }
@@ -624,12 +626,12 @@ static void Usage (vlc_object_t *p_this, char const *psz_search)
         /* Print module options */
         for (size_t j = 0; j < p->conf.size; j++)
         {
-            const module_config_t *item = p->conf.items + j;
+            const struct vlc_param *param = p->conf.params + j;
 
-            if (item->b_removed)
+            if (param->obsolete)
                 continue; /* Skip removed options */
 
-            print_item(m, item, &section, color, desc);
+            print_item(m, param, &section, color, desc);
         }
     }
 


=====================================
src/modules/cache.c
=====================================
@@ -178,14 +178,16 @@ static int vlc_cache_load_align(size_t align, block_t *file)
     if (vlc_cache_load_align(alignof(t), file)) \
         goto error
 
-static int vlc_cache_load_config(module_config_t *cfg, block_t *file)
+static int vlc_cache_load_config(struct vlc_param *param, block_t *file)
 {
+    module_config_t *cfg = &param->item;
+
     LOAD_IMMEDIATE (cfg->i_type);
-    LOAD_IMMEDIATE (cfg->i_short);
-    LOAD_FLAG (cfg->b_internal);
-    LOAD_FLAG (cfg->b_unsaveable);
-    LOAD_FLAG (cfg->b_safe);
-    LOAD_FLAG (cfg->b_removed);
+    LOAD_IMMEDIATE (param->shortname);
+    LOAD_FLAG (param->internal);
+    LOAD_FLAG (param->unsaved);
+    LOAD_FLAG (param->safe);
+    LOAD_FLAG (param->obsolete);
     LOAD_STRING (cfg->psz_type);
     LOAD_STRING (cfg->psz_name);
     LOAD_STRING (cfg->psz_text);
@@ -248,24 +250,25 @@ static int vlc_cache_load_plugin_config(vlc_plugin_t *plugin, block_t *file)
     /* Allocate memory */
     if (lines)
     {
-        plugin->conf.items = calloc(sizeof (module_config_t), lines);
-        if (unlikely(plugin->conf.items == NULL))
+        plugin->conf.params = calloc(sizeof (struct vlc_param), lines);
+        if (unlikely(plugin->conf.params == NULL))
         {
             plugin->conf.size = 0;
             return -1;
         }
     }
     else
-        plugin->conf.items = NULL;
+        plugin->conf.params = NULL;
 
     plugin->conf.size = lines;
 
     /* Do the duplication job */
     for (size_t i = 0; i < lines; i++)
     {
-        module_config_t *item = plugin->conf.items + i;
+        struct vlc_param *param = plugin->conf.params + i;
+        module_config_t *item = &param->item;
 
-        if (vlc_cache_load_config(item, file))
+        if (vlc_cache_load_config(param, file))
             return -1;
 
         if (CONFIG_ITEM(item->i_type))
@@ -274,7 +277,7 @@ static int vlc_cache_load_plugin_config(vlc_plugin_t *plugin, block_t *file)
             if (item->i_type == CONFIG_ITEM_BOOL)
                 plugin->conf.booleans++;
         }
-        item->owner = plugin;
+        param->owner = plugin;
     }
 
     return 0;
@@ -506,14 +509,16 @@ static int CacheSaveAlign(FILE *file, size_t align)
     if (CacheSaveAlign(file, alignof (t))) \
         goto error
 
-static int CacheSaveConfig (FILE *file, const module_config_t *cfg)
+static int CacheSaveConfig(FILE *file, const struct vlc_param *param)
 {
+    const module_config_t *cfg = &param->item;
+
     SAVE_IMMEDIATE (cfg->i_type);
-    SAVE_IMMEDIATE (cfg->i_short);
-    SAVE_FLAG (cfg->b_internal);
-    SAVE_FLAG (cfg->b_unsaveable);
-    SAVE_FLAG (cfg->b_safe);
-    SAVE_FLAG (cfg->b_removed);
+    SAVE_IMMEDIATE (param->shortname);
+    SAVE_FLAG (param->internal);
+    SAVE_FLAG (param->unsaved);
+    SAVE_FLAG (param->safe);
+    SAVE_FLAG (param->obsolete);
     SAVE_STRING (cfg->psz_type);
     SAVE_STRING (cfg->psz_name);
     SAVE_STRING (cfg->psz_text);
@@ -556,7 +561,7 @@ static int CacheSaveModuleConfig(FILE *file, const vlc_plugin_t *plugin)
     SAVE_IMMEDIATE (lines);
 
     for (size_t i = 0; i < lines; i++)
-        if (CacheSaveConfig(file, plugin->conf.items + i))
+        if (CacheSaveConfig(file, plugin->conf.params + i))
            goto error;
 
     return 0;


=====================================
src/modules/entry.c
=====================================
@@ -99,7 +99,7 @@ vlc_plugin_t *vlc_plugin_create(void)
 
     plugin->modules_count = 0;
     plugin->textdomain = NULL;
-    plugin->conf.items = NULL;
+    plugin->conf.params = NULL;
     plugin->conf.size = 0;
     plugin->conf.count = 0;
     plugin->conf.booleans = 0;
@@ -129,7 +129,7 @@ void vlc_plugin_destroy(vlc_plugin_t *plugin)
     if (plugin->module != NULL)
         vlc_module_destroy(plugin->module);
 
-    config_Free(plugin->conf.items, plugin->conf.size);
+    config_Free(plugin->conf.params, plugin->conf.size);
 #ifdef HAVE_DYNAMIC_PLUGINS
     free(plugin->abspath);
     free(plugin->path);
@@ -140,7 +140,7 @@ void vlc_plugin_destroy(vlc_plugin_t *plugin)
 static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
 {
     unsigned confsize = plugin->conf.size;
-    module_config_t *tab = plugin->conf.items;
+    struct vlc_param *tab = plugin->conf.params;
 
     if ((confsize & 0xf) == 0)
     {
@@ -148,24 +148,27 @@ static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
         if (tab == NULL)
             return NULL;
 
-        plugin->conf.items = tab;
+        plugin->conf.params = tab;
     }
 
     memset (tab + confsize, 0, sizeof (tab[confsize]));
-    tab += confsize;
-    tab->owner = plugin;
+
+    struct vlc_param *param = tab + confsize;
+    struct module_config_t *item = &param->item;
+
+    param->owner = plugin;
 
     if (IsConfigIntegerType (type))
     {
-        tab->max.i = INT64_MAX;
-        tab->min.i = INT64_MIN;
+        item->max.i = INT64_MAX;
+        item->min.i = INT64_MIN;
     }
     else if( IsConfigFloatType (type))
     {
-        tab->max.f = FLT_MAX;
-        tab->min.f = -FLT_MAX;
+        item->max.f = FLT_MAX;
+        item->min.f = -FLT_MAX;
     }
-    tab->i_type = type;
+    item->i_type = type;
 
     if (CONFIG_ITEM(type))
     {
@@ -175,7 +178,7 @@ static module_config_t *vlc_config_create(vlc_plugin_t *plugin, int type)
     }
     plugin->conf.size++;
 
-    return tab;
+    return item;
 }
 
 /**
@@ -362,28 +365,48 @@ static int vlc_plugin_desc_cb(void *ctx, void *tgt, int propid, ...)
         }
 
         case VLC_CONFIG_VOLATILE:
-            item->b_unsaveable = true;
+        {
+            struct vlc_param *param = container_of (item, struct vlc_param,
+                                                    item);
+            param->unsaved = true;
             break;
+        }
 
         case VLC_CONFIG_PRIVATE:
-            item->b_internal = true;
+        {
+            struct vlc_param *param = container_of (item, struct vlc_param,
+                                                    item);
+            param->internal = true;
             break;
+        }
 
         case VLC_CONFIG_REMOVED:
-            item->b_removed = true;
+        {
+            struct vlc_param *param = container_of (item, struct vlc_param,
+                                                    item);
+            param->obsolete = true;
             break;
+        }
 
         case VLC_CONFIG_CAPABILITY:
             item->psz_type = va_arg (ap, const char *);
             break;
 
         case VLC_CONFIG_SHORTCUT:
-            item->i_short = va_arg (ap, int);
+        {
+            struct vlc_param *param = container_of (item, struct vlc_param,
+                                                    item);
+            param->shortname = va_arg(ap, int);
             break;
+        }
 
         case VLC_CONFIG_SAFE:
-            item->b_safe = true;
+        {
+            struct vlc_param *param = container_of (item, struct vlc_param,
+                                                    item);
+            param->safe = true;
             break;
+        }
 
         case VLC_CONFIG_DESC:
             item->psz_text = va_arg (ap, const char *);


=====================================
src/modules/modules.c
=====================================
@@ -351,9 +351,11 @@ module_config_t *module_config_get( const module_t *module, unsigned *restrict p
     unsigned i, j;
     for( i = 0, j = 0; i < size; i++ )
     {
-        const module_config_t *item = plugin->conf.items + i;
-        if( item->b_internal /* internal option */
-         || item->b_removed /* removed option */ )
+        const struct vlc_param *param = plugin->conf.params + i;
+        const module_config_t *item = &param->item;
+
+        if (param->internal /* internal option */
+         || param->obsolete /* removed option */)
             continue;
 
         memcpy( config + j, item, sizeof( *config ) );


=====================================
src/modules/modules.h
=====================================
@@ -25,6 +25,8 @@
 
 # include <stdatomic.h>
 
+struct vlc_param;
+
 /** VLC plugin */
 typedef struct vlc_plugin_t
 {
@@ -39,7 +41,7 @@ typedef struct vlc_plugin_t
      */
     struct
     {
-        module_config_t *items; /**< Table of configuration items */
+        struct vlc_param *params; /**< Table of configuration items */
         size_t size; /**< Total count of all items */
         size_t count; /**< Count of real options (excludes hints) */
         size_t booleans; /**< Count of options that are of boolean type */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e514ff3d10ce22049813b672bdfc0e39bd378492...4bb18364728aebdf5fa11cbccc18f8faa3a8e5f0

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e514ff3d10ce22049813b672bdfc0e39bd378492...4bb18364728aebdf5fa11cbccc18f8faa3a8e5f0
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list