[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 4/8] qapi: Store Error in StackObject.h for qobject-input-visi
From: |
Kevin Wolf |
Subject: |
[PATCH v4 4/8] qapi: Store Error in StackObject.h for qobject-input-visitor |
Date: |
Fri, 17 Sep 2021 18:13:16 +0200 |
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
- [PATCH v4 0/8] qapi: Add support for aliases, Kevin Wolf, 2021/09/17
- [PATCH v4 1/8] qapi: Add interfaces for alias support to Visitor, Kevin Wolf, 2021/09/17
- [PATCH v4 4/8] qapi: Store Error in StackObject.h for qobject-input-visitor,
Kevin Wolf <=
- [PATCH v4 6/8] qapi: Revert an accidental change from list to view object, Kevin Wolf, 2021/09/17
- [PATCH v4 7/8] qapi: Add support for aliases, Kevin Wolf, 2021/09/17
- [PATCH v4 5/8] qapi: Apply aliases in qobject-input-visitor, Kevin Wolf, 2021/09/17
- [PATCH v4 3/8] qapi: Simplify full_name_nth() in qobject-input-visitor, Kevin Wolf, 2021/09/17
- [PATCH v4 2/8] qapi: Remember alias definitions in qobject-input-visitor, Kevin Wolf, 2021/09/17
- [PATCH v4 8/8] tests/qapi-schema: Test cases for aliases, Kevin Wolf, 2021/09/17