[PATCH 03/12] Split yajl_gen allocation into a separate function.

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

 



Split yajl_gen (and handling of the yajl version differences) into
virYAJLInit().

No functionality changed; the function will be used in a later patch.

Signed-off-by: Miloslav Trmač <mitr@xxxxxxxxxx>
---
 src/util/json.c | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/util/json.c b/src/util/json.c
index 8529b5f..1accde9 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -1073,6 +1073,27 @@ cleanup:
 }
 
 
+static yajl_gen virYAJLInit(bool pretty)
+{
+    yajl_gen g;
+# ifndef HAVE_YAJL2
+    yajl_gen_config conf = { pretty ? 1 : 0, pretty ? "    " : " "};
+# endif
+
+# ifdef HAVE_YAJL2
+    g = yajl_gen_alloc(NULL);
+    if (g) {
+        yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
+        yajl_gen_config(g, yajl_gen_indent_string, pretty ? "    " : " ");
+        yajl_gen_config(g, yajl_gen_validate_utf8, 1);
+    }
+# else
+    g = yajl_gen_alloc(&conf, NULL);
+# endif
+
+    return g;
+}
+
 static int virJSONValueToStringOne(virJSONValuePtr object,
                                    yajl_gen g)
 {
@@ -1143,22 +1164,10 @@ char *virJSONValueToString(virJSONValuePtr object,
     const unsigned char *str;
     char *ret = NULL;
     yajl_size_t len;
-# ifndef HAVE_YAJL2
-    yajl_gen_config conf = { pretty ? 1 : 0, pretty ? "    " : " "};
-# endif
 
     VIR_DEBUG("object=%p", object);
 
-# ifdef HAVE_YAJL2
-    g = yajl_gen_alloc(NULL);
-    if (g) {
-        yajl_gen_config(g, yajl_gen_beautify, pretty ? 1 : 0);
-        yajl_gen_config(g, yajl_gen_indent_string, pretty ? "    " : " ");
-        yajl_gen_config(g, yajl_gen_validate_utf8, 1);
-    }
-# else
-    g = yajl_gen_alloc(&conf, NULL);
-# endif
+    g = virYAJLInit(pretty);
     if (!g) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to create JSON formatter"));
-- 
1.7.11.4

--
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]