Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnIL1-00072e-4q for qemu-devel@nongnu.org; Thu, 04 Mar 2010 16:12:07 -0500 Received: from [199.232.76.173] (port=48865 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnIL0-00072W-SC for qemu-devel@nongnu.org; Thu, 04 Mar 2010 16:12:06 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnIKz-0000cU-FP for qemu-devel@nongnu.org; Thu, 04 Mar 2010 16:12:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8859) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NnIKy-0000cK-W8 for qemu-devel@nongnu.org; Thu, 04 Mar 2010 16:12:05 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o24LC4M1004217 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 4 Mar 2010 16:12:04 -0500 From: Markus Armbruster References: <1267718231-13303-1-git-send-email-armbru@redhat.com> <1267718231-13303-46-git-send-email-armbru@redhat.com> <20100304175506.33a6456c@redhat.com> Date: Thu, 04 Mar 2010 22:12:01 +0100 In-Reply-To: <20100304175506.33a6456c@redhat.com> (Luiz Capitulino's message of "Thu, 4 Mar 2010 17:55:06 -0300") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH 45/50] qemu-option: Functions to convert to/from QDict List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: qemu-devel@nongnu.org Luiz Capitulino writes: > On Thu, 4 Mar 2010 16:57:06 +0100 > Markus Armbruster wrote: > >> The functions are somewhat restricted. Good enough for the job at >> hand. We'll extend them when we need more. >> >> Signed-off-by: Markus Armbruster >> --- >> qemu-option.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ >> qemu-option.h | 3 ++ >> 2 files changed, 82 insertions(+), 0 deletions(-) >> >> diff --git a/qemu-option.c b/qemu-option.c >> index ab488e4..24bb19b 100644 >> --- a/qemu-option.c >> +++ b/qemu-option.c [...] >> +/* >> + * Convert from QemuOpts to QDict. >> + * The QDict values are of type QString. >> + * TODO We'll want to use types appropriate for opt->desc->type, but >> + * this is enough for now. >> + */ >> +QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict) >> +{ >> + QemuOpt *opt; >> + QObject *val; >> + >> + if (!qdict) { >> + qdict = qdict_new(); >> + } >> + if (opts->id) { >> + qdict_put(qdict, "id", qstring_from_str(opts->id)); >> + } >> + QTAILQ_FOREACH(opt, &opts->head, next) { >> + val = QOBJECT(qstring_from_str(opt->str)); >> + qdict_put_obj(qdict, opt->name, val); >> + } > > Why not just do: > > qdict_put(qdict, opt->name, qstring_from_str(opt->str)); I got a version without the TODO. Looks like this: QTAILQ_FOREACH(opt, &opts->head, next) { switch (opt->desc ? opt->desc->type : QEMU_OPT_STRING) { case QEMU_OPT_BOOL: val = QOBJECT(qbool_from_int(opt->value.boolean)); break; case QEMU_OPT_NUMBER: case QEMU_OPT_SIZE: // FIXME opts only uint64_t, qint only int64_t val = QOBJECT(qint_from_int(opt->value.uint)); break; default: val = QOBJECT(qstring_from_str(opt->str)); break; } qdict_put_obj(qdict, opt->name, val); } I dumbed it down to keep this series as simple as possible, and missed the simplification opportunity. Okay to leave it as is? [...]