[PATCH 1/3] util: json: Make function to free JSON values in virHash universal

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

 



Move the helper that frees JSON entries put into hash tables into the
JSON module so that it does not have to be reimplemented.
---
 src/libvirt_private.syms     |  1 +
 src/qemu/qemu_monitor_json.c | 10 +---------
 src/util/virjson.c           |  8 ++++++++
 src/util/virjson.h           |  1 +
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index db0e11e33..84619f01f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1832,6 +1832,7 @@ virJSONValueGetNumberLong;
 virJSONValueGetNumberUint;
 virJSONValueGetNumberUlong;
 virJSONValueGetString;
+virJSONValueHashFree;
 virJSONValueIsArray;
 virJSONValueIsNull;
 virJSONValueNewArray;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 75af5cb93..e6b73d340 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7449,14 +7449,6 @@ qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED,
 }


-static void
-qemuMonitorJSONFreeSchemaEntry(void *opaque,
-                               const void *name ATTRIBUTE_UNUSED)
-{
-    virJSONValueFree(opaque);
-}
-
-
 virHashTablePtr
 qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
 {
@@ -7477,7 +7469,7 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)

     arr = virJSONValueObjectGet(reply, "return");

-    if (!(schema = virHashCreate(512, qemuMonitorJSONFreeSchemaEntry)))
+    if (!(schema = virHashCreate(512, virJSONValueHashFree)))
         goto cleanup;

     if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema,
diff --git a/src/util/virjson.c b/src/util/virjson.c
index c907b5ded..b49b29b0f 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -376,6 +376,14 @@ virJSONValueFree(virJSONValuePtr value)
 }


+void
+virJSONValueHashFree(void *opaque,
+                     const void *name ATTRIBUTE_UNUSED)
+{
+    virJSONValueFree(opaque);
+}
+
+
 virJSONValuePtr
 virJSONValueNewString(const char *data)
 {
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 5e32cb9a4..14b74c061 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -81,6 +81,7 @@ struct _virJSONValue {
 };

 void virJSONValueFree(virJSONValuePtr value);
+void virJSONValueHashFree(void *opaque, const void *name);

 int virJSONValueObjectCreate(virJSONValuePtr *obj, ...)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;
-- 
2.12.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux