From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>,
Eric Blake <eblake@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v1 3/6] qapi: assert that visitor impls have required callbacks
Date: Tue, 7 Jun 2016 11:11:12 +0100 [thread overview]
Message-ID: <1465294275-8733-4-git-send-email-berrange@redhat.com> (raw)
In-Reply-To: <1465294275-8733-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 eada467..3b5efbe 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -29,6 +29,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);
@@ -45,6 +46,7 @@ void visit_check_struct(Visitor *v, Error **errp)
void visit_end_struct(Visitor *v)
{
+ assert(v->end_struct != NULL);
v->end_struct(v);
}
@@ -54,6 +56,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));
@@ -64,11 +67,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)
{
+ assert(v->end_list != NULL);
v->end_list(v);
}
@@ -112,6 +117,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);
}
@@ -121,6 +127,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);
@@ -160,6 +167,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);
}
@@ -170,6 +178,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);
@@ -218,6 +227,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);
}
}
@@ -225,6 +235,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);
}
@@ -237,6 +248,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);
@@ -248,6 +260,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);
}
@@ -257,6 +270,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);
@@ -266,6 +280,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.5.5
next prev parent reply other threads:[~2016-06-07 10:11 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 10:11 [Qemu-devel] [PATCH v1 0/6] Report format specific info for LUKS block driver Daniel P. Berrange
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 1/6] crypto: add support for querying parameters for block encryption Daniel P. Berrange
2016-06-07 14:17 ` Eric Blake
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 2/6] block: export LUKS specific data to qemu-img info Daniel P. Berrange
2016-06-07 15:36 ` Eric Blake
2016-06-07 15:51 ` Daniel P. Berrange
2016-06-07 16:11 ` Eric Blake
2016-06-07 10:11 ` Daniel P. Berrange [this message]
2016-06-07 15:40 ` [Qemu-devel] [PATCH v1 3/6] qapi: assert that visitor impls have required callbacks Eric Blake
2016-06-07 15:46 ` Daniel P. Berrange
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 4/6] qapi: add a text output visitor for pretty printing types Daniel P. Berrange
2016-06-07 16:09 ` Eric Blake
2016-06-07 16:20 ` Daniel P. Berrange
2016-06-07 16:40 ` Eric Blake
2016-06-07 16:45 ` Daniel P. Berrange
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 5/6] qapi: generate a qapi_stringify_TYPENAME method for all types Daniel P. Berrange
2016-06-07 16:23 ` Eric Blake
2016-06-07 10:11 ` [Qemu-devel] [PATCH v1 6/6] block: convert to use qapi_stringify_ImageInfoSpecific Daniel P. Berrange
2016-06-07 16:59 ` Eric Blake
2016-06-07 12:04 ` [Qemu-devel] [PATCH v1 0/6] Report format specific info for LUKS block driver Eric Blake
2016-06-07 14:35 ` Daniel P. Berrange
2016-06-14 13:56 ` Max Reitz
2016-06-14 14:05 ` 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=1465294275-8733-4-git-send-email-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mreitz@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 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).