libxl: fixes for JSON infrastructure
v2 cover libxl: fixes for JSON infrastructure
This small series contains three fixes to libxl JSON infrasturcture.
Changes in V2:
* generate empty map for None field in keyed-union
* replace empty Struct with None for libxl_event
Wei.
Wei Liu (4):
libxl/gentypes.py: don't generate JSON for private type(s)
libxl_json: fix JSON parser debug code libxl/gentypes.py: generate empty map for None field in keyed-union libxl_types.idl: replace empty Struct with None for libxl_event
tools/libxl/gentypes.py | 9 ++++++++- tools/libxl/libxl_json.c | 17 +++++++++++++---- tools/libxl/libxl_types.idl | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v2 1/4 libxl/gentypes.py: don't generate JSON for private type(s)
Private types are only useful inside libxl. They don't have a valid JSON generation function by default.
Currently there's only one private type, that's libxl_ev_link. Not skipping this field causes testidl to fail as the code generated for this type is NULL.
--- tools/libxl/gentypes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/gentypes.py +1 -1
@@ -226,7 +226,7 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += "s = yajl_gen_map_open(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n" - for f in [f for f in ty.fields if not f.const]: + for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) s += "s = yajl_gen_string(hand, (const unsigned char *)\"%s\", sizeof(\"%s\")-1);\n" % (f.name, f.name) s += "if (s != yajl_gen_status_ok)\n"
Signature · 1 line
1.7.10.4
Re: [PATCH V2 1/4] libxl/gentypes.py: don't generate JSON for private type(s)
Quoted 8 lines · Wei Liu
Private types are only useful inside libxl. They don't have a valid JSON generation function by default.
Currently there's only one private type, that's
libxl_ev_link. Not skipping this field causes testidl to fail as the code generated for this type is NULL.Signed-off-by Wei Liu <[email protected]>
PATCH v2 2/4 libxl_json: fix JSON parser debug code
In reply to Wei LiuTwo changes included:
1. implement DEBUG_GEN_ALLOC for YAJL2
2. use size_t for variable "len"
without these two fixes it fails to compile when DEBUG_ANSWER is defined.
--- tools/libxl/libxl_json.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
tools/libxl/libxl_json.c +13 -4
@@ -34,11 +34,20 @@ struct libxl__yajl_ctx { };#ifdef DEBUG_ANSWER -# define DEBUG_GEN_ALLOC (ctx) \ - if ((ctx)->g == NULL) { \ - yajl_gen_config conf = { 1, " " }; \ +#if YAJL_VERSION <20000 +# define DEBUG_GEN_ALLOC (ctx) \ + if ((ctx)->g == NULL) { \ + yajl_gen_config conf = { 1, " " }; \ (ctx)->g = yajl_gen_alloc(&conf, NULL); \ } +#else /* YAJL2 */ +# define DEBUG_GEN_ALLOC (ctx) \ + if ((ctx)->g == NULL) { \ + (ctx)->g = yajl_gen_alloc(NULL); \ + yajl_gen_config((ctx)->g, yajl_gen_beautify, 1); \ + yajl_gen_config((ctx)->g, yajl_gen_indent_string, " "); \ + } +#endif # define DEBUG_GEN_FREE (ctx) \ if ((ctx)->g) yajl_gen_free((ctx)->g)# define DEBUG_GEN (ctx, type) yajl_gen_##type(ctx->g)
@@ -48,7 +57,7 @@ struct libxl__yajl_ctx {# define DEBUG_GEN_REPORT (yajl_ctx) \ do { \ const unsigned char *buf = NULL; \ - unsigned int len = 0; \ + size_t len = 0; \ yajl_gen_get_buf((yajl_ctx)->g, &buf, &len); \ LIBXL__LOG(libxl__gc_owner((yajl_ctx)->gc), \ LIBXL__LOG_DEBUG, "response:\n%s", buf); \
Signature · 1 line
1.7.10.4
Re: [PATCH V2 2/4] libxl_json: fix JSON parser debug code
Quoted 8 lines · Wei Liu
Two changes included:
1. implementDEBUG_GEN_ALLOCfor YAJL2
2. usesize_tfor variable "len"without these two fixes it fails to compile when
DEBUG_ANSWERis defined.Signed-off-by Wei Liu <[email protected]>
PATCH v2 3/4 libxl/gentypes.py: generate empty map for None field in keyed-union
In reply to Wei LiuWithout this the generated JSON is malformed.
--- tools/libxl/gentypes.py | 7 +++++++ 1 file changed, 7 insertions(+)
tools/libxl/gentypes.py +7 -0
@@ -220,6 +220,13 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += "case %s:\n" % f.enumname if f.type is not None: s += libxl_C_type_gen_json(f.type, fexpr, indent + " ", nparent) + else: + s += " yajl_gen_map_open(hand);\n" + s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " yajl_gen_map_close(hand);\n" + s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" s += " break;\n" s += "}\n" elif isinstance(ty, idl.Struct) and (parent is None or ty.json_fn is None):
Signature · 1 line
1.7.10.4
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Quoted 3 lines · Wei Liu
Without this the generated JSON is malformed.
Signed-off-by Wei Liu <[email protected]>
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
In reply to Wei LiuQuoted 3 lines · Wei Liu
Without this the generated JSON is malformed.
Signed-off-by Wei Liu <[email protected]>
Hold on the Ack...
Review
Quoted 2 lines
(quoted diff) +2
-0+ else: + s += " yajl_gen_map_open(hand);\n"
ITHM s =...
Review
Quoted 3 lines
(quoted diff) +3
-0+ s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " yajl_gen_map_close(hand);\n"
and again.
Spotted because the diff of the generated code across the entire series was as below, the spurious change is pretty obvious in the third hunk.
Ian.
libxl/_libxl_types.c renamed from libxl/_libxl_BACKUP_types.c +8 -5
@@ -2523,6 +2523,12 @@ yajl_gen_status libxl_domain_build_info_ goto out;break ;case LIBXL_DOMAIN_TYPE_INVALID : +yajl_gen_map_open (hand); +if (s != yajl_gen_status_ok) + goto out; +yajl_gen_map_close (hand); +if (s != yajl_gen_status_ok) + goto out;break ; } s =yajl_gen_map_close (hand);
@@ -3631,9 +3637,6 @@ yajl_gen_status libxl_event_gen_json(yaj s =yajl_gen_map_open (hand);if (s != yajl_gen_status_ok) goto out; - s =yajl_gen_string (hand, (const unsigned char *)"link" ,sizeof ("link" )-1 ); -if (s != yajl_gen_status_ok) - goto out; s =yajl_gen_string (hand, (const unsigned char *)"domid" ,sizeof ("domid" )-1 );if (s != yajl_gen_status_ok) goto out;
@@ -3713,10 +3716,10 @@ yajl_gen_status libxl_event_gen_json(yaj goto out;break ;case LIBXL_EVENT_TYPE_DOMAIN_CREATE_CONSOLE_AVAILABLE : - s =yajl_gen_map_open (hand); +yajl_gen_map_open (hand);if (s != yajl_gen_status_ok) goto out; - s =yajl_gen_map_close (hand); +yajl_gen_map_close (hand);if (s != yajl_gen_status_ok) goto out;break ;
libxl/_libxl_types.h renamed from libxl/_libxl_BACKUP_types.h +0 -2
@@ -694,8 +694,6 @@ typedef struct libxl_event {struct {int rc; } operation_complete; -struct { - } domain_create_console_available; } u; } libxl_event;void libxl_event_dispose (libxl_event *p);
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Quoted 12 lines · Ian Campbell
Quoted 3 lines · Wei Liu
Without this the generated JSON is malformed.
Signed-off-by Wei Liu <[email protected]>Hold on the Ack...
Review
Quoted 2 lines
(quoted diff) +2
-0+ else: + s += " yajl_gen_map_open(hand);\n"ITHM s =...
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " yajl_gen_map_close(hand);\n"and again.
Spotted because the diff of the generated code across the entire series was as below, the spurious change is pretty obvious in the third hunk.
I should've stolen your handy script earlier!
This one should be correct.
---8<---
Quoted 1 line
From
eda04499a0b15d0a7549206834112823b59cf6f9Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Thu, 10 Apr 2014 16:18:00 +0100
Subject: [PATCH] libxl/gentypes.py: generate empty map for None field in
keyed-union
Without this the generated JSON is malformed.
--- tools/libxl/gentypes.py | 7 +++++++ 1 file changed, 7 insertions(+)
tools/libxl/gentypes.py +7 -0
@@ -220,6 +220,13 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += "case %s:\n" % f.enumname if f.type is not None: s += libxl_C_type_gen_json(f.type, fexpr, indent + " ", nparent) + else: + s += " s = yajl_gen_map_open(hand);\n" + s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " s = yajl_gen_map_close(hand);\n" + s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" s += " break;\n" s += "}\n" elif isinstance(ty, idl.Struct) and (parent is None or ty.json_fn is None):
Signature · 1 line
1.7.10.4
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Quoted 17 lines · Wei Liu
Quoted 16 lines · Ian Campbell
Quoted 3 lines · Wei Liu
Without this the generated JSON is malformed.
Signed-off-by Wei Liu <[email protected]>Hold on the Ack...
Review
Quoted 2 lines
(quoted diff) +2
-0+ else: + s += " yajl_gen_map_open(hand);\n"ITHM s =...
Quoted 3 lines
tools/libxl/gentypes.py +3
-0+ s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " yajl_gen_map_close(hand);\n"
Quoted 7 lines
Quoted 5 lines
and again.
Spotted because the diff of the generated code across the entire series was as below, the spurious change is pretty obvious in the third hunk.
I should've stolen your handy script earlier!
~ianc/xen-build-tools/libxl-idl-* if you still want to...
Quoted 1 line
This one should be correct.
Agreed, you can have that Ack back ;-)
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Quoted 24 lines · Ian Campbell
Quoted 23 lines · Wei Liu
Quoted 21 lines · Ian Campbell
Quoted 3 lines · Wei Liu
Without this the generated JSON is malformed.
Signed-off-by Wei Liu <[email protected]>Hold on the Ack...
Review
Quoted 2 lines
(quoted diff) +2
-0+ else: + s += " yajl_gen_map_open(hand);\n"ITHM s =...
tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None):
Quoted 3 lines
tools/libxl/gentypes.py +3
-0+ s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " yajl_gen_map_close(hand);\n"and again.
Spotted because the diff of the generated code across the entire series was as below, the spurious change is pretty obvious in the third hunk.
Quoted 8 lines
Quoted 1 line
I should've stolen your handy script earlier!
~ianc/xen-build-tools/libxl-idl-* if you still want to...
Quoted 1 line
This one should be correct.
Agreed, you can have that Ack back ;-)
Do you want me to resend the whole series with all Acks folded in?
Wei.
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Quoted 27 lines · Wei Liu
Quoted 26 lines · Ian Campbell
Quoted 24 lines · Wei Liu
Quoted 12 lines · Ian Campbell
Quoted 3 lines · Wei Liu
Without this the generated JSON is malformed.
Signed-off-by Wei Liu <[email protected]>Hold on the Ack...
Review
Quoted 2 lines
(quoted diff) +2
-0+ else: + s += " yajl_gen_map_open(hand);\n"ITHM s =...
Quoted 9 lines
tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None):
Quoted 3 lines
tools/libxl/gentypes.py +3
-0+ s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " yajl_gen_map_close(hand);\n"and again.
Spotted because the diff of the generated code across the entire series was as below, the spurious change is pretty obvious in the third hunk.
I should've stolen your handy script earlier!
Quoted 8 lines
Quoted 6 lines
~ianc/xen-build-tools/libxl-idl-* if you still want to...
Quoted 1 line
This one should be correct.
Agreed, you can have that Ack back ;-)
Do you want me to resend the whole series with all Acks folded in?
No need, I've applied. Please check I got the right versions of everything!
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
On Wed, Apr 16, 2014 at 05:30:21PM +0100, Ian Campbell wrote:
[...]
Quoted 3 lines
No need, I've applied. Please check I got the right versions of everything!
I've checked. You checked in the correct version. Thanks.
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
In reply to Ian CampbellIan Campbell writes ("Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union"):
Quoted 4 lines · Wei Liu
Quoted 1 line
I should've stolen your handy script earlier!
~ianc/xen-build-tools/libxl-idl-* if you still want to...
Can we check this into the tree ?
Ian.
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Quoted 7 lines · Ian Jackson
Ian Campbell writes ("Re: [PATCH V2 3/4]
libxl/gentypes.py: generate empty map for None field in keyed-union"):Quoted 4 lines · Wei Liu
Quoted 1 line
I should've stolen your handy script earlier!
~ianc/xen-build-tools/libxl-idl-* if you still want to...
Can we check this into the tree ?
They are pretty dumb, but we can if you like. Here they are for prejudgement...
----- libxl-idl-save-baseline ------
#!/bin/bash
set -e
for i in tools/libxl/_libxl_types.c tools/libxl/_libxl_types.h tools/libxl/_libxl_types_json.h \
tools/libxl/_libxl_types_internal.c tools/libxl/_libxl_types_internal.h tools/libxl/_libxl_types_internal_json.h \
tools/python/xen/lowlevel/xl/_pyxl_types.h tools/python/xen/lowlevel/xl/_pyxl_types.c \
tools/ocaml/libs/xl/_libxl_types.inc tools/ocaml/libs/xl/_libxl_types.mli.in tools/ocaml/libs/xl/_libxl_types.ml.in \
tools/libxl/testidl.c \tools/libxl/_libxl_save_msgs_callout.c tools/libxl/_libxl_save_msgs_callout.h tools/libxl/_libxl_save_msgs_helper.c tools/libxl/_libxl_save_msgs_helper.h ; do
bak=$(echo $i | sed -e 's,[^/]*/\(_libxl\|_pyxl\|testidl\),&_BACKUP,g')
if [ -e "$i" ] ; then
cp -v "$i" "$bak"
else
rm -f "$bak"
echo touch "$bak"
touch "$bak"
fidone
----- libxl-idl-compare-baseline -----
#!/bin/bash
set -e
for i in tools/libxl/_libxl_types.c tools/libxl/_libxl_types.h tools/libxl/_libxl_types_json.h \
tools/libxl/_libxl_types_internal.c tools/libxl/_libxl_types_internal.h tools/libxl/_libxl_types_internal_json.h \
tools/python/xen/lowlevel/xl/_pyxl_types.h tools/python/xen/lowlevel/xl/_pyxl_types.c \
tools/ocaml/libs/xl/_libxl_types.inc tools/ocaml/libs/xl/_libxl_types.mli.in tools/ocaml/libs/xl/_libxl_types.ml.in \
tools/libxl/testidl.c \tools/libxl/_libxl_save_msgs_callout.c tools/libxl/_libxl_save_msgs_callout.h tools/libxl/_libxl_save_msgs_helper.c tools/libxl/_libxl_save_msgs_helper.h ; do
bak=$(echo $i | sed -e 's,[^/]*/\(_libxl\|_pyxl\|testidl\),&_BACKUP,g')
diff -puN $bak $i || truedone
Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union
Ian Campbell writes ("Re: [PATCH V2 3/4] libxl/gentypes.py: generate empty map for None field in keyed-union"):
Quoted 2 lines
They are pretty dumb, but we can if you like. Here they are for prejudgement...
Quite ugly, I agree. But I think it's better to have them in-tree where they can be shared and improved, than floating about on some NFS filer in the Citrix Cambridge office.
TBH it might be possible to do in the Makefile but I think that's a task for another day.
Ian.
PATCH v2 4/4 libxl_types.idl: replace empty Struct with None for libxl_event
In reply to Wei LiuNow we generate empty map for None, the empty Struct trick is not necessary anymore.
--- tools/libxl/libxl_types.idl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_types.idl +1 -1
@@ -596,5 +596,5 @@ libxl_event = Struct("event",[ ("operation_complete", Struct(None, [ ("rc", integer), ])), - ("domain_create_console_available", Struct(None, [])), + ("domain_create_console_available", None), ]))])
Signature · 1 line
1.7.10.4
Re: [PATCH V2 4/4] libxl_types.idl: replace empty Struct with None for libxl_event
Quoted 4 lines · Wei Liu
Now we generate empty map for None, the empty Struct trick is not necessary anymore.
Signed-off-by Wei Liu <[email protected]>
But you've missed
("domain_death", Struct(None, [])),in the same struct.
Arguably this is an API change -- but since the struct was
struct {
} domain_create_console_available;I don't think it is material enough to warrant a #define etc.
Re: [PATCH V2 4/4] libxl_types.idl: replace empty Struct with None for libxl_event
Quoted 11 lines · Ian Campbell
Quoted 4 lines · Wei Liu
Now we generate empty map for None, the empty Struct trick is not necessary anymore.
Signed-off-by Wei Liu <[email protected]>Acked-by Ian Campbell <[email protected]>But you've missed
("domain_death", Struct(None, [])),in the same struct.
Oops. My fault.
Quoted 6 lines
Arguably this is an API change -- but since the struct was
struct { } domain_create_console_available;I don't think it is material enough to warrant a #define etc.
---8<---
Quoted 1 line
From
2cfa7a3623847a431c0bf662a19e9eb2d9c79254Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Thu, 10 Apr 2014 16:20:22 +0100
Subject: [PATCH] libxl_types.idl: replace empty Struct with None for
libxl_event
Now we generate empty map for None, the empty Struct trick is not necessary anymore.
--- tools/libxl/libxl_types.idl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_types.idl +2 -2
@@ -588,7 +588,7 @@ libxl_event = Struct("event",[ [("domain_shutdown", Struct(None, [ ("shutdown_reason", uint8), ])), - ("domain_death", Struct(None, [])), + ("domain_death", None), ("disk_eject", Struct(None, [ ("vdev", string), ("disk", libxl_device_disk),
@@ -596,5 +596,5 @@ libxl_event = Struct("event",[ ("operation_complete", Struct(None, [ ("rc", integer), ])), - ("domain_create_console_available", Struct(None, [])), + ("domain_create_console_available", None), ]))])
Signature · 1 line
1.7.10.4
Re: [PATCH V2 4/4] libxl_types.idl: replace empty Struct with None for libxl_event
Quoted 7 lines · Wei Liu
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Wei Liu
Now we generate empty map for None, the empty Struct trick is not necessary anymore.
Signed-off-by Wei Liu <[email protected]>
Quoted 7 lines
Quoted 5 lines
Acked-by Ian Campbell <[email protected]>But you've missed
("domain_death", Struct(None, [])),in the same struct.
Oops. My fault.
No worries, you can keep the ack on the new version too.