From 85390818f8fc565e7606a9b201bc6aa313d9f85d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
Date: Sat, 19 Jan 2013 10:45:04 +0200
Subject: [PATCH] cache: store whether there is a choices callback or not

---
 src/modules/cache.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index 9d83632ddbe0..97e42018b0cf 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -57,7 +57,7 @@
 #ifdef HAVE_DYNAMIC_PLUGINS
 /* Sub-version number
  * (only used to avoid breakage in dev version when cache structure changes) */
-#define CACHE_SUBVERSION_NUM 20
+#define CACHE_SUBVERSION_NUM 21
 
 /* Cache filename */
 #define CACHE_NAME "plugins.dat"
@@ -132,8 +132,8 @@ static int CacheLoadConfig (module_config_t *cfg, FILE *file)
 
         if (cfg->list_count)
             cfg->list.psz = xmalloc (cfg->list_count * sizeof (char *));
-        else
-            cfg->list.psz_cb = NULL;
+        else /* TODO: fix config_GetPszChoices() instead of this hack: */
+            LOAD_IMMEDIATE(cfg->list.psz_cb);
         for (unsigned i = 0; i < cfg->list_count; i++)
             LOAD_STRING (cfg->list.psz[i]);
     }
@@ -146,8 +146,8 @@ static int CacheLoadConfig (module_config_t *cfg, FILE *file)
 
         if (cfg->list_count)
             cfg->list.i = xmalloc (cfg->list_count * sizeof (int));
-        else
-            cfg->list.i_cb = NULL;
+        else /* TODO: fix config_GetPszChoices() instead of this hack: */
+            LOAD_IMMEDIATE(cfg->list.i_cb);
         for (unsigned i = 0; i < cfg->list_count; i++)
              LOAD_IMMEDIATE (cfg->list.i[i]);
     }
@@ -403,6 +403,8 @@ static int CacheSaveConfig (FILE *file, const module_config_t *cfg)
     if (IsConfigStringType (cfg->i_type))
     {
         SAVE_STRING (cfg->orig.psz);
+        if (cfg->list_count == 0)
+            SAVE_IMMEDIATE (cfg->list.psz_cb); /* XXX: see CacheLoadConfig() */
         for (unsigned i = 0; i < cfg->list_count; i++)
             SAVE_STRING (cfg->list.psz[i]);
     }
@@ -411,6 +413,8 @@ static int CacheSaveConfig (FILE *file, const module_config_t *cfg)
         SAVE_IMMEDIATE (cfg->orig);
         SAVE_IMMEDIATE (cfg->min);
         SAVE_IMMEDIATE (cfg->max);
+        if (cfg->list_count == 0)
+            SAVE_IMMEDIATE (cfg->list.i_cb); /* XXX: see CacheLoadConfig() */
         for (unsigned i = 0; i < cfg->list_count; i++)
              SAVE_IMMEDIATE (cfg->list.i[i]);
     }
-- 
GitLab