[vlc-commits] modules: allow NULL for matched module names

Rémi Denis-Courmont git at videolan.org
Sat Sep 26 21:23:34 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Sep 25 22:14:13 2020 +0300| [a38a0cab8227a881d405d6da1c5ab780e3c33dea] | committer: Rémi Denis-Courmont

modules: allow NULL for matched module names

This just returns the non-zero priority modules. This matches the
behaviour of vlc_module_load() and module_need(), to simplify some of
the call sites.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a38a0cab8227a881d405d6da1c5ab780e3c33dea
---

 include/vlc_modules.h      |  3 ++-
 modules/codec/avcodec/va.c |  2 +-
 src/modules/modules.c      | 48 ++++++++++++++++++++++++----------------------
 src/network/tls.c          |  4 ++--
 4 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/include/vlc_modules.h b/include/vlc_modules.h
index ec3c602934..6dbb891240 100644
--- a/include/vlc_modules.h
+++ b/include/vlc_modules.h
@@ -43,7 +43,8 @@ struct vlc_logger;
  * table.
  *
  * \param capability capability, i.e. class of module
- * \param names string of comma-separated requested module shortcut names
+ * \param names string of comma-separated requested module shortcut names,
+ *              or NULL for defaults
  * \param strict whether to exclude modules with no unmatching shortcut names
  * \param modules storage location for the base address of a sorted table
  *                of candidate modules (NULL on error) [OUT]
diff --git a/modules/codec/avcodec/va.c b/modules/codec/avcodec/va.c
index f9497759e9..5f747ed46d 100644
--- a/modules/codec/avcodec/va.c
+++ b/modules/codec/avcodec/va.c
@@ -109,7 +109,7 @@ vlc_va_t *vlc_va_New(vlc_object_t *obj, AVCodecContext *avctx,
         return NULL;
 
     module_t **mods;
-    ssize_t total = vlc_module_match("hw decoder", "any", false, &mods, NULL);
+    ssize_t total = vlc_module_match("hw decoder", NULL, false, &mods, NULL);
 
     for (ssize_t i = 0; i < total; i++) {
         vlc_va_open open = vlc_module_map(obj->logger, mods[i]);
diff --git a/src/modules/modules.c b/src/modules/modules.c
index 531f96ad96..2b9ed30fe0 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -125,32 +125,34 @@ ssize_t vlc_module_match(const char *capability, const char *names,
     *modules = sorted;
 
     /* Go through the list of module shortcut names. */
-    while (names[0] != '\0') {
-        const char *shortcut = names;
-        size_t slen = strcspn(names, ",");
-
-        names += slen;
-        names += strspn(names, ",");
-
-        /* "none" matches nothing and ends the search */
-        if (slen == 4 && strncasecmp("none", shortcut, 4) == 0) {
-            total = 0;
-            break;
-        }
+    if (names != NULL) {
+        while (names[0] != '\0') {
+            const char *shortcut = names;
+            size_t slen = strcspn(names, ",");
+
+            names += slen;
+            names += strspn(names, ",");
+
+            /* "none" matches nothing and ends the search */
+            if (slen == 4 && strncasecmp("none", shortcut, 4) == 0) {
+                total = 0;
+                break;
+            }
 
-        /* "any" matches everything with strictly positive score */
-        if (slen == 3 && strncasecmp("any", shortcut, 3) == 0) {
-            strict = false;
-            break;
-        }
+            /* "any" matches everything with strictly positive score */
+            if (slen == 3 && strncasecmp("any", shortcut, 3) == 0) {
+                strict = false;
+                break;
+            }
 
-        for (size_t i = 0; i < total; i++) {
-            module_t *cand = unsorted[i];
+            for (size_t i = 0; i < total; i++) {
+                module_t *cand = unsorted[i];
 
-            if (cand != NULL && module_match_name(cand, shortcut, slen)) {
-                assert(matches < total);
-                sorted[matches++] = cand;
-                unsorted[i] = NULL;
+                if (cand != NULL && module_match_name(cand, shortcut, slen)) {
+                    assert(matches < total);
+                    sorted[matches++] = cand;
+                    unsorted[i] = NULL;
+                }
             }
         }
     }
diff --git a/src/network/tls.c b/src/network/tls.c
index 25f1c95bdc..0bbcee8e00 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -59,7 +59,7 @@ vlc_tls_ServerCreate (vlc_object_t *obj, const char *cert_path,
         key_path = cert_path;
 
     module_t **mods;
-    ssize_t total = vlc_module_match("tls server", "any", false, &mods, NULL);
+    ssize_t total = vlc_module_match("tls server", NULL, false, &mods, NULL);
 
     for (ssize_t i = 0; i < total; i++) {
         int (*probe)(vlc_tls_server_t *, const char *, const char *);
@@ -98,7 +98,7 @@ vlc_tls_client_t *vlc_tls_ClientCreate(vlc_object_t *obj)
         return NULL;
 
     module_t **mods;
-    ssize_t total = vlc_module_match("tls client", "any", false, &mods, NULL);
+    ssize_t total = vlc_module_match("tls client", NULL, false, &mods, NULL);
 
     for (ssize_t i = 0; i < total; i++) {
         int (*probe)(vlc_tls_client_t *);



More information about the vlc-commits mailing list