From: Markus Armbruster <armbru@redhat.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH 07/10] Introduce QError
Date: Thu, 19 Nov 2009 09:42:27 +0100 [thread overview]
Message-ID: <m38we2aoss.fsf@crossbow.pond.sub.org> (raw)
In-Reply-To: <20091118152357.2d1dc535@doriath> (Luiz Capitulino's message of "Wed, 18 Nov 2009 15:23:57 -0200")
Luiz Capitulino <lcapitulino@redhat.com> writes:
> On Wed, 18 Nov 2009 16:16:11 +0100
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> Luiz Capitulino <lcapitulino@redhat.com> writes:
>
> [...]
>
>> > +static const char *append_field(QString *outstr, const QError *qerror,
>> > + const char *start)
>> > +{
>> > + QObject *obj;
>> > + QDict *qdict;
>> > + QString *key_qs;
>> > + const char *end, *key;
>> > +
>> > + if (*start != '%')
>> > + parse_error(qerror, '%');
>>
>> Can't happen, because it gets called only with *start == '%'. Taking
>> pointer to the character following the '%' as argument would sidestep
>> the issue. But I'm fine with leaving it as is.
>
> It's just an assertion.
It's not coded as an assertion. If we ever do coverage testing, it'll
stick out. But again, I'm fine with it.
>> > + start++;
>> > + if (*start != '(')
>> > + parse_error(qerror, '(');
>> > + start++;
>> > +
>> > + end = strchr(start, ')');
>> > + if (!end)
>> > + parse_error(qerror, ')');
>> > +
>> > + key_qs = qstring_from_substr(start, 0, end - start - 1);
>> > + key = qstring_get_str(key_qs);
>> > +
>> > + qdict = qobject_to_qdict(qdict_get(qerror->error, "data"));
>> > + obj = qdict_get(qdict, key);
>> > + if (!obj) {
>> > + qerror_abort(qerror, "key '%s' not found in QDict", key);
>> > + }
>> > +
>> > + switch (qobject_type(obj)) {
>> > + case QTYPE_QSTRING:
>> > + qstring_append(outstr, qdict_get_str(qdict, key));
>> > + break;
>> > + case QTYPE_QINT:
>> > + qstring_append_int(outstr, qdict_get_int(qdict, key));
>> > + break;
>> > + default:
>> > + qerror_abort(qerror, "invalid type '%c'", qobject_type(obj));
>> > + }
>> > +
>> > + QDECREF(key_qs);
>>
>> Looks like you create key_qs just because it's a convenient way to
>> extract key zero-terminated. Correct?
>
> Yes, as a substring of 'desc', which is passed through 'start'.
Funny that the convenient way to extract a substring is to go through
QString. Fine with me.
> [...]
>
>> > diff --git a/qjson.c b/qjson.c
>> > index 12e6cf0..60c904d 100644
>> > --- a/qjson.c
>> > +++ b/qjson.c
>> > @@ -224,6 +224,8 @@ static void to_json(const QObject *obj, QString *str)
>> > }
>> > break;
>> > }
>> > + case QTYPE_QERROR:
>> > + /* XXX: should QError be emitted? */
>>
>> Pros & cons?
>
> It's probably convenient to have qjson emitting QError, I'm unsure
> if we should do that for all kinds of QObjects though.
For a general purpose system, I'd recommend to cover all types. But as
long as this has just one user (QEMU), it can use the special purpose
excuse not to.
>> > case QTYPE_NONE:
>> > break;
>> > }
>> > diff --git a/qobject.h b/qobject.h
>> > index 2270ec1..07de211 100644
>> > --- a/qobject.h
>> > +++ b/qobject.h
>> > @@ -43,6 +43,7 @@ typedef enum {
>> > QTYPE_QLIST,
>> > QTYPE_QFLOAT,
>> > QTYPE_QBOOL,
>> > + QTYPE_QERROR,
>> > } qtype_code;
>> >
>> > struct QObject;
>>
>> Erroneous QERRs are detected only when they're passed to
>> qerror_from_info() at run-time, i.e. when the error happens. Likewise
>> for erroneous qerror_table[].desc. Perhaps a unit test to ensure
>> qerror_table[] is sane would make sense. Can't protect from passing
>> unknown errors to qerror_from_info(), but that shouldn't be a problem in
>> practice.
>
> We could also have a debug function that could run once at startup
> and do the check.
Yes.
next prev parent reply other threads:[~2009-11-19 8:42 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-17 19:43 [Qemu-devel] [PATCH 00/10]: QError v4 Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 01/10] QJSON: Introduce qobject_from_jsonv() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 02/10] QString: Introduce qstring_append_chr() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 03/10] QString: Introduce qstring_append_int() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 04/10] QString: Introduce qstring_from_substr() Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 05/10] utests: Add qstring_append_chr() unit-test Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 06/10] utests: Add qstring_from_substr() unit-test Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 07/10] Introduce QError Luiz Capitulino
2009-11-18 15:16 ` Markus Armbruster
2009-11-18 17:23 ` Luiz Capitulino
2009-11-19 8:42 ` Markus Armbruster [this message]
2009-11-19 12:59 ` [Qemu-devel] " Paolo Bonzini
2009-11-18 18:14 ` [Qemu-devel] " Daniel P. Berrange
2009-11-18 19:58 ` Anthony Liguori
2009-11-18 20:13 ` Luiz Capitulino
2009-11-17 19:43 ` [Qemu-devel] [PATCH 08/10] monitor: QError support Luiz Capitulino
2009-11-18 15:16 ` Markus Armbruster
2009-11-18 17:29 ` Luiz Capitulino
2009-11-18 18:16 ` Daniel P. Berrange
2009-11-17 19:43 ` [Qemu-devel] [PATCH 09/10] qdev: Use QError for 'device not found' error Luiz Capitulino
2009-11-18 15:17 ` Markus Armbruster
2009-11-18 17:32 ` Luiz Capitulino
2009-11-20 7:23 ` Amit Shah
2009-11-17 19:43 ` [Qemu-devel] [PATCH 10/10] monitor: do_info_balloon(): use QError Luiz Capitulino
2009-11-18 15:17 ` Markus Armbruster
2009-11-18 15:58 ` Anthony Liguori
2009-11-18 18:10 ` Luiz Capitulino
2009-11-18 16:06 ` [Qemu-devel] [PATCH 00/10]: QError v4 Markus Armbruster
2009-11-18 18:08 ` Anthony Liguori
2009-11-19 2:36 ` Jamie Lokier
2009-11-20 15:56 ` Anthony Liguori
2009-11-20 16:20 ` Luiz Capitulino
2009-11-20 16:27 ` Anthony Liguori
2009-11-20 17:57 ` Markus Armbruster
2009-11-20 17:29 ` Markus Armbruster
2009-11-20 17:37 ` Anthony Liguori
2009-11-19 10:11 ` Markus Armbruster
2009-11-20 16:13 ` Anthony Liguori
2009-11-20 18:47 ` Markus Armbruster
2009-11-20 19:04 ` Anthony Liguori
2009-11-21 10:02 ` Markus Armbruster
2009-11-22 16:08 ` Anthony Liguori
2009-11-23 13:06 ` Luiz Capitulino
2009-11-23 13:11 ` Anthony Liguori
2009-11-23 13:34 ` Luiz Capitulino
2009-11-23 13:50 ` Alexander Graf
2009-11-24 11:55 ` Luiz Capitulino
2009-11-24 12:13 ` Alexander Graf
2009-11-23 16:08 ` Markus Armbruster
2009-11-23 12:42 ` Luiz Capitulino
2009-11-23 16:15 ` Markus Armbruster
2009-11-18 18:13 ` [Qemu-devel] " Paolo Bonzini
2009-11-19 10:25 ` Markus Armbruster
2009-11-19 13:01 ` Paolo Bonzini
2009-11-19 14:11 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m38we2aoss.fsf@crossbow.pond.sub.org \
--to=armbru@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kraxel@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.