[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/23] qapi-commands: Wrap argument visit in visit_st
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 08/23] qapi-commands: Wrap argument visit in visit_start_struct |
Date: |
Thu, 12 May 2016 09:58:55 +0200 |
From: Eric Blake <address@hidden>
The qmp-input visitor was allowing callers to play rather fast
and loose: when visiting a QDict, you could grab members of the
root dictionary without first pushing into the dict; among the
culprit callers was the generated marshal code on the 'arguments'
dictionary of a QMP command. But we are about to tighten the
input visitor, at which point the generated marshal code MUST
follow the same paradigms as everyone else, of pushing into the
struct before grabbing its keys.
Generated code grows as follows:
|@@ -515,7 +641,12 @@ void qmp_marshal_blockdev_backup(QDict *
| BlockdevBackup arg = {0};
|
| v = qmp_input_get_visitor(qiv);
|+ visit_start_struct(v, NULL, NULL, 0, &err);
|+ if (err) {
|+ goto out;
|+ }
| visit_type_BlockdevBackup_members(v, &arg, &err);
|+ visit_end_struct(v, err ? NULL : &err);
| if (err) {
| goto out;
| }
|@@ -527,7 +715,9 @@ out:
| qmp_input_visitor_cleanup(qiv);
| qdv = qapi_dealloc_visitor_new();
| v = qapi_dealloc_get_visitor(qdv);
|+ visit_start_struct(v, NULL, NULL, 0, NULL);
| visit_type_BlockdevBackup_members(v, &arg, NULL);
|+ visit_end_struct(v, NULL);
| qapi_dealloc_visitor_cleanup(qdv);
| }
The use of 'err ? NULL : &err' is temporary; a later patch will
clean that up when it splits visit_end_struct().
Prior to this patch, the fact that there was no final
visit_end_struct() meant that even though we are using a strict
input visit, the marshalling code was not detecting excess input
at the top level (only in nested levels). Fortunately, we have
code in monitor.c:qmp_check_client_args() that also checks for
no excess arguments at the top level. But as the generated code
is more compact than the manual check, a later patch will clean
up monitor.c to drop the redundancy added here.
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
docs/qapi-code-gen.txt | 7 +++++++
scripts/qapi-commands.py | 7 +++++++
2 files changed, 14 insertions(+)
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 4a917f9..b4ae1be 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -1002,7 +1002,12 @@ Example:
UserDefOneList *arg1 = NULL;
v = qmp_input_get_visitor(qiv);
+ visit_start_struct(v, NULL, NULL, 0, &err);
+ if (err) {
+ goto out;
+ }
visit_type_UserDefOneList(v, "arg1", &arg1, &err);
+ visit_end_struct(v, err ? NULL : &err);
if (err) {
goto out;
}
@@ -1019,7 +1024,9 @@ Example:
qmp_input_visitor_cleanup(qiv);
qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv);
+ visit_start_struct(v, NULL, NULL, 0, NULL);
visit_type_UserDefOneList(v, "arg1", &arg1, NULL);
+ visit_end_struct(v, NULL);
qapi_dealloc_visitor_cleanup(qdv);
}
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 6261e44..04549fa 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -121,7 +121,12 @@ def gen_marshal(name, arg_type, ret_type):
%(c_name)s arg = {0};
v = qmp_input_get_visitor(qiv);
+ visit_start_struct(v, NULL, NULL, 0, &err);
+ if (err) {
+ goto out;
+ }
visit_type_%(c_name)s_members(v, &arg, &err);
+ visit_end_struct(v, err ? NULL : &err);
if (err) {
goto out;
}
@@ -150,7 +155,9 @@ out:
qmp_input_visitor_cleanup(qiv);
qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv);
+ visit_start_struct(v, NULL, NULL, 0, NULL);
visit_type_%(c_name)s_members(v, &arg, NULL);
+ visit_end_struct(v, NULL);
qapi_dealloc_visitor_cleanup(qdv);
''',
c_name=arg_type.c_name())
--
2.5.5
- [Qemu-devel] [PULL 21/23] qapi: Fix string input visitor handling of invalid list, (continued)
- [Qemu-devel] [PULL 21/23] qapi: Fix string input visitor handling of invalid list, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 20/23] tests/string-input-visitor: Add negative integer tests, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 14/23] qapi: Add visit_type_null() visitor, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 17/23] qmp: Don't reuse qmp visitor after grabbing output, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 13/23] tests: Add check-qnull, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 23/23] qapi: Change visit_type_FOO() to no longer return partial objects, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 04/23] qmp-input: Clean up stack handling, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 11/23] qmp-input: Refactor when list is advanced, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 16/23] spapr_drc: Expose 'null' in qom-get when there is no fdt, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 22/23] qapi: Simplify semantics of visit_next_list(), Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 08/23] qapi-commands: Wrap argument visit in visit_start_struct,
Markus Armbruster <=
- [Qemu-devel] [PULL 15/23] qmp: Support explicit null during visits, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 12/23] qapi: Document visitor interfaces, add assertions, Markus Armbruster, 2016/05/12
- [Qemu-devel] [PULL 19/23] qapi: Split visit_end_struct() into pieces, Markus Armbruster, 2016/05/12
- Re: [Qemu-devel] [PULL 00/23] QAPI patches for 2016-05-12, Peter Maydell, 2016/05/12