qmp-input-visitor: Favor new visit_free() function

Now that we have a polymorphic visit_free(), we no longer need
qmp_input_visitor_cleanup(); which in turn means we no longer
need to return a subtype from qmp_input_visitor_new() nor a
public upcast function.

Generated code changes to qmp-marshal.c look like:

|@@ -52,11 +52,10 @@ void qmp_marshal_add_fd(QDict *args, QOb
| {
| Error *err = NULL;
| AddfdInfo *retval;
|- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
| Visitor *v;
| q_obj_add_fd_arg arg = {0};
|
|- v = qmp_input_get_visitor(qiv);
|+ v = qmp_input_visitor_new(QOBJECT(args), true);
| visit_start_struct(v, NULL, NULL, 0, &err);
| if (err) {
| goto out;

Backports commit b70ce1018a251c0c33498d9c927a07cade655a5e from qemu
This commit is contained in:
Eric Blake 2018-02-25 01:09:42 -05:00 committed by Lioncash
parent e88a7e260b
commit f008d93ac0
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
3 changed files with 9 additions and 24 deletions

View file

@ -25,10 +25,6 @@ typedef struct QmpInputVisitor QmpInputVisitor;
* Set @strict to reject a parse that doesn't consume all keys of a * Set @strict to reject a parse that doesn't consume all keys of a
* dictionary; otherwise excess input is ignored. * dictionary; otherwise excess input is ignored.
*/ */
QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict); Visitor *qmp_input_visitor_new(QObject *obj, bool strict);
void qmp_input_visitor_cleanup(QmpInputVisitor *v);
Visitor *qmp_input_get_visitor(QmpInputVisitor *v);
#endif #endif

View file

@ -374,25 +374,15 @@ static void qmp_input_optional(Visitor *v, const char *name, bool *present)
*present = true; *present = true;
} }
Visitor *qmp_input_get_visitor(QmpInputVisitor *v)
{
return &v->visitor;
}
static void qmp_input_free(Visitor *v) static void qmp_input_free(Visitor *v)
{ {
QmpInputVisitor *qiv = to_qiv(v); QmpInputVisitor *qiv = to_qiv(v);
qmp_input_visitor_cleanup(qiv); qobject_decref(qiv->root);
g_free(qiv);
} }
void qmp_input_visitor_cleanup(QmpInputVisitor *v) Visitor *qmp_input_visitor_new(QObject *obj, bool strict)
{
qobject_decref(v->root);
g_free(v);
}
QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict)
{ {
QmpInputVisitor *v; QmpInputVisitor *v;
@ -420,5 +410,5 @@ QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict)
v->root = obj; v->root = obj;
qobject_incref(obj); qobject_incref(obj);
return v; return &v->visitor;
} }

View file

@ -21,12 +21,11 @@
void object_property_set_qobject(struct uc_struct *uc, Object *obj, QObject *value, void object_property_set_qobject(struct uc_struct *uc, Object *obj, QObject *value,
const char *name, Error **errp) const char *name, Error **errp)
{ {
QmpInputVisitor *qiv; Visitor *v;
/* TODO: Should we reject, rather than ignore, excess input? */ /* TODO: Should we reject, rather than ignore, excess input? */
qiv = qmp_input_visitor_new(value, false); v = qmp_input_visitor_new(value, false);
object_property_set(uc, obj, qmp_input_get_visitor(qiv), name, errp); object_property_set(uc, obj, v, name, errp);
visit_free(v);
qmp_input_visitor_cleanup(qiv);
} }
QObject *object_property_get_qobject(struct uc_struct *uc, Object *obj, const char *name, QObject *object_property_get_qobject(struct uc_struct *uc, Object *obj, const char *name,