mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
qapi: Split visit_end_struct() into pieces
As mentioned in previous patches, we want to call visit_end_struct() functions unconditionally, so that visitors can release resources tied up since the matching visit_start_struct() without also having to worry about error priority if more than one error occurs. Even though error_propagate() can be safely used to ignore a second error during cleanup caused by a first error, it is simpler if the cleanup cannot set an error. So, split out the error checking portion (basically, input visitors checking for unvisited keys) into a new function visit_check_struct(), which can be safely skipped if any earlier errors are encountered, and leave the cleanup portion (which never fails, but must be called unconditionally if visit_start_struct() succeeded) in visit_end_struct(). Generated code in qapi-visit.c has diffs resembling: |@@ -59,10 +59,12 @@ void visit_type_ACPIOSTInfo(Visitor *v, | goto out_obj; | } | visit_type_ACPIOSTInfo_members(v, obj, &err); |- error_propagate(errp, err); |- err = NULL; |+ if (err) { |+ goto out_obj; |+ } |+ visit_check_struct(v, &err); | out_obj: |- visit_end_struct(v, &err); |+ visit_end_struct(v); | out: and in qapi-event.c: @@ -47,7 +47,10 @@ void qapi_event_send_acpi_device_ost(ACP | goto out; | } | visit_type_q_obj_ACPI_DEVICE_OST_arg_members(v, ¶m, &err); |- visit_end_struct(v, err ? NULL : &err); |+ if (!err) { |+ visit_check_struct(v, &err); |+ } |+ visit_end_struct(v); | if (err) { | goto out; Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1461879932-9020-20-git-send-email-eblake@redhat.com> [Conflict with a doc fixup resolved] Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
56a6f02b8c
commit
15c2f669e3
18 changed files with 128 additions and 73 deletions
|
@ -125,9 +125,11 @@ static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, Error **errp)
|
|||
}
|
||||
|
||||
|
||||
static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp)
|
||||
static void qmp_input_check_struct(Visitor *v, Error **errp)
|
||||
{
|
||||
QmpInputVisitor *qiv = to_qiv(v);
|
||||
StackObject *tos = &qiv->stack[qiv->nb_stack - 1];
|
||||
|
||||
assert(qiv->nb_stack > 0);
|
||||
|
||||
if (qiv->strict) {
|
||||
|
@ -140,6 +142,20 @@ static void qmp_input_pop(QmpInputVisitor *qiv, Error **errp)
|
|||
if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) {
|
||||
error_setg(errp, QERR_QMP_EXTRA_MEMBER, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void qmp_input_pop(Visitor *v)
|
||||
{
|
||||
QmpInputVisitor *qiv = to_qiv(v);
|
||||
StackObject *tos = &qiv->stack[qiv->nb_stack - 1];
|
||||
|
||||
assert(qiv->nb_stack > 0);
|
||||
|
||||
if (qiv->strict) {
|
||||
GHashTable * const top_ht = qiv->stack[qiv->nb_stack - 1].h;
|
||||
if (top_ht) {
|
||||
g_hash_table_unref(top_ht);
|
||||
}
|
||||
tos->h = NULL;
|
||||
|
@ -175,12 +191,6 @@ static void qmp_input_start_struct(Visitor *v, const char *name, void **obj,
|
|||
}
|
||||
}
|
||||
|
||||
static void qmp_input_end_struct(Visitor *v, Error **errp)
|
||||
{
|
||||
QmpInputVisitor *qiv = to_qiv(v);
|
||||
|
||||
qmp_input_pop(qiv, errp);
|
||||
}
|
||||
|
||||
static void qmp_input_start_list(Visitor *v, const char *name, Error **errp)
|
||||
{
|
||||
|
@ -218,12 +228,6 @@ static GenericList *qmp_input_next_list(Visitor *v, GenericList **list,
|
|||
return entry;
|
||||
}
|
||||
|
||||
static void qmp_input_end_list(Visitor *v)
|
||||
{
|
||||
QmpInputVisitor *qiv = to_qiv(v);
|
||||
|
||||
qmp_input_pop(qiv, &error_abort);
|
||||
}
|
||||
|
||||
static void qmp_input_start_alternate(Visitor *v, const char *name,
|
||||
GenericAlternate **obj, size_t size,
|
||||
|
@ -383,10 +387,11 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict)
|
|||
|
||||
v->visitor.type = VISITOR_INPUT;
|
||||
v->visitor.start_struct = qmp_input_start_struct;
|
||||
v->visitor.end_struct = qmp_input_end_struct;
|
||||
v->visitor.check_struct = qmp_input_check_struct;
|
||||
v->visitor.end_struct = qmp_input_pop;
|
||||
v->visitor.start_list = qmp_input_start_list;
|
||||
v->visitor.next_list = qmp_input_next_list;
|
||||
v->visitor.end_list = qmp_input_end_list;
|
||||
v->visitor.end_list = qmp_input_pop;
|
||||
v->visitor.start_alternate = qmp_input_start_alternate;
|
||||
v->visitor.type_int64 = qmp_input_type_int64;
|
||||
v->visitor.type_uint64 = qmp_input_type_uint64;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue