From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eric Blake <eblake@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-block@nongnu.org, "Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v2 3/6] qapi: assert that visitor impls have required callbacks
Date: Fri, 9 Sep 2016 18:41:58 +0100 [thread overview]
Message-ID: <1473442921-2968-4-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1473442921-2968-1-git-send-email-berrange@redhat.com>
Not all visitor implementations supply the full set of
visitor callback functions. For example, the string
output visitor does not provide 'start_struct' and
friends. If you don't know this and feed it an object
that uses structs, you'll get a crash:
Segmentation fault (core dumped)
Crashing is fine, because this is a programmer mistake,
but we can improve the error message upon crash to make
it obvious what failed by adding assert()s:
qapi/qapi-visit-core.c:32: visit_start_struct: Assertion `v->start_struct != ((void *)0)' failed.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
qapi/qapi-visit-core.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 55f5876..df199b7 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -44,6 +44,7 @@ void visit_start_struct(Visitor *v, const char *name, void **obj,
assert(size);
assert(!(v->type & VISITOR_OUTPUT) || *obj);
}
+ assert(v->start_struct != NULL);
v->start_struct(v, name, obj, size, &err);
if (obj && (v->type & VISITOR_INPUT)) {
assert(!err != !*obj);
@@ -60,6 +61,7 @@ void visit_check_struct(Visitor *v, Error **errp)
void visit_end_struct(Visitor *v, void **obj)
{
+ assert(v->end_struct != NULL);
v->end_struct(v, obj);
}
@@ -69,6 +71,7 @@ void visit_start_list(Visitor *v, const char *name, GenericList **list,
Error *err = NULL;
assert(!list || size >= sizeof(GenericList));
+ assert(v->start_list != NULL);
v->start_list(v, name, list, size, &err);
if (list && (v->type & VISITOR_INPUT)) {
assert(!(err && *list));
@@ -79,11 +82,13 @@ void visit_start_list(Visitor *v, const char *name, GenericList **list,
GenericList *visit_next_list(Visitor *v, GenericList *tail, size_t size)
{
assert(tail && size >= sizeof(GenericList));
+ assert(v->next_list != NULL);
return v->next_list(v, tail, size);
}
void visit_end_list(Visitor *v, void **obj)
{
+ assert(v->end_list != NULL);
v->end_list(v, obj);
}
@@ -127,6 +132,7 @@ bool visit_is_input(Visitor *v)
void visit_type_int(Visitor *v, const char *name, int64_t *obj, Error **errp)
{
assert(obj);
+ assert(v->type_int64 != NULL);
v->type_int64(v, name, obj, errp);
}
@@ -136,6 +142,7 @@ static void visit_type_uintN(Visitor *v, uint64_t *obj, const char *name,
Error *err = NULL;
uint64_t value = *obj;
+ assert(v->type_uint64 != NULL);
v->type_uint64(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
@@ -175,6 +182,7 @@ void visit_type_uint64(Visitor *v, const char *name, uint64_t *obj,
Error **errp)
{
assert(obj);
+ assert(v->type_uint64 != NULL);
v->type_uint64(v, name, obj, errp);
}
@@ -185,6 +193,7 @@ static void visit_type_intN(Visitor *v, int64_t *obj, const char *name,
Error *err = NULL;
int64_t value = *obj;
+ assert(v->type_int64 != NULL);
v->type_int64(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
@@ -233,6 +242,7 @@ void visit_type_size(Visitor *v, const char *name, uint64_t *obj,
if (v->type_size) {
v->type_size(v, name, obj, errp);
} else {
+ assert(v->type_uint64 != NULL);
v->type_uint64(v, name, obj, errp);
}
}
@@ -240,6 +250,7 @@ void visit_type_size(Visitor *v, const char *name, uint64_t *obj,
void visit_type_bool(Visitor *v, const char *name, bool *obj, Error **errp)
{
assert(obj);
+ assert(v->type_bool != NULL);
v->type_bool(v, name, obj, errp);
}
@@ -252,6 +263,7 @@ void visit_type_str(Visitor *v, const char *name, char **obj, Error **errp)
* can enable:
assert(!(v->type & VISITOR_OUTPUT) || *obj);
*/
+ assert(v->type_str != NULL);
v->type_str(v, name, obj, &err);
if (v->type & VISITOR_INPUT) {
assert(!err != !*obj);
@@ -263,6 +275,7 @@ void visit_type_number(Visitor *v, const char *name, double *obj,
Error **errp)
{
assert(obj);
+ assert(v->type_number != NULL);
v->type_number(v, name, obj, errp);
}
@@ -272,6 +285,7 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp)
assert(obj);
assert(v->type != VISITOR_OUTPUT || *obj);
+ assert(v->type_any != NULL);
v->type_any(v, name, obj, &err);
if (v->type == VISITOR_INPUT) {
assert(!err != !*obj);
@@ -281,6 +295,7 @@ void visit_type_any(Visitor *v, const char *name, QObject **obj, Error **errp)
void visit_type_null(Visitor *v, const char *name, Error **errp)
{
+ assert(v->type_null != NULL);
v->type_null(v, name, errp);
}
--
2.7.4
next prev parent reply other threads:[~2016-09-09 17:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-09 17:41 [Qemu-devel] [PATCH v2 0/6] Stable output of blockdev format specific info Daniel P. Berrange
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 1/6] cutils: add helpers for formatting sized values Daniel P. Berrange
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 2/6] qapi: convert StringOutputVisitor to use qemu_szutostr Daniel P. Berrange
2016-09-09 17:41 ` Daniel P. Berrange [this message]
2016-09-09 17:41 ` [Qemu-devel] [PATCH v2 4/6] qapi: add a text output visitor for pretty printing types Daniel P. Berrange
2016-09-09 17:42 ` [Qemu-devel] [PATCH v2 5/6] block: convert to use the qemu_szutostr functions Daniel P. Berrange
2016-09-09 17:42 ` [Qemu-devel] [PATCH v2 6/6] block: convert to use qapi_stringify_ImageInfoSpecific Daniel P. Berrange
2016-09-13 13:44 ` [Qemu-devel] [PATCH v2 0/6] Stable output of blockdev format specific info Markus Armbruster
2016-09-13 13:52 ` Daniel P. Berrange
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=1473442921-2968-4-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.