]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
libxl: Add wrapper around libxl__json_object_to_json JSON
authorAnthony PERARD <anthony.perard@citrix.com>
Thu, 22 Nov 2018 18:38:39 +0000 (18:38 +0000)
committerWei Liu <wei.liu2@citrix.com>
Fri, 11 Jan 2019 14:57:35 +0000 (14:57 +0000)
That wrapper is going to be used to safely log a json_object, as
libxl__json_object_to_json return NULL on error. In the error case,
JSON() will return an invalid json string.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_internal.h

index aa9059ffecd8a7f41d891912e284164996bc8f8a..16e6eb6c5e05206e352908a3d1f3035baae0eba7 100644 (file)
@@ -2046,6 +2046,9 @@ _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc_opt, const char *s);
 
 _hidden char *libxl__json_object_to_json(libxl__gc *gc,
                                          const libxl__json_object *args);
+/* Always return a valid string, but invalid json on error. */
+#define JSON(o) \
+    (libxl__json_object_to_json(gc, (o)) ? : "<invalid-json-object>")
 
   /* Based on /local/domain/$domid/dm-version xenstore key
    * default is qemu xen traditional */