From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 12/21] qapi: Improve qobject input visitor error reporting
Date: Mon, 27 Feb 2017 06:31:38 +0100 [thread overview]
Message-ID: <87varwnqrp.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <d05878a3-d77a-627d-9f94-a0fdf175e280@redhat.com> (Eric Blake's message of "Sat, 25 Feb 2017 10:08:59 -0600")
Eric Blake <eblake@redhat.com> writes:
> On 02/23/2017 03:45 PM, Markus Armbruster wrote:
>> Error messages refer to nodes of the QObject being visited by name.
>> Trouble is the names are sometimes less than helpful:
>>
>
>> Improve error messages by referring to nodes by path instead, as
>> follows:
>>
>> * The path of the root QObject is whatever @name argument got passed
>> to the visitor, except NULL gets mapped to "<anonymous>".
>>
>> * The path of a root QDict's member is the member key.
>>
>> * The path of a root QList's member is "[%zu]", where %zu is the list
>> index, starting at zero.
>>
>> * The path of a non-root QDict's member is the path of the QDict
>> concatenated with "." and the member key.
>>
>> * The path of a non-root QList's member is the path of the QList
>> concatenated with "[%zu]", where %zu is the list index.
>>
>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>> include/qapi/visitor.h | 6 ---
>> qapi/qobject-input-visitor.c | 121 +++++++++++++++++++++++++++++++------------
>> 2 files changed, 87 insertions(+), 40 deletions(-)
>>
>
>> +typedef struct StackObject {
>> + const char *name; /* Name of @obj in its parent, if any */
>> + QObject *obj; /* QDict or QList being visited */
>> void *qapi; /* sanity check that caller uses same pointer */
>>
>> - GHashTable *h; /* If obj is dict: unvisited keys */
>> - const QListEntry *entry; /* If obj is list: unvisited tail */
>> + GHashTable *h; /* If @obj is QDict: unvisited keys */
>> + const QListEntry *entry; /* If @obj is QList: unvisited tail */
>> + unsigned index; /* If @obj is QList: list index of @entry */
>
> Could perhaps make the QDict vs. QList fields shared through a union if
> we were tight on storage space or cache line pressure. I don't think
> that's the case, though, so no need to change it.
>
>> +static const char *full_name(QObjectInputVisitor *qiv, const char *name)
>> +{
>> + StackObject *so;
>> + char buf[32];
>> +
>> + if (qiv->errname) {
>> + g_string_truncate(qiv->errname, 0);
>> + } else {
>> + qiv->errname = g_string_new("");
>> + }
>> +
>> + QSLIST_FOREACH(so , &qiv->stack, node) {
>> + if (qobject_type(so->obj) == QTYPE_QDICT) {
>> + g_string_prepend(qiv->errname, name);
>> + g_string_prepend_c(qiv->errname, '.');
>> + } else {
>> + snprintf(buf, sizeof(buf), "[%u]", so->index);
>> + g_string_prepend(qiv->errname, buf);
>> + }
>> + name = so->name;
>> + }
>
> Building the string from back to front requires quite a bit of memory
> reshuffling, as well as the temporary buffer for integer formatting. Is
> there any way to build it from front to back? But this code is only
> triggered on error paths, so I don't care if it is slow. I'm fine with
> what you have.
I opted for simplicity over speed here.
The easiest way to support forward iteration would be making the stack
doubly linked. Fairly cheap, but it's doubtful whether it would be an
amortized win.
An obvious alternative: measure the stack depth, allocate a char *[],
fill it with names back to front, format front to back. Not too
complicated, but is it worth on an error path?
However, users exist that try one visit, and if it fails, another one.
For instance, set_pci_devfn() tries visit_type_str() first, then
visit_type_int32. It should arguably use a suitable
visit_start_alternate() instead.
I think we should hunt down such visitor misuses before we complicate
error paths for speed.
In general,
foo(..., &err);
if (err) {
error_free(err);
...
}
is a performance anti-pattern, because it allocates and frees an Error
object, a message string and whatever it takes to build that just to
transmit one bit of information.
It's better to have foo() return something:
if (foo(..., NULL)) {
...
}
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks!
next prev parent reply other threads:[~2017-02-27 5:31 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-23 21:44 [Qemu-devel] [PATCH 00/21] qapi: QMP dispatch and input visitor work Markus Armbruster
2017-02-23 21:44 ` [Qemu-devel] [PATCH 01/21] qga: Fix crash on non-dictionary QMP argument Markus Armbruster
2017-02-23 22:46 ` Eric Blake
2017-02-23 22:50 ` Eric Blake
2017-02-24 6:07 ` Markus Armbruster
2017-02-23 21:44 ` [Qemu-devel] [PATCH 02/21] libqtest: Work around a "QMP wants a newline" bug Markus Armbruster
2017-02-23 22:59 ` Eric Blake
2017-02-23 21:44 ` [Qemu-devel] [PATCH 03/21] qmp-test: New, covering basic QMP protocol Markus Armbruster
2017-02-23 23:05 ` Eric Blake
2017-02-24 6:12 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 04/21] qmp: Dumb down how we run QMP command registration Markus Armbruster
2017-02-24 19:39 ` Eric Blake
2017-02-24 20:21 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 05/21] qmp: Clean up how we enforce capability negotiation Markus Armbruster
2017-02-24 21:56 ` Eric Blake
2017-02-25 6:33 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 06/21] qmp: Drop duplicated QMP command object checks Markus Armbruster
2017-02-24 23:03 ` Eric Blake
2017-02-25 6:37 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 07/21] qmp: Eliminate silly QERR_QMP_* macros Markus Armbruster
2017-02-24 23:11 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 08/21] qmp: Improve QMP dispatch error messages Markus Armbruster
2017-02-24 23:13 ` Eric Blake
2017-02-25 6:39 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 09/21] qapi: Improve a QObject input visitor error message Markus Armbruster
2017-02-25 15:44 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 10/21] qapi: Clean up after commit 3d344c2 Markus Armbruster
2017-02-25 15:45 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 11/21] qapi: Make QObject input visitor set *list reliably Markus Armbruster
2017-02-25 15:56 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 12/21] qapi: Improve qobject input visitor error reporting Markus Armbruster
2017-02-25 16:08 ` Eric Blake
2017-02-27 5:31 ` Markus Armbruster [this message]
2017-02-23 21:45 ` [Qemu-devel] [PATCH 13/21] qapi: Drop string input visitor method optional() Markus Armbruster
2017-02-25 16:12 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 14/21] qapi: Make string input and opts visitor require non-null input Markus Armbruster
2017-02-25 16:14 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 15/21] qom: Make object_property_set_qobject()'s input visitor strict Markus Armbruster
2017-02-25 16:15 ` Eric Blake
2017-02-23 21:45 ` [Qemu-devel] [PATCH 16/21] test-qobject-input-visitor: Use strict visitor Markus Armbruster
2017-02-25 16:30 ` Eric Blake
2017-02-27 5:35 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 17/21] qapi: Drop unused non-strict qobject input visitor Markus Armbruster
2017-02-24 9:27 ` Paolo Bonzini
2017-02-24 15:02 ` Markus Armbruster
2017-02-25 21:16 ` Eric Blake
2017-02-27 5:46 ` Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 18/21] tests-qobject-input-strict: Merge into test-qobject-input-visitor Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 19/21] tests: Cover partial input visit of list Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 20/21] qapi: Make input visitors detect unvisited list tails Markus Armbruster
2017-02-23 21:45 ` [Qemu-devel] [PATCH 21/21] qapi: Improve qobject visitor documentation Markus Armbruster
2017-02-24 19:49 ` [Qemu-devel] [PATCH 00/21] qapi: QMP dispatch and input visitor work no-reply
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=87varwnqrp.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@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.