[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC 43/48] qemu-option: Functions to convert to/
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH RFC 43/48] qemu-option: Functions to convert to/from QDict. |
Date: |
Mon, 01 Mar 2010 10:24:50 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Luiz Capitulino <address@hidden> writes:
> On Wed, 24 Feb 2010 18:55:55 +0100
> Markus Armbruster <address@hidden> wrote:
>
>> FIXME Only string options are implemented.
>>
>> Signed-off-by: Markus Armbruster <address@hidden>
>> ---
>> qemu-option.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> qemu-option.h | 3 +++
>> 2 files changed, 57 insertions(+), 0 deletions(-)
>>
>> diff --git a/qemu-option.c b/qemu-option.c
>> index ab488e4..f86aac0 100644
>> --- a/qemu-option.c
>> +++ b/qemu-option.c
>> @@ -29,6 +29,8 @@
>> #include "qemu-common.h"
>> #include "qemu-error.h"
>> #include "qemu-option.h"
>> +#include "qobject.h"
>> +#include "qstring.h"
>>
>> /*
>> * Extracts the name of an option from the parameter string (p points at the
>> @@ -777,6 +779,58 @@ QemuOpts *qemu_opts_parse(QemuOptsList *list, const
>> char *params, const char *fi
>> return opts;
>> }
>>
>> +static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void
>> *opaque)
>> +{
>> + const char *value;
>> +
>> + if (!strcmp(key, "id")) {
>> + return;
>> + }
>> +
>> + switch (qobject_type(obj)) {
>> + case QTYPE_QSTRING:
>> + value = qstring_get_str(qobject_to_qstring(obj));
>> + break;
>> + default:
>> + abort(); // FIXME implement
>> + }
>> + qemu_opt_set(opaque, key, value);
>
> qstring_get_str() returns a pointer to the stored string, are you sure
> you want to pass it down without cloning it?
qemu_opt_set() strdups both its name and its value argument.
> We allow this violation in QString because most handlers that get a string
> wants only temporary read-only access. In this case the violation is very
> convenient, as otherwise we would have to add tons of free()s around.
>
>> +}
>> +
>> +QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict)
>> +{
>> + const char *id;
>> + QemuOpts *opts;
>> +
>> + id = qdict_haskey(qdict, "id") ? qdict_get_str(qdict, "id") : NULL;
>
> You should use qdict_get_try_str() here.
Yes, thanks.
>> + opts = qemu_opts_create(list, id, 1);
>> + if (opts == NULL)
>> + return NULL;
>> +
>> + qdict_iter(qdict, qemu_opts_from_qdict_1, opts);
>> + return opts;
>> +}
>> +
>> +static int qemu_opts_to_qdict_1(const char *name, const char *value,
>> + void *opaque)
>> +{
>> + qdict_put(opaque, name, qstring_from_str(value));
>> + // FIXME obey QemuOptType
>> + return 0;
>> +}
>> +
>> +QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict)
>> +{
>> + if (!qdict) {
>> + qdict = qdict_new();
>> + }
>> + if (opts->id) {
>> + qdict_put(qdict, "id", qstring_from_str(opts->id));
>> + }
>> + qemu_opt_foreach(opts, qemu_opts_to_qdict_1, qdict, 0);
>> + return qdict;
>> +}
>> +
>> /* Validate parsed opts against descriptions where no
>> * descriptions were provided in the QemuOptsList.
>> */
>> diff --git a/qemu-option.h b/qemu-option.h
>> index f3f1de7..d735386 100644
>> --- a/qemu-option.h
>> +++ b/qemu-option.h
>> @@ -28,6 +28,7 @@
>>
>> #include <stdint.h>
>> #include "qemu-queue.h"
>> +#include "qdict.h"
>>
>> enum QEMUOptionParType {
>> OPT_FLAG,
>> @@ -118,6 +119,8 @@ void qemu_opts_del(QemuOpts *opts);
>> int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
>> int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char
>> *firstname);
>> QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const
>> char *firstname);
>> +QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict);
>> +QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
>>
>> typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
>> int qemu_opts_print(QemuOpts *opts, void *dummy);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Qemu-devel] [PATCH RFC 43/48] qemu-option: Functions to convert to/from QDict.,
Markus Armbruster <=