From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, armbru@redhat.com,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH v8 14.5/35] qapi: Update docs to match recent generator changes
Date: Tue, 5 Jan 2016 17:01:29 -0700 [thread overview]
Message-ID: <1452038489-8611-1-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1450717720-9627-15-git-send-email-eblake@redhat.com>
Several commits have been changing the generator, but not updating
the docs to match (an obvious one is commit 9f08c8ec that made
list types lazy, and thereby dropped UserDefOneList). Rework the
example to show slightly more output (we don't want to show too
much; that's what the testsuite is for), and regenerate the output
to match recent changes, including the previous patch's reordering
of parameter positions.
Reported-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
v9: new patch
---
docs/qapi-code-gen.txt | 103 ++++++++++++++++++++++++++++---------------------
1 file changed, 59 insertions(+), 44 deletions(-)
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 128f074..f9b1d0c 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -1,7 +1,7 @@
= How to use the QAPI code generator =
Copyright IBM Corp. 2011
-Copyright (C) 2012-2015 Red Hat, Inc.
+Copyright (C) 2012-2016 Red Hat, Inc.
This work is licensed under the terms of the GNU GPL, version 2 or
later. See the COPYING file in the top-level directory.
@@ -721,29 +721,34 @@ the names of built-in types. Clients should examine member
== Code generation ==
-Schemas are fed into four scripts to generate all the code/files that,
+Schemas are fed into five scripts to generate all the code/files that,
paired with the core QAPI libraries, comprise everything required to
take JSON commands read in by a Client JSON Protocol server, unmarshal
the arguments into the underlying C types, call into the corresponding
-C function, and map the response back to a Client JSON Protocol
-response to be returned to the user.
+C function, map the response back to a Client JSON Protocol response
+to be returned to the user, and introspect the commands.
-As an example, we'll use the following schema, which describes a single
-complex user-defined type (which will produce a C struct, along with a list
-node structure that can be used to chain together a list of such types in
-case we want to accept/return a list of this type with a command), and a
-command which takes that type as a parameter and returns the same type:
+As an example, we'll use the following schema, which describes a
+single complex user-defined type, along with command which takes a
+list of that type as a parameter. The user is responsible for writing
+the implementation of qmp_my_command(); everything else is produced by
+the generator.
$ cat example-schema.json
{ 'struct': 'UserDefOne',
- 'data': { 'integer': 'int', 'string': 'str' } }
+ 'data': { 'integer': 'int', '*string': 'str' } }
{ 'command': 'my-command',
- 'data': {'arg1': 'UserDefOne'},
+ 'data': { 'arg1': ['UserDefOne'] },
'returns': 'UserDefOne' }
{ 'event': 'MY_EVENT' }
+For a more thorough look at generated code, the testsuite includes
+tests/qapi-schema/qapi-schema-tests.json that covers more examples of
+what the generator will accept, and compiles the resulting C code as
+part of 'make check-unit'.
+
=== scripts/qapi-types.py ===
Used to generate the C types defined by a schema. The following files are
@@ -776,7 +781,7 @@ Example:
qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv);
- visit_type_UserDefOne(v, &obj, NULL, NULL);
+ visit_type_UserDefOne(v, NULL, &obj, NULL);
qapi_dealloc_visitor_cleanup(qdv);
}
@@ -791,7 +796,7 @@ Example:
qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv);
- visit_type_UserDefOneList(v, &obj, NULL, NULL);
+ visit_type_UserDefOneList(v, NULL, &obj, NULL);
qapi_dealloc_visitor_cleanup(qdv);
}
$ cat qapi-generated/example-qapi-types.h
@@ -808,6 +813,7 @@ Example:
struct UserDefOne {
int64_t integer;
+ bool has_string;
char *string;
};
@@ -854,34 +860,42 @@ Example:
{
Error *err = NULL;
- visit_type_int(v, &(*obj)->integer, "integer", &err);
+ visit_type_int(v, "integer", &(*obj)->integer, &err);
if (err) {
goto out;
}
- visit_type_str(v, &(*obj)->string, "string", &err);
- if (err) {
- goto out;
- }
-
- out:
- error_propagate(errp, err);
- }
-
- void visit_type_UserDefOne(Visitor *v, UserDefOne **obj, const char *name, Error **errp)
- {
- Error *err = NULL;
-
- visit_start_struct(v, (void **)obj, "UserDefOne", name, sizeof(UserDefOne), &err);
- if (!err) {
- if (*obj) {
- visit_type_UserDefOne_fields(v, obj, errp);
+ if (visit_optional(v, "string", &(*obj)->has_string)) {
+ visit_type_str(v, "string", &(*obj)->string, &err);
+ if (err) {
+ goto out;
}
- visit_end_struct(v, &err);
}
+
+ out:
+ error_propagate(errp, err);
+ }
+
+ void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp)
+ {
+ Error *err = NULL;
+
+ visit_start_struct(v, name, (void **)obj, "UserDefOne", sizeof(UserDefOne), &err);
+ if (err) {
+ goto out;
+ }
+ if (!*obj) {
+ goto out_obj;
+ }
+ visit_type_UserDefOne_fields(v, obj, &err);
+ out_obj:
+ error_propagate(errp, err);
+ err = NULL;
+ visit_end_struct(v, &err);
+ out:
error_propagate(errp, err);
}
- void visit_type_UserDefOneList(Visitor *v, UserDefOneList **obj, const char *name, Error **errp)
+ void visit_type_UserDefOneList(Visitor *v, const char *name, UserDefOneList **obj, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
@@ -895,7 +909,7 @@ Example:
!err && (i = visit_next_list(v, prev, &err)) != NULL;
prev = &i) {
UserDefOneList *native_i = (UserDefOneList *)i;
- visit_type_UserDefOne(v, &native_i->value, NULL, &err);
+ visit_type_UserDefOne(v, NULL, &native_i->value, &err);
}
error_propagate(errp, err);
@@ -912,8 +926,8 @@ Example:
[Visitors for built-in types omitted...]
- void visit_type_UserDefOne(Visitor *v, UserDefOne **obj, const char *name, Error **errp);
- void visit_type_UserDefOneList(Visitor *v, UserDefOneList **obj, const char *name, Error **errp);
+ void visit_type_UserDefOne(Visitor *v, const char *name, UserDefOne **obj, Error **errp);
+ void visit_type_UserDefOneList(Visitor *v, const char *name, UserDefOneList **obj, Error **errp);
#endif
@@ -949,7 +963,7 @@ Example:
Visitor *v;
v = qmp_output_get_visitor(qov);
- visit_type_UserDefOne(v, &ret_in, "unused", &err);
+ visit_type_UserDefOne(v, "unused", &ret_in, &err);
if (err) {
goto out;
}
@@ -960,7 +974,7 @@ Example:
qmp_output_visitor_cleanup(qov);
qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv);
- visit_type_UserDefOne(v, &ret_in, "unused", NULL);
+ visit_type_UserDefOne(v, "unused", &ret_in, NULL);
qapi_dealloc_visitor_cleanup(qdv);
}
@@ -971,10 +985,10 @@ Example:
QmpInputVisitor *qiv = qmp_input_visitor_new_strict(QOBJECT(args));
QapiDeallocVisitor *qdv;
Visitor *v;
- UserDefOne *arg1 = NULL;
+ UserDefOneList *arg1 = NULL;
v = qmp_input_get_visitor(qiv);
- visit_type_UserDefOne(v, &arg1, "arg1", &err);
+ visit_type_UserDefOne(v, "arg1", &arg1, &err);
if (err) {
goto out;
}
@@ -991,7 +1005,7 @@ Example:
qmp_input_visitor_cleanup(qiv);
qdv = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(qdv);
- visit_type_UserDefOne(v, &arg1, "arg1", NULL);
+ visit_type_UserDefOne(v, "arg1", &arg1, NULL);
qapi_dealloc_visitor_cleanup(qdv);
}
@@ -1011,7 +1025,7 @@ Example:
#include "qapi/qmp/qdict.h"
#include "qapi/error.h"
- UserDefOne *qmp_my_command(UserDefOne *arg1, Error **errp);
+ UserDefOne *qmp_my_command(UserDefOneList *arg1, Error **errp);
#endif
@@ -1095,8 +1109,9 @@ Example:
"{\"arg-type\": \"0\", \"meta-type\": \"event\", \"name\": \"MY_EVENT\"}, "
"{\"arg-type\": \"1\", \"meta-type\": \"command\", \"name\": \"my-command\", \"ret-type\": \"2\"}, "
"{\"members\": [], \"meta-type\": \"object\", \"name\": \"0\"}, "
- "{\"members\": [{\"name\": \"arg1\", \"type\": \"2\"}], \"meta-type\": \"object\", \"name\": \"1\"}, "
- "{\"members\": [{\"name\": \"integer\", \"type\": \"int\"}, {\"name\": \"string\", \"type\": \"str\"}], \"meta-type\": \"object\", \"name\": \"2\"}, "
+ "{\"members\": [{\"name\": \"arg1\", \"type\": \"[2]\"}], \"meta-type\": \"object\", \"name\": \"1\"}, "
+ "{\"members\": [{\"name\": \"integer\", \"type\": \"int\"}, {\"default\": null, \"name\": \"string\", \"type\": \"str\"}], \"meta-type\": \"object\", \"name\": \"2\"}, "
+ "{\"element-type\": \"2\", \"meta-type\": \"array\", \"name\": \"[2]\"}, "
"{\"json-type\": \"int\", \"meta-type\": \"builtin\", \"name\": \"int\"}, "
"{\"json-type\": \"string\", \"meta-type\": \"builtin\", \"name\": \"str\"}]";
$ cat qapi-generated/example-qmp-introspect.h
--
2.4.3
next prev parent reply other threads:[~2016-01-06 0:01 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-21 17:08 [Qemu-devel] [PATCH v8 00/35] qapi visitor cleanups (post-introspection cleanups subset E) Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 01/35] qobject: Document more shortcomings in our number handling Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 02/35] qapi: Avoid use of misnamed DO_UPCAST() Eric Blake
2016-01-05 14:08 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 03/35] qapi: Drop dead dealloc visitor variable Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 04/35] hmp: Improve use of qapi visitor Eric Blake
2016-01-05 14:06 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 05/35] vl: " Eric Blake
2016-01-05 14:06 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 06/35] balloon: " Eric Blake
2016-01-05 14:08 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 07/35] qapi: Improve generated event " Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2016-01-05 15:21 ` Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 08/35] qapi: Track all failures between visit_start/stop Eric Blake
2016-01-05 14:06 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 09/35] qapi: Prefer type_int64 over type_int in visitors Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 10/35] qapi: Make all visitors supply uint64 callbacks Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 11/35] qapi: Consolidate visitor small integer callbacks Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 12/35] qapi: Don't cast Enum* to int* Eric Blake
2016-01-05 14:06 ` Marc-André Lureau
2016-01-05 15:23 ` Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 13/35] qom: Use typedef for Visitor Eric Blake
2016-01-05 14:07 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 14/35] qapi: Swap visit_* arguments for consistent 'name' placement Eric Blake
2016-01-05 14:06 ` Marc-André Lureau
2016-01-05 15:32 ` Eric Blake
2016-01-05 22:47 ` Eric Blake
2016-01-06 0:01 ` Eric Blake [this message]
2016-01-06 0:16 ` [Qemu-devel] [PATCH v8 14.5/35] qapi: Update docs to match recent generator changes Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 15/35] qom: Swap 'name' next to visitor in ObjectPropertyAccessor Eric Blake
2015-12-23 16:30 ` Eric Blake
2016-01-05 14:06 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 16/35] qapi: Swap 'name' in visit_* callbacks to match public API Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 17/35] qapi: Drop unused 'kind' for struct/enum visit Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2016-01-06 0:26 ` Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 18/35] qapi: Drop unused error argument for list and implicit struct Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2016-01-05 15:58 ` Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 19/35] qmp: Fix reference-counting of qnull on empty output visit Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2016-01-06 17:42 ` Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 20/35] qmp: Don't abuse stack to track qmp-output root Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 21/35] qapi: Document visitor interfaces, add assertions Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 22/35] qapi: Add visit_type_null() visitor Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2016-01-05 16:08 ` Eric Blake
2016-01-06 22:15 ` [Qemu-devel] [PATCH v8 22.5/35] qmp: Support explicit null on input visit Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 23/35] qmp: Tighten output visitor rules Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2016-01-06 22:18 ` Eric Blake
2016-01-06 22:40 ` [Qemu-devel] [PATCH v8 23.5/35] qmp: Tighten output visitor rules, part 2 Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 24/35] spapr_drc: Expose 'null' in qom-get when there is no fdt Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 25/35] qapi: Simplify excess input reporting in input visitors Eric Blake
2016-01-05 14:05 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 26/35] qapi: Add type.is_empty() helper Eric Blake
2016-01-05 14:04 ` Marc-André Lureau
2016-01-05 16:10 ` Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 27/35] qapi: Fix command with named empty argument type Eric Blake
2016-01-05 14:04 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 28/35] qapi: Eliminate empty visit_type_FOO_fields Eric Blake
2016-01-05 14:04 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 29/35] qapi: Canonicalize missing object to :empty Eric Blake
2015-12-23 17:54 ` [Qemu-devel] [PATCH v8 29.5/35] fixup! " Eric Blake
2016-01-05 14:03 ` [Qemu-devel] [PATCH v8 29/35] " Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 30/35] qapi-visit: Unify struct and union visit Eric Blake
2016-01-05 14:03 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 31/35] qapi: Rework deallocation of partial struct Eric Blake
2016-01-05 13:58 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 32/35] qapi: Split visit_end_struct() into pieces Eric Blake
2016-01-05 17:22 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 33/35] qapi: Simplify semantics of visit_next_list() Eric Blake
2016-01-05 17:22 ` Marc-André Lureau
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 34/35] qapi: Change visit_type_FOO() to no longer return partial objects Eric Blake
2016-01-05 17:22 ` Marc-André Lureau
2016-01-05 18:02 ` Eric Blake
2016-01-07 23:02 ` [Qemu-devel] [PATCH v8 34/35] fixup! " Eric Blake
2015-12-21 17:08 ` [Qemu-devel] [PATCH v8 35/35] RFC: qapi: Adjust layout of FooList types Eric Blake
2016-01-05 17:22 ` Marc-André Lureau
2016-01-08 16:45 ` [Qemu-devel] [PATCH] qapi: Update docs to match recent generated changes, part 2 Eric Blake
2016-01-19 9:10 ` [Qemu-devel] [PATCH v8 00/35] qapi visitor cleanups (post-introspection cleanups subset E) Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1452038489-8611-1-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).