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

[Xen-devel] [PATCH v7 04/14] libxl: Add wrapper around libxl__json_object_to_json JSON



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@xxxxxxxxxx>
---

Notes:
    v7:
        new patch
        There are no user yet because the first users is going to be in
        "libxl_qmp: Implementation of libxl__ev_qmp_*" which is already a
        huge patch, that 3 lines might get lost.

 tools/libxl/libxl_internal.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index d96c5b7f89..38c8c3a59d 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2034,6 +2034,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 */
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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