提交 09204eac 编写于 作者: E Eric Blake 提交者: Markus Armbruster

opts-visitor: Favor new visit_free() function

Now that we have a polymorphic visit_free(), we no longer need
opts_visitor_cleanup(); which in turn means we no longer need
to return a subtype from opts_visitor_new() nor a public upcast
function.
Signed-off-by: NEric Blake <eblake@redhat.com>
Message-Id: <1465490926-28625-6-git-send-email-eblake@redhat.com>
Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
上级 2c0ef9f4
......@@ -193,17 +193,16 @@ block_crypto_open_opts_init(QCryptoBlockFormat format,
QemuOpts *opts,
Error **errp)
{
OptsVisitor *ov;
Visitor *v;
QCryptoBlockOpenOptions *ret = NULL;
Error *local_err = NULL;
ret = g_new0(QCryptoBlockOpenOptions, 1);
ret->format = format;
ov = opts_visitor_new(opts);
v = opts_visitor_new(opts);
visit_start_struct(opts_get_visitor(ov),
NULL, NULL, 0, &local_err);
visit_start_struct(v, NULL, NULL, 0, &local_err);
if (local_err) {
goto out;
}
......@@ -211,7 +210,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format,
switch (format) {
case Q_CRYPTO_BLOCK_FORMAT_LUKS:
visit_type_QCryptoBlockOptionsLUKS_members(
opts_get_visitor(ov), &ret->u.luks, &local_err);
v, &ret->u.luks, &local_err);
break;
default:
......@@ -219,10 +218,10 @@ block_crypto_open_opts_init(QCryptoBlockFormat format,
break;
}
if (!local_err) {
visit_check_struct(opts_get_visitor(ov), &local_err);
visit_check_struct(v, &local_err);
}
visit_end_struct(opts_get_visitor(ov), NULL);
visit_end_struct(v, NULL);
out:
if (local_err) {
......@@ -230,7 +229,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format,
qapi_free_QCryptoBlockOpenOptions(ret);
ret = NULL;
}
opts_visitor_cleanup(ov);
visit_free(v);
return ret;
}
......@@ -240,17 +239,16 @@ block_crypto_create_opts_init(QCryptoBlockFormat format,
QemuOpts *opts,
Error **errp)
{
OptsVisitor *ov;
Visitor *v;
QCryptoBlockCreateOptions *ret = NULL;
Error *local_err = NULL;
ret = g_new0(QCryptoBlockCreateOptions, 1);
ret->format = format;
ov = opts_visitor_new(opts);
v = opts_visitor_new(opts);
visit_start_struct(opts_get_visitor(ov),
NULL, NULL, 0, &local_err);
visit_start_struct(v, NULL, NULL, 0, &local_err);
if (local_err) {
goto out;
}
......@@ -258,7 +256,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format,
switch (format) {
case Q_CRYPTO_BLOCK_FORMAT_LUKS:
visit_type_QCryptoBlockCreateOptionsLUKS_members(
opts_get_visitor(ov), &ret->u.luks, &local_err);
v, &ret->u.luks, &local_err);
break;
default:
......@@ -266,10 +264,10 @@ block_crypto_create_opts_init(QCryptoBlockFormat format,
break;
}
if (!local_err) {
visit_check_struct(opts_get_visitor(ov), &local_err);
visit_check_struct(v, &local_err);
}
visit_end_struct(opts_get_visitor(ov), NULL);
visit_end_struct(v, NULL);
out:
if (local_err) {
......@@ -277,7 +275,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format,
qapi_free_QCryptoBlockCreateOptions(ret);
ret = NULL;
}
opts_visitor_cleanup(ov);
visit_free(v);
return ret;
}
......
......@@ -1722,7 +1722,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
QemuOpts *opts;
OptsVisitor *ov;
Visitor *v;
Object *obj = NULL;
opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
......@@ -1731,9 +1731,9 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
return;
}
ov = opts_visitor_new(opts);
obj = user_creatable_add(qdict, opts_get_visitor(ov), &err);
opts_visitor_cleanup(ov);
v = opts_visitor_new(opts);
obj = user_creatable_add(qdict, v, &err);
visit_free(v);
qemu_opts_del(opts);
if (err) {
......
......@@ -239,11 +239,11 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
char unsigned *blob = NULL;
{
OptsVisitor *ov;
Visitor *v;
ov = opts_visitor_new(opts);
visit_type_AcpiTableOptions(opts_get_visitor(ov), NULL, &hdrs, &err);
opts_visitor_cleanup(ov);
v = opts_visitor_new(opts);
visit_type_AcpiTableOptions(v, NULL, &hdrs, &err);
visit_free(v);
}
if (err) {
......
......@@ -35,8 +35,6 @@ typedef struct OptsVisitor OptsVisitor;
* QTypes. It also requires a non-null list argument to
* visit_start_list().
*/
OptsVisitor *opts_visitor_new(const QemuOpts *opts);
void opts_visitor_cleanup(OptsVisitor *nv);
Visitor *opts_get_visitor(OptsVisitor *nv);
Visitor *opts_visitor_new(const QemuOpts *opts);
#endif
......@@ -1024,8 +1024,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
void *object = NULL;
Error *err = NULL;
int ret = -1;
OptsVisitor *ov = opts_visitor_new(opts);
Visitor *v = opts_get_visitor(ov);
Visitor *v = opts_visitor_new(opts);
{
/* Parse convenience option format ip6-net=fec0::0[/64] */
......@@ -1075,7 +1074,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
}
error_propagate(errp, err);
opts_visitor_cleanup(ov);
visit_free(v);
return ret;
}
......
......@@ -217,9 +217,9 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
Error *err = NULL;
{
OptsVisitor *ov = opts_visitor_new(opts);
visit_type_NumaOptions(opts_get_visitor(ov), NULL, &object, &err);
opts_visitor_cleanup(ov);
Visitor *v = opts_visitor_new(opts);
visit_type_NumaOptions(v, NULL, &object, &err);
visit_free(v);
}
if (err) {
......
......@@ -518,11 +518,15 @@ opts_free(Visitor *v)
{
OptsVisitor *ov = to_ov(v);
opts_visitor_cleanup(ov);
if (ov->unprocessed_opts != NULL) {
g_hash_table_destroy(ov->unprocessed_opts);
}
g_free(ov->fake_id_opt);
g_free(ov);
}
OptsVisitor *
Visitor *
opts_visitor_new(const QemuOpts *opts)
{
OptsVisitor *ov;
......@@ -553,23 +557,5 @@ opts_visitor_new(const QemuOpts *opts)
ov->opts_root = opts;
return ov;
}
void
opts_visitor_cleanup(OptsVisitor *ov)
{
if (ov->unprocessed_opts != NULL) {
g_hash_table_destroy(ov->unprocessed_opts);
}
g_free(ov->fake_id_opt);
g_free(ov);
}
Visitor *
opts_get_visitor(OptsVisitor *ov)
{
return &ov->visitor;
}
......@@ -156,15 +156,15 @@ out:
Object *user_creatable_add_opts(QemuOpts *opts, Error **errp)
{
OptsVisitor *ov;
Visitor *v;
QDict *pdict;
Object *obj = NULL;
ov = opts_visitor_new(opts);
v = opts_visitor_new(opts);
pdict = qemu_opts_to_qdict(opts, NULL);
obj = user_creatable_add(pdict, opts_get_visitor(ov), errp);
opts_visitor_cleanup(ov);
obj = user_creatable_add(pdict, v, errp);
visit_free(v);
QDECREF(pdict);
return obj;
}
......
......@@ -37,16 +37,15 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data)
{
const char *opts_string = test_data;
QemuOpts *opts;
OptsVisitor *ov;
Visitor *v;
opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, false,
NULL);
g_assert(opts != NULL);
ov = opts_visitor_new(opts);
visit_type_UserDefOptions(opts_get_visitor(ov), NULL, &f->userdef,
&f->err);
opts_visitor_cleanup(ov);
v = opts_visitor_new(opts);
visit_type_UserDefOptions(v, NULL, &f->userdef, &f->err);
visit_free(v);
qemu_opts_del(opts);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册