diff mbox series

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

Message ID 829def3bc27e138286677b95d549684b82f864f4.1690990428.git.ehem+xen@m5p.com (mailing list archive)
State New, archived
Headers show
Series Cleanup and splitting of xl.cfg parsing | expand

Commit Message

Elliott Mitchell July 25, 2023, 6:06 p.m. UTC
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@m5p.com>
---
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 mbox series

Patch

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*/
 
 /*