[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 12/21] qapi: Improve qobject input visitor error
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH 12/21] qapi: Improve qobject input visitor error reporting |
Date: |
Sat, 25 Feb 2017 10:08:59 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
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 <address@hidden>
> ---
> 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.
Reviewed-by: Eric Blake <address@hidden>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 20/21] qapi: Make input visitors detect unvisited list tails, (continued)
- [Qemu-devel] [PATCH 20/21] qapi: Make input visitors detect unvisited list tails, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 15/21] qom: Make object_property_set_qobject()'s input visitor strict, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 19/21] tests: Cover partial input visit of list, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 10/21] qapi: Clean up after commit 3d344c2, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 13/21] qapi: Drop string input visitor method optional(), Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 21/21] qapi: Improve qobject visitor documentation, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 12/21] qapi: Improve qobject input visitor error reporting, Markus Armbruster, 2017/02/23
- Re: [Qemu-devel] [PATCH 12/21] qapi: Improve qobject input visitor error reporting,
Eric Blake <=
- [Qemu-devel] [PATCH 18/21] tests-qobject-input-strict: Merge into test-qobject-input-visitor, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 11/21] qapi: Make QObject input visitor set *list reliably, Markus Armbruster, 2017/02/23
- [Qemu-devel] [PATCH 17/21] qapi: Drop unused non-strict qobject input visitor, Markus Armbruster, 2017/02/23
- Re: [Qemu-devel] [PATCH 00/21] qapi: QMP dispatch and input visitor work, no-reply, 2017/02/24