[vlc-commits] modules: remove plugins count from the plugins cache

Rémi Denis-Courmont git at videolan.org
Sun Feb 8 13:57:20 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb  7 21:10:57 2015 +0200| [514d4fcb6fcc1a9bcafbb53b753af63cbb57ef22] | committer: Rémi Denis-Courmont

modules: remove plugins count from the plugins cache

This potentially allows generating the plugins cache on-the-go - there
is no more need to know the total number of plugins ahead of time.

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

 src/modules/cache.c |   26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index 40af399..f43fea9 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -55,7 +55,7 @@
 #ifdef HAVE_DYNAMIC_PLUGINS
 /* Sub-version number
  * (only used to avoid breakage in dev version when cache structure changes) */
-#define CACHE_SUBVERSION_NUM 22
+#define CACHE_SUBVERSION_NUM 23
 
 /* Cache filename */
 #define CACHE_NAME "plugins.dat"
@@ -291,7 +291,6 @@ size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t **r )
     FILE *file;
     int i_size, i_read;
     char p_cachestring[sizeof(CACHE_STRING)];
-    size_t i_cache;
     int32_t i_marker;
 
     assert( dir != NULL );
@@ -337,7 +336,7 @@ size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t **r )
     }
 #endif
 
-    /* Check Sub-version number */
+    /* Check sub-version number */
     i_read = fread( &i_marker, 1, sizeof(i_marker), file );
     if( i_read != sizeof(i_marker) || i_marker != CACHE_SUBVERSION_NUM )
     {
@@ -358,21 +357,18 @@ size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t **r )
         return 0;
     }
 
-    if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
-    {
-        msg_Warn( p_this, "This doesn't look like a valid plugins cache "
-                  "(file too short)" );
-        fclose( file );
-        return 0;
-    }
-
     module_cache_t *cache = NULL;
+    size_t count = 0;
 
-    for (size_t count = 0; count < i_cache;)
+    for (;;)
     {
         module_t *module = CacheLoadModule (file);
         if (module == NULL)
+        {
+            if (feof (file))
+                break;
             goto error;
+        }
 
         char *path;
         struct stat st;
@@ -388,10 +384,11 @@ size_t CacheLoad( vlc_object_t *p_this, const char *dir, module_cache_t **r )
         free (path);
         /* TODO: deal with errors */
     }
+
     fclose( file );
 
     *r = cache;
-    return i_cache;
+    return count;
 
 error:
     if (ferror (file))
@@ -566,9 +563,6 @@ static int CacheSaveBank (FILE *file, const module_cache_t *cache,
     if (fwrite (&i_file_size, sizeof (i_file_size), 1, file) != 1)
         goto error;
 
-    if (fwrite( &i_cache, sizeof (i_cache), 1, file) != 1)
-        goto error;
-
     for (unsigned i = 0; i < i_cache; i++)
     {
         module_t *module = cache[i].p_module;



More information about the vlc-commits mailing list