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;
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <
1465490926-28625-8-git-send-email-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
{
Error *err = NULL;
UserDefOne *retval;
- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
Visitor *v;
UserDefOneList *arg1 = NULL;
- 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;
* Set @strict to reject a parse that doesn't consume all keys of a
* dictionary; otherwise excess input is ignored.
*/
-QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict);
-
-void qmp_input_visitor_cleanup(QmpInputVisitor *v);
-
-Visitor *qmp_input_get_visitor(QmpInputVisitor *v);
+Visitor *qmp_input_visitor_new(QObject *obj, bool strict);
#endif
*present = true;
}
-Visitor *qmp_input_get_visitor(QmpInputVisitor *v)
-{
- return &v->visitor;
-}
-
static void qmp_input_free(Visitor *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)
-{
- qobject_decref(v->root);
- g_free(v);
-}
-
-QmpInputVisitor *qmp_input_visitor_new(QObject *obj, bool strict)
+Visitor *qmp_input_visitor_new(QObject *obj, bool strict)
{
QmpInputVisitor *v;
v->root = obj;
qobject_incref(obj);
- return v;
+ return &v->visitor;
}
bool has_props, QObject *props, Error **errp)
{
const QDict *pdict = NULL;
- QmpInputVisitor *qiv;
+ Visitor *v;
Object *obj;
if (props) {
}
}
- qiv = qmp_input_visitor_new(props, true);
- obj = user_creatable_add_type(type, id, pdict,
- qmp_input_get_visitor(qiv), errp);
- qmp_input_visitor_cleanup(qiv);
+ v = qmp_input_visitor_new(props, true);
+ obj = user_creatable_add_type(type, id, pdict, v, errp);
+ visit_free(v);
if (obj) {
object_unref(obj);
}
void object_property_set_qobject(Object *obj, QObject *value,
const char *name, Error **errp)
{
- QmpInputVisitor *qiv;
+ Visitor *v;
/* TODO: Should we reject, rather than ignore, excess input? */
- qiv = qmp_input_visitor_new(value, false);
- object_property_set(obj, qmp_input_get_visitor(qiv), name, errp);
-
- qmp_input_visitor_cleanup(qiv);
+ v = qmp_input_visitor_new(value, false);
+ object_property_set(obj, v, name, errp);
+ visit_free(v);
}
QObject *object_property_get_qobject(Object *obj, const char *name,
static InputEvent *qapi_clone_InputEvent(InputEvent *src)
{
QmpOutputVisitor *qov;
- QmpInputVisitor *qiv;
Visitor *ov, *iv;
QObject *obj;
InputEvent *dst = NULL;
return NULL;
}
- qiv = qmp_input_visitor_new(obj, true);
- iv = qmp_input_get_visitor(qiv);
+ iv = qmp_input_visitor_new(obj, true);
visit_type_InputEvent(iv, NULL, &dst, &error_abort);
- qmp_input_visitor_cleanup(qiv);
+ visit_free(iv);
qobject_decref(obj);
return dst;
if arg_type and arg_type.members:
ret += mcgen('''
- QmpInputVisitor *qiv = qmp_input_visitor_new(QOBJECT(args), true);
Visitor *v;
%(c_name)s 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;
{
QObject *obj;
QmpOutputVisitor *qov;
- QmpInputVisitor *qiv;
+ Visitor *v;
/*
* Most tests of interactions between QObject and visitors are in
g_assert(qnull_.refcnt == 1);
obj = qnull();
- qiv = qmp_input_visitor_new(obj, true);
+ v = qmp_input_visitor_new(obj, true);
qobject_decref(obj);
- visit_type_null(qmp_input_get_visitor(qiv), NULL, &error_abort);
- qmp_input_visitor_cleanup(qiv);
+ visit_type_null(v, NULL, &error_abort);
+ visit_free(v);
qov = qmp_output_visitor_new();
visit_type_null(qmp_output_get_visitor(qov), NULL, &error_abort);
/* create partial object */
{
QDict *ud2_dict;
- QmpInputVisitor *qiv;
+ Visitor *v;
ud2_dict = qdict_new();
qdict_put_obj(ud2_dict, "string0", QOBJECT(qstring_from_str(text)));
- qiv = qmp_input_visitor_new(QOBJECT(ud2_dict), true);
- visit_type_UserDefTwo(qmp_input_get_visitor(qiv), NULL, &ud2, &err);
- qmp_input_visitor_cleanup(qiv);
+ v = qmp_input_visitor_new(QOBJECT(ud2_dict), true);
+ visit_type_UserDefTwo(v, NULL, &ud2, &err);
+ visit_free(v);
QDECREF(ud2_dict);
}
typedef struct TestInputVisitorData {
QObject *obj;
- QmpInputVisitor *qiv;
+ Visitor *qiv;
} TestInputVisitorData;
static void validate_teardown(TestInputVisitorData *data,
data->obj = NULL;
if (data->qiv) {
- qmp_input_visitor_cleanup(data->qiv);
+ visit_free(data->qiv);
data->qiv = NULL;
}
}
const char *json_string,
va_list *ap)
{
- Visitor *v;
-
validate_teardown(data, NULL);
data->obj = qobject_from_jsonv(json_string, ap);
data->qiv = qmp_input_visitor_new(data->obj, true);
g_assert(data->qiv);
-
- v = qmp_input_get_visitor(data->qiv);
- g_assert(v);
-
- return v;
+ return data->qiv;
}
static GCC_FMT_ATTR(2, 3)
typedef struct TestInputVisitorData {
QObject *obj;
- QmpInputVisitor *qiv;
+ Visitor *qiv;
} TestInputVisitorData;
static void visitor_input_teardown(TestInputVisitorData *data,
data->obj = NULL;
if (data->qiv) {
- qmp_input_visitor_cleanup(data->qiv);
+ visit_free(data->qiv);
data->qiv = NULL;
}
}
const char *json_string,
va_list *ap)
{
- Visitor *v;
-
visitor_input_teardown(data, NULL);
data->obj = qobject_from_jsonv(json_string, ap);
data->qiv = qmp_input_visitor_new(data->obj, false);
g_assert(data->qiv);
-
- v = qmp_input_get_visitor(data->qiv);
- g_assert(v);
-
- return v;
+ return data->qiv;
}
static GCC_FMT_ATTR(2, 3)
typedef struct QmpSerializeData {
QmpOutputVisitor *qov;
- QmpInputVisitor *qiv;
+ Visitor *qiv;
} QmpSerializeData;
static void qmp_serialize(void *native_in, void **datap,
d->qiv = qmp_input_visitor_new(obj, true);
qobject_decref(obj_orig);
qobject_decref(obj);
- visit(qmp_input_get_visitor(d->qiv), native_out, errp);
+ visit(d->qiv, native_out, errp);
}
static void qmp_cleanup(void *datap)
{
QmpSerializeData *d = datap;
qmp_output_visitor_cleanup(d->qov);
- qmp_input_visitor_cleanup(d->qiv);
+ visit_free(d->qiv);
g_free(d);
}
SocketAddress *src)
{
QmpOutputVisitor *qov;
- QmpInputVisitor *qiv;
Visitor *ov, *iv;
QObject *obj;
return;
}
- qiv = qmp_input_visitor_new(obj, true);
- iv = qmp_input_get_visitor(qiv);
+ iv = qmp_input_visitor_new(obj, true);
visit_type_SocketAddress(iv, NULL, p_dest, &error_abort);
- qmp_input_visitor_cleanup(qiv);
+ visit_free(iv);
qobject_decref(obj);
}