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

[Xen-devel] [PATCH V5 10/32] libxl: fix JSON generator for uint64_t



yajl_gen_integer cannot cope with uint64_t. A new function called
libxl__uint64_gen_json is introduced to handle uint64_t.

Also removed a duplicated definition of MemKB while I was there.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/libxl/idl.py          |    2 +-
 tools/libxl/libxl_json.c    |   21 +++++++++++++++++++++
 tools/libxl/libxl_json.h    |    1 +
 tools/libxl/libxl_types.idl |    4 +---
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/idl.py b/tools/libxl/idl.py
index e4dc79b..69e08e1 100644
--- a/tools/libxl/idl.py
+++ b/tools/libxl/idl.py
@@ -266,7 +266,7 @@ integer = Number("int", namespace = None, signed = True)
 uint8 = UInt(8)
 uint16 = UInt(16)
 uint32 = UInt(32)
-uint64 = UInt(64)
+uint64 = UInt(64, json_fn = "libxl__uint64_gen_json")
 
 string = Builtin("char *", namespace = None, dispose_fn = "free",
                  json_fn = "libxl__string_gen_json",
diff --git a/tools/libxl/libxl_json.c b/tools/libxl/libxl_json.c
index 3ea56a4..ff23376 100644
--- a/tools/libxl/libxl_json.c
+++ b/tools/libxl/libxl_json.c
@@ -794,6 +794,27 @@ out:
     return ret;
 }
 
+yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val)
+{
+    char *num;
+    unsigned int len;
+    yajl_gen_status s;
+
+    if (asprintf(&num, "%"PRIu64, val) == -1) {
+        s = yajl_gen_in_error_state;
+        goto out;
+    }
+
+    len = strlen(num);
+
+    s = yajl_gen_number(hand, num, len);
+
+    free(num);
+
+out:
+    return s;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_json.h b/tools/libxl/libxl_json.h
index a4dd8fc..a45d429 100644
--- a/tools/libxl/libxl_json.h
+++ b/tools/libxl/libxl_json.h
@@ -22,6 +22,7 @@
 #  include <yajl/yajl_version.h>
 #endif
 
+yajl_gen_status libxl__uint64_gen_json(yajl_gen hand, uint64_t val);
 yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, libxl_defbool *p);
 yajl_gen_status libxl_domid_gen_json(yajl_gen hand, libxl_domid *p);
 yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, libxl_uuid *p);
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 7b0901c..30a4f7a 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -22,7 +22,7 @@ libxl_hwcap = Builtin("hwcap", passby=PASS_BY_REFERENCE)
 # Specific integer types
 #
 
-MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
+MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", json_fn = 
"libxl__uint64_gen_json")
 
 #
 # Constants / Enumerations
@@ -288,8 +288,6 @@ libxl_domain_restore_params = 
Struct("domain_restore_params", [
     ("checkpointed_stream", integer),
     ])
 
-MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
-
 libxl_domain_sched_params = Struct("domain_sched_params",[
     ("sched",        libxl_scheduler),
     ("weight",       integer, {'init_val': 
'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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