[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 17/22] tools/utils: move setting free loop to xlu__cfg_set_free()



This better breaks layers apart.  xlu_cfg_destroy() now only knows about
the XLU_Config structure, while xlu__cfg_set_free() knows about
XLU_ConfigSetting.

Move declaration of xlu__cfg_set_free() to shared header to indicate it
will bridge layers.

Signed-off-by: Elliott Mitchell <ehem+xen@xxxxxxx>
---
This is the end of the higher-value series.  Moving the loop is
appropriate whether or not libxlu_cfg.c is split.

Moving the declaration and patches after this though are mostly valuable
for splitting libxlu_cfg.c into reusable and non-reusable portions.
---
 tools/libs/util/libxlu_cfg.c      | 20 ++++++++------------
 tools/libs/util/libxlu_cfg_y.y    |  1 -
 tools/libs/util/libxlu_internal.h |  5 +++++
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/libs/util/libxlu_cfg.c b/tools/libs/util/libxlu_cfg.c
index 69b95a4ed0..7fec7fe7be 100644
--- a/tools/libs/util/libxlu_cfg.c
+++ b/tools/libs/util/libxlu_cfg.c
@@ -178,22 +178,18 @@ void xlu__cfg_value_free(XLU_ConfigValue *value)
 }
 
 void xlu__cfg_set_free(XLU_ConfigSetting *set) {
-    if (!set) return;
-    free(set->name);
-    xlu__cfg_value_free(set->value);
-    free(set);
+    while(set) {
+        XLU_ConfigSetting *next = set->next;
+        free(set->name);
+        xlu__cfg_value_free(set->value);
+        free(set);
+        set = next;
+    }
 }
 
 void xlu_cfg_destroy(XLU_Config *cfg) {
-    XLU_ConfigSetting *set, *set_next;
-
     if (!cfg) return;
-    for (set= cfg->settings;
-         set;
-         set= set_next) {
-        set_next= set->next;
-        xlu__cfg_set_free(set);
-    }
+    xlu__cfg_set_free(cfg->settings);
     free((void *)cfg->config_source);
     free(cfg);
 }
diff --git a/tools/libs/util/libxlu_cfg_y.y b/tools/libs/util/libxlu_cfg_y.y
index 5dfb06941a..5c7e31222d 100644
--- a/tools/libs/util/libxlu_cfg_y.y
+++ b/tools/libs/util/libxlu_cfg_y.y
@@ -32,7 +32,6 @@ enum XLU_Operation {
     XLU_OP_ADDITION,
 };
 
-void xlu__cfg_set_free(XLU_ConfigSetting *set);
 void xlu__cfg_set_store(CfgParseContext*, char *name,
                         enum XLU_Operation op,
                         XLU_ConfigValue *val, int lineno);
diff --git a/tools/libs/util/libxlu_internal.h 
b/tools/libs/util/libxlu_internal.h
index 93caf24a6e..cc98efba27 100644
--- a/tools/libs/util/libxlu_internal.h
+++ b/tools/libs/util/libxlu_internal.h
@@ -35,6 +35,11 @@ typedef struct XLU_ConfigSetting XLU_ConfigSetting;
 extern int xlu_cfg_printf(const XLU_Config *cfg, const char *format, ...)
     __attribute__((__format__(__printf__, 2, 3)));
 
+/*
+ * Internals for file parser *only*, NOT to be used by other parsing/lexing
+ */
+extern void xlu__cfg_set_free(XLU_ConfigSetting *set);
+
 #endif /*LIBXLU_INTERNAL_H*/
 
 /*
-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |       ehem+sigmsg@xxxxxxx      PGP 87145445       |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445






 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.