From 7e832740123bb8f8d0480b1bfc8ee5023054f28a Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 19 Feb 2018 22:21:33 -0500 Subject: [PATCH] qapi-visit: Kill unused visit_end_union() The generated code can call visit_end_union() without having called visit_start_union(). Example: if (!*obj) { goto out_obj; } visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err); if (err) { goto out_obj; // if we go from here... } if (!visit_start_union(v, !!(*obj)->u.data, &err) || err) { goto out_obj; } switch ((*obj)->arch) { [...] } out_obj: // ... then *obj is true, and ... error_propagate(errp, err); err = NULL; if (*obj) { // we end up here visit_end_union(v, !!(*obj)->u.data, &err); } error_propagate(errp, err); Harmless only because no visitor implements end_union(). Clean it up anyway, by deleting the function as useless. Messed up since we have visit_end_union (commit cee2ded). Backports commit 7c91aabd8964cfdf637f302c579c95401f21ce92 from qemu --- msvc/unicorn/qapi-visit.c | 32 ++++++++++++++++++++++---------- qemu/include/qapi/visitor-impl.h | 1 - qemu/include/qapi/visitor.h | 1 - qemu/qapi/qapi-visit-core.c | 9 ++------- qemu/scripts/qapi-visit.py | 5 ----- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/msvc/unicorn/qapi-visit.c b/msvc/unicorn/qapi-visit.c index bcab3b39..f5ed07da 100644 --- a/msvc/unicorn/qapi-visit.c +++ b/msvc/unicorn/qapi-visit.c @@ -35,12 +35,18 @@ void visit_type_DummyForceArrays(Visitor *v, DummyForceArrays **obj, const char visit_start_struct(v, (void **)obj, "DummyForceArrays", name, sizeof(DummyForceArrays), &err); - if (!err) { - if (*obj) { - visit_type_DummyForceArrays_fields(v, obj, errp); - } - visit_end_struct(v, &err); + if (err) { + goto out; } + if (!*obj) { + goto out_obj; + } + visit_type_DummyForceArrays_fields(v, obj, &err); + error_propagate(errp, err); + err = NULL; +out_obj: + visit_end_struct(v, &err); +out: error_propagate(errp, err); } @@ -87,12 +93,18 @@ void visit_type_X86CPUFeatureWordInfo(Visitor *v, X86CPUFeatureWordInfo **obj, c visit_start_struct(v, (void **)obj, "X86CPUFeatureWordInfo", name, sizeof(X86CPUFeatureWordInfo), &err); - if (!err) { - if (*obj) { - visit_type_X86CPUFeatureWordInfo_fields(v, obj, errp); - } - visit_end_struct(v, &err); + if (err) { + goto out; } + if (!*obj) { + goto out_obj; + } + visit_type_X86CPUFeatureWordInfo_fields(v, obj, &err); + error_propagate(errp, err); + err = NULL; +out_obj: + visit_end_struct(v, &err); +out: error_propagate(errp, err); } diff --git a/qemu/include/qapi/visitor-impl.h b/qemu/include/qapi/visitor-impl.h index c9604611..f06a3307 100644 --- a/qemu/include/qapi/visitor-impl.h +++ b/qemu/include/qapi/visitor-impl.h @@ -62,7 +62,6 @@ struct Visitor void (*type_int16)(Visitor *v, int16_t *obj, const char *name, Error **errp); void (*type_int32)(Visitor *v, int32_t *obj, const char *name, Error **errp); bool (*start_union)(Visitor *v, bool data_present, Error **errp); - void (*end_union)(Visitor *v, bool data_present, Error **errp); }; void input_type_enum(Visitor *v, int *obj, const char * const strings[], diff --git a/qemu/include/qapi/visitor.h b/qemu/include/qapi/visitor.h index 6b08bbee..042cc12c 100644 --- a/qemu/include/qapi/visitor.h +++ b/qemu/include/qapi/visitor.h @@ -70,6 +70,5 @@ void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp); void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp); void visit_type_any(Visitor *v, QObject **obj, const char *name, Error **errp); bool visit_start_union(Visitor *v, bool data_present, Error **errp); -void visit_end_union(Visitor *v, bool data_present, Error **errp); #endif diff --git a/qemu/qapi/qapi-visit-core.c b/qemu/qapi/qapi-visit-core.c index a2bd3a34..a5b205b2 100644 --- a/qemu/qapi/qapi-visit-core.c +++ b/qemu/qapi/qapi-visit-core.c @@ -1,8 +1,10 @@ /* * Core Definitions for QAPI Visitor Classes * + * Copyright (C) 2012-2016 Red Hat, Inc. * Copyright IBM, Corp. 2011 * + * * Authors: * Anthony Liguori * @@ -67,13 +69,6 @@ bool visit_start_union(Visitor *v, bool data_present, Error **errp) return true; } -void visit_end_union(Visitor *v, bool data_present, Error **errp) -{ - if (v->end_union) { - v->end_union(v, data_present, errp); - } -} - bool visit_optional(Visitor *v, bool *present, const char *name) { if (v->optional) { diff --git a/qemu/scripts/qapi-visit.py b/qemu/scripts/qapi-visit.py index e2976fd0..65a8cc92 100644 --- a/qemu/scripts/qapi-visit.py +++ b/qemu/scripts/qapi-visit.py @@ -316,11 +316,6 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error abort(); } out_obj: - error_propagate(errp, err); - err = NULL; - if (*obj) { - visit_end_union(v, !!(*obj)->u.data, &err); - } error_propagate(errp, err); err = NULL; visit_end_struct(v, &err);