qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, jsnow@redhat.com, armbru@redhat.com
Subject: [PATCH v4 4/8] qapi: Store Error in StackObject.h for qobject-input-visitor
Date: Fri, 17 Sep 2021 18:13:16 +0200	[thread overview]
Message-ID: <20210917161320.201086-5-kwolf@redhat.com> (raw)
In-Reply-To: <20210917161320.201086-1-kwolf@redhat.com>

StackObject.h is a GHashTable that stores all keys in the input that
haven't been consumed yet. If qobject_input_check_struct() still finds
any entry, an error is returned because the input was unexpected. The
value of hash table entries is currently unused (always NULL).

The next patch implements, amongst others, wildcard aliases that can
lead to situations where it can't be decided immediately if a value is
still used elsewhere or if a conflict (two values for one member) needs
to be reported.

Allow it to store an Error object in the hash table so that a good error
message is used for qobject_input_check_struct() if the value isn't
consumed elsewhere, but no error is reported if some other object does
consume the value.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qapi/qobject-input-visitor.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 3eb3b34894..90ebd2fe95 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -79,7 +79,14 @@ typedef struct StackObject {
     QObject *obj;                /* QDict or QList being visited */
     void *qapi; /* sanity check that caller uses same pointer */
 
-    GHashTable *h;              /* If @obj is QDict: unvisited keys */
+    /*
+     * If @obj is QDict:
+     * Keys are the unvisited keys. Values are Error objects to be
+     * returned in qobject_input_check_struct() if the value was not
+     * consumed, or NULL for a default error.
+     */
+    GHashTable *h;
+
     const QListEntry *entry;    /* If @obj is QList: unvisited tail */
     unsigned index;             /* If @obj is QList: list index of @entry */
 
@@ -318,7 +325,8 @@ static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
     QSIMPLEQ_INIT(&tos->aliases);
 
     if (qdict) {
-        h = g_hash_table_new(g_str_hash, g_str_equal);
+        h = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+                                  (GDestroyNotify) error_free);
         for (entry = qdict_first(qdict);
              entry;
              entry = qdict_next(qdict, entry)) {
@@ -345,13 +353,19 @@ static bool qobject_input_check_struct(Visitor *v, Error **errp)
     StackObject *tos = QSLIST_FIRST(&qiv->stack);
     GHashTableIter iter;
     const char *key;
+    Error *err;
 
     assert(tos && !tos->entry);
 
     g_hash_table_iter_init(&iter, tos->h);
-    if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) {
-        error_setg(errp, "Parameter '%s' is unexpected",
-                   full_name(qiv, key));
+    if (g_hash_table_iter_next(&iter, (void **)&key, (void **)&err)) {
+        if (err) {
+            g_hash_table_steal(tos->h, key);
+            error_propagate(errp, err);
+        } else {
+            error_setg(errp, "Parameter '%s' is unexpected",
+                       full_name(qiv, key));
+        }
         return false;
     }
     return true;
-- 
2.31.1



  parent reply	other threads:[~2021-09-17 16:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 16:13 [PATCH v4 0/8] qapi: Add support for aliases Kevin Wolf
2021-09-17 16:13 ` [PATCH v4 1/8] qapi: Add interfaces for alias support to Visitor Kevin Wolf
2021-09-17 16:13 ` [PATCH v4 2/8] qapi: Remember alias definitions in qobject-input-visitor Kevin Wolf
2021-09-17 16:13 ` [PATCH v4 3/8] qapi: Simplify full_name_nth() " Kevin Wolf
2021-09-17 16:13 ` Kevin Wolf [this message]
2021-09-17 16:13 ` [PATCH v4 5/8] qapi: Apply aliases " Kevin Wolf
2021-09-17 16:13 ` [PATCH v4 6/8] qapi: Revert an accidental change from list to view object Kevin Wolf
2021-09-17 16:13 ` [PATCH v4 7/8] qapi: Add support for aliases Kevin Wolf
2021-09-17 16:13 ` [PATCH v4 8/8] tests/qapi-schema: Test cases " Kevin Wolf
2021-10-01  9:28 ` [PATCH v4 0/8] qapi: Add support " Kevin Wolf
2021-10-26 21:23 ` John Snow
2021-10-27 10:31   ` Kevin Wolf
2021-10-27 15:34     ` John Snow

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=20210917161320.201086-5-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=armbru@redhat.com \
    --cc=jsnow@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).