From: Luiz Capitulino <lcapitulino@redhat.com>
To: peter.maydell@linaro.org
Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws
Subject: [Qemu-devel] [PULL 01/20] qapi: Update qapi-code-gen.txt example to match current code
Date: Fri, 16 May 2014 11:30:16 -0400 [thread overview]
Message-ID: <1400254235-9435-2-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1400254235-9435-1-git-send-email-lcapitulino@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
docs/qapi-code-gen.txt | 146 ++++++++++++++++++++++++++++++-------------------
1 file changed, 90 insertions(+), 56 deletions(-)
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt
index 26312d8..b915c4d 100644
--- a/docs/qapi-code-gen.txt
+++ b/docs/qapi-code-gen.txt
@@ -258,11 +258,23 @@ Example:
mdroth@illuin:~/w/qemu2.git$ python scripts/qapi-types.py \
--output-dir="qapi-generated" --prefix="example-" --input-file=example-schema.json
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-types.c
- /* AUTOMATICALLY GENERATED, DO NOT MODIFY */
+[Uninteresting stuff omitted...]
+
+ void qapi_free_UserDefOneList(UserDefOneList * obj)
+ {
+ QapiDeallocVisitor *md;
+ Visitor *v;
+
+ if (!obj) {
+ return;
+ }
+
+ md = qapi_dealloc_visitor_new();
+ v = qapi_dealloc_get_visitor(md);
+ visit_type_UserDefOneList(v, &obj, NULL, NULL);
+ qapi_dealloc_visitor_cleanup(md);
+ }
- #include "qapi/qapi-dealloc-visitor.h"
- #include "example-qapi-types.h"
- #include "example-qapi-visit.h"
void qapi_free_UserDefOne(UserDefOne * obj)
{
@@ -280,31 +292,37 @@ Example:
}
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-types.h
- /* AUTOMATICALLY GENERATED, DO NOT MODIFY */
- #ifndef QAPI_GENERATED_EXAMPLE_QAPI_TYPES
- #define QAPI_GENERATED_EXAMPLE_QAPI_TYPES
+[Uninteresting stuff omitted...]
+
+ #ifndef EXAMPLE_QAPI_TYPES_H
+ #define EXAMPLE_QAPI_TYPES_H
- #include "qapi/qapi-types-core.h"
+[Builtin types omitted...]
typedef struct UserDefOne UserDefOne;
typedef struct UserDefOneList
{
- UserDefOne *value;
+ union {
+ UserDefOne *value;
+ uint64_t padding;
+ };
struct UserDefOneList *next;
} UserDefOneList;
+[Functions on builtin types omitted...]
+
struct UserDefOne
{
int64_t integer;
char * string;
};
+ void qapi_free_UserDefOneList(UserDefOneList * obj);
void qapi_free_UserDefOne(UserDefOne * obj);
#endif
-
=== scripts/qapi-visit.py ===
Used to generate the visitor functions used to walk through and convert
@@ -328,39 +346,63 @@ Example:
mdroth@illuin:~/w/qemu2.git$ python scripts/qapi-visit.py \
--output-dir="qapi-generated" --prefix="example-" --input-file=example-schema.json
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-visit.c
- /* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
+[Uninteresting stuff omitted...]
- #include "example-qapi-visit.h"
+ static void visit_type_UserDefOne_fields(Visitor *m, UserDefOne ** obj, Error **errp)
+ {
+ Error *err = NULL;
+ visit_type_int(m, &(*obj)->integer, "integer", &err);
+ visit_type_str(m, &(*obj)->string, "string", &err);
+
+ error_propagate(errp, err);
+ }
void visit_type_UserDefOne(Visitor *m, UserDefOne ** obj, const char *name, Error **errp)
{
- visit_start_struct(m, (void **)obj, "UserDefOne", name, sizeof(UserDefOne), errp);
- visit_type_int(m, (obj && *obj) ? &(*obj)->integer : NULL, "integer", errp);
- visit_type_str(m, (obj && *obj) ? &(*obj)->string : NULL, "string", errp);
- visit_end_struct(m, errp);
+ if (!error_is_set(errp)) {
+ Error *err = NULL;
+ visit_start_struct(m, (void **)obj, "UserDefOne", name, sizeof(UserDefOne), &err);
+ if (!err) {
+ if (*obj) {
+ visit_type_UserDefOne_fields(m, obj, &err);
+ error_propagate(errp, err);
+ err = NULL;
+ }
+ /* Always call end_struct if start_struct succeeded. */
+ visit_end_struct(m, &err);
+ }
+ error_propagate(errp, err);
+ }
}
void visit_type_UserDefOneList(Visitor *m, UserDefOneList ** obj, const char *name, Error **errp)
{
GenericList *i, **prev = (GenericList **)obj;
-
- visit_start_list(m, name, errp);
-
- for (; (i = visit_next_list(m, prev, errp)) != NULL; prev = &i) {
- UserDefOneList *native_i = (UserDefOneList *)i;
- visit_type_UserDefOne(m, &native_i->value, NULL, errp);
+ Error *err = NULL;
+
+ if (!error_is_set(errp)) {
+ visit_start_list(m, name, &err);
+ if (!err) {
+ for (; (i = visit_next_list(m, prev, &err)) != NULL; prev = &i) {
+ UserDefOneList *native_i = (UserDefOneList *)i;
+ visit_type_UserDefOne(m, &native_i->value, NULL, &err);
+ }
+ error_propagate(errp, err);
+ err = NULL;
+
+ /* Always call end_list if start_list succeeded. */
+ visit_end_list(m, &err);
+ }
+ error_propagate(errp, err);
}
-
- visit_end_list(m, errp);
}
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qapi-visit.h
- /* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
+[Uninteresting stuff omitted...]
- #ifndef QAPI_GENERATED_EXAMPLE_QAPI_VISIT
- #define QAPI_GENERATED_EXAMPLE_QAPI_VISIT
+ #ifndef EXAMPLE_QAPI_VISIT_H
+ #define EXAMPLE_QAPI_VISIT_H
- #include "qapi/qapi-visit-core.h"
- #include "example-qapi-types.h"
+[Visitors for builtin types omitted...]
void visit_type_UserDefOne(Visitor *m, UserDefOne ** obj, const char *name, Error **errp);
void visit_type_UserDefOneList(Visitor *m, UserDefOneList ** obj, const char *name, Error **errp);
@@ -368,9 +410,6 @@ Example:
#endif
mdroth@illuin:~/w/qemu2.git$
-(The actual structure of the visit_type_* functions is a bit more complex
-in order to propagate errors correctly and avoid leaking memory).
-
=== scripts/qapi-commands.py ===
Used to generate the marshaling/dispatch functions for the commands defined
@@ -391,18 +430,8 @@ $(prefix)qmp-commands.h: Function prototypes for the QMP commands
Example:
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qmp-marshal.c
- /* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
-
- #include "qemu-objects.h"
- #include "qapi/qmp-core.h"
- #include "qapi/qapi-visit-core.h"
- #include "qapi/qmp-output-visitor.h"
- #include "qapi/qmp-input-visitor.h"
- #include "qapi/qapi-dealloc-visitor.h"
- #include "example-qapi-types.h"
- #include "example-qapi-visit.h"
+[Uninteresting stuff omitted...]
- #include "example-qmp-commands.h"
static void qmp_marshal_output_my_command(UserDefOne * ret_in, QObject **ret_out, Error **errp)
{
QapiDeallocVisitor *md = qapi_dealloc_visitor_new();
@@ -411,15 +440,16 @@ Example:
v = qmp_output_get_visitor(mo);
visit_type_UserDefOne(v, &ret_in, "unused", errp);
+ if (!error_is_set(errp)) {
+ *ret_out = qmp_output_get_qobject(mo);
+ }
+ qmp_output_visitor_cleanup(mo);
v = qapi_dealloc_get_visitor(md);
- visit_type_UserDefOne(v, &ret_in, "unused", errp);
+ visit_type_UserDefOne(v, &ret_in, "unused", NULL);
qapi_dealloc_visitor_cleanup(md);
-
-
- *ret_out = qmp_output_get_qobject(mo);
}
- static void qmp_marshal_input_my_command(QmpState *qmp__sess, QDict *args, QObject **ret, Error **errp)
+ static void qmp_marshal_input_my_command(QDict *args, QObject **ret, Error **errp)
{
UserDefOne * retval = NULL;
QmpInputVisitor *mi;
@@ -427,38 +457,42 @@ Example:
Visitor *v;
UserDefOne * arg1 = NULL;
- mi = qmp_input_visitor_new(QOBJECT(args));
+ mi = qmp_input_visitor_new_strict(QOBJECT(args));
v = qmp_input_get_visitor(mi);
visit_type_UserDefOne(v, &arg1, "arg1", errp);
+ qmp_input_visitor_cleanup(mi);
if (error_is_set(errp)) {
goto out;
}
retval = qmp_my_command(arg1, errp);
- qmp_marshal_output_my_command(retval, ret, errp);
+ if (!error_is_set(errp)) {
+ qmp_marshal_output_my_command(retval, ret, errp);
+ }
out:
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
- visit_type_UserDefOne(v, &arg1, "arg1", errp);
+ visit_type_UserDefOne(v, &arg1, "arg1", NULL);
qapi_dealloc_visitor_cleanup(md);
return;
}
static void qmp_init_marshal(void)
{
- qmp_register_command("my-command", qmp_marshal_input_my_command);
+ qmp_register_command("my-command", qmp_marshal_input_my_command, QCO_NO_OPTIONS);
}
qapi_init(qmp_init_marshal);
mdroth@illuin:~/w/qemu2.git$ cat qapi-generated/example-qmp-commands.h
- /* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
+[Uninteresting stuff omitted...]
- #ifndef QAPI_GENERATED_EXAMPLE_QMP_COMMANDS
- #define QAPI_GENERATED_EXAMPLE_QMP_COMMANDS
+ #ifndef EXAMPLE_QMP_COMMANDS_H
+ #define EXAMPLE_QMP_COMMANDS_H
#include "example-qapi-types.h"
- #include "error.h"
+ #include "qapi/qmp/qdict.h"
+ #include "qapi/error.h"
UserDefOne * qmp_my_command(UserDefOne * arg1, Error **errp);
--
1.9.0
next prev parent reply other threads:[~2014-05-16 15:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 15:30 [Qemu-devel] [PULL 00/20] QMP queue Luiz Capitulino
2014-05-16 15:30 ` Luiz Capitulino [this message]
2014-05-16 15:30 ` [Qemu-devel] [PULL 02/20] qapi: Normalize marshalling's visitor initialization and cleanup Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 03/20] qapi: Remove unused Visitor callbacks start_handle(), end_handle() Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 04/20] qapi: Replace start_optional()/end_optional() by optional() Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 05/20] qapi-visit.py: Clean up confusing push_indent() / pop_indent() use Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 06/20] qapi: Clean up shadowing of parameters and locals in inner scopes Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 07/20] qapi-visit.py: Clean up a sloppy use of field prefix Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 08/20] qapi: Un-inline visit of implicit struct Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 09/20] hmp: Call visit_end_struct() after visit_start_struct() succeeds Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 10/20] hw: Don't call visit_end_struct() after visit_start_struct() fails Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 11/20] tests: " Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 12/20] qapi: Replace uncommon use of the error API by the common one Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 13/20] qapi: Show qapi-commands.py invocation in qapi-code-gen.txt Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 14/20] monitor: Convert sendkey to use command_completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 15/20] monitor: Add chardev-remove command completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 16/20] monitor: Add chardev-add backend argument completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 17/20] monitor: Add set_link arguments completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 18/20] monitor: Add netdev_add type argument completion Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 19/20] monitor: Add netdev_del id " Luiz Capitulino
2014-05-16 15:30 ` [Qemu-devel] [PULL 20/20] qapi: skip redundant includes Luiz Capitulino
2014-05-19 15:09 ` [Qemu-devel] [PULL 00/20] QMP queue Peter Maydell
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=1400254235-9435-2-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=peter.maydell@linaro.org \
--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).