[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 27/46] qapi: Simplify visits of optional fields
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v5 27/46] qapi: Simplify visits of optional fields |
Date: |
Mon, 21 Sep 2015 15:57:43 -0600 |
None of the visitor callbacks would set an error when testing
if an optional field was present; make this part of the interface
contract by eliminating the errp argument. Then, for less code,
reflect the determined boolean value back to the caller instead
of making the caller read the boolean after the fact.
The resulting generated code has a nice diff:
|- visit_optional(v, &has_fdset_id, "fdset-id", &err);
|- if (err) {
|- goto out;
|- }
|- if (has_fdset_id) {
|+ if (visit_optional(v, &has_fdset_id, "fdset-id")) {
| visit_type_int(v, &fdset_id, "fdset-id", &err);
| if (err) {
| goto out;
| }
| }
Signed-off-by: Eric Blake <address@hidden>
---
include/qapi/visitor-impl.h | 3 +--
include/qapi/visitor.h | 5 ++---
qapi/opts-visitor.c | 2 +-
qapi/qapi-visit-core.c | 6 +++---
qapi/qmp-input-visitor.c | 3 +--
qapi/string-input-visitor.c | 3 +--
scripts/qapi.py | 9 ++-------
7 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h
index 090b19b..590b067 100644
--- a/include/qapi/visitor-impl.h
+++ b/include/qapi/visitor-impl.h
@@ -69,8 +69,7 @@ struct Visitor
Error **errp);
/* May be NULL; most useful for input visitors. */
- void (*optional)(Visitor *v, bool *present, const char *name,
- Error **errp);
+ void (*optional)(Visitor *v, bool *present, const char *name);
/* FIXME - needs to be removed */
bool (*start_union)(Visitor *v, bool data_present, Error **errp);
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 2883cf4..2deeb7f 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -107,10 +107,9 @@ void visit_end_list(Visitor *v, Error **errp);
* Check if an optional member @name of a QDict needs visiting.
* For input visitors, set address@hidden according to whether the
* corresponding visit_type_*() needs calling; for other visitors,
- * leave address@hidden unchanged.
+ * leave address@hidden unchanged. Return address@hidden for convenience.
*/
-void visit_optional(Visitor *v, bool *present, const char *name,
- Error **errp);
+bool visit_optional(Visitor *v, bool *present, const char *name);
/**
* Determine the qtype of the item @name in the current QDict visit.
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 7ae33b3..b2cd5b3 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -488,7 +488,7 @@ opts_type_size(Visitor *v, uint64_t *obj, const char *name,
Error **errp)
static void
-opts_optional(Visitor *v, bool *present, const char *name, Error **errp)
+opts_optional(Visitor *v, bool *present, const char *name)
{
OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index cbf7780..2594147 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -73,12 +73,12 @@ void visit_end_union(Visitor *v, bool data_present, Error
**errp)
}
}
-void visit_optional(Visitor *v, bool *present, const char *name,
- Error **errp)
+bool visit_optional(Visitor *v, bool *present, const char *name)
{
if (v->optional) {
- v->optional(v, present, name, errp);
+ v->optional(v, present, name);
}
+ return *present;
}
void visit_get_next_type(Visitor *v, qtype_code *type, bool promote_int,
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index 5310db5..f714dfc 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -300,8 +300,7 @@ static void qmp_input_type_any(Visitor *v, QObject **obj,
const char *name,
*obj = qobj;
}
-static void qmp_input_optional(Visitor *v, bool *present, const char *name,
- Error **errp)
+static void qmp_input_optional(Visitor *v, bool *present, const char *name)
{
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name, true);
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index bbd6a54..dee780a 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -299,8 +299,7 @@ static void parse_type_number(Visitor *v, double *obj,
const char *name,
*obj = val;
}
-static void parse_optional(Visitor *v, bool *present, const char *name,
- Error **errp)
+static void parse_optional(Visitor *v, bool *present, const char *name)
{
StringInputVisitor *siv = DO_UPCAST(StringInputVisitor, visitor, v);
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 46c55a9..a91bdf2 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1580,15 +1580,10 @@ def gen_visit_fields(members, prefix, need_cast,
errarg):
for memb in members:
if memb.optional:
ret += mcgen('''
-visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s", %(errp)s);
+if (visit_optional(v, &%(prefix)shas_%(c_name)s, "%(name)s")) {
''',
prefix=prefix, c_name=c_name(memb.name),
- name=memb.name, errp=errparg)
- ret += gen_err_check(errarg)
- ret += mcgen('''
-if (%(prefix)shas_%(c_name)s) {
-''',
- prefix=prefix, c_name=c_name(memb.name))
+ name=memb.name)
push_indent()
# Ugly: sometimes we need to cast away const
--
2.4.3
- [Qemu-devel] [PATCH v5 15/46] qapi: Defer duplicate member checks to schema check(), (continued)
- [Qemu-devel] [PATCH v5 15/46] qapi: Defer duplicate member checks to schema check(), Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 13/46] qapi: Track owner of each object member, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 17/46] qapi: Provide nicer array names in introspection, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 18/46] qapi-introspect: Guarantee particular sorting, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 20/46] qapi: Fix alternates that accept 'number' but not 'int', Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 21/46] qmp: Fix reference-counting of qnull on empty output visit, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 19/46] qapi: Simplify visiting of alternate types, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 22/46] qapi: Don't abuse stack to track qmp-output root, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 26/46] qapi: Test failure in middle of array parse, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 23/46] qapi: Remove dead visitor code, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 27/46] qapi: Simplify visits of optional fields,
Eric Blake <=
- [Qemu-devel] [PATCH v5 25/46] qapi: Plug leaks in test-qmp-input-visitor, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 24/46] qapi: Document visitor interfaces, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 28/46] qapi: Rework deallocation of partial struct, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 29/46] qapi: Change visit_type_FOO() to no longer return partial objects, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 30/46] net: use Netdev instead of NetClientOptions in client init, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 33/46] vnc: hoist allocation of VncBasicInfo to callers, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 32/46] qapi: Hide tag_name data member of variants, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 35/46] qapi-visit: Remove redundant functions for flat union base, Eric Blake, 2015/09/21
- [Qemu-devel] [PATCH v5 34/46] qapi: Unbox base members, Eric Blake, 2015/09/21