From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, alex.bennee@linaro.org,
stefanha@redhat.com, peter.maydell@linaro.org,
Markus Armbruster <armbru@redhat.com>,
richard.henderson@linaro.org, pbonzini@redhat.com,
jsnow@redhat.com, philmd@linaro.org, thuth@redhat.com,
Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH 03/13] qobject/qlit: allow to hide dict or list entries
Date: Thu, 8 May 2025 13:25:10 -0700 [thread overview]
Message-ID: <49dc014b-bfd1-43de-8d0c-c916e178432a@linaro.org> (raw)
In-Reply-To: <aBy94N6JSwDj53mb@redhat.com>
On 5/8/25 7:21 AM, Daniel P. Berrangé wrote:
> On Wed, May 07, 2025 at 04:14:33PM -0700, Pierrick Bouvier wrote:
>> We add a new .hidden field to qlit entries, which gets ignored when
>> creating the associated QObject.
>> By default .hidden is 0, so it means the entry is visible. This way,
>> only potentially hidden elements need to be assigned.
>
> IMHO this feels like a somewhat dubious concept to have in the
> qobject code, as it is quite specialized to a single use case.
> A more general purpose approach would be to have some mechanism
> for cloning while applying a data filter, though I admit that
> may be more tedious to actually use.
>
It's the least worse solution I found, for conditionally defining the
schema.
Trying to dynamically create the qlit stuff with individual .push() was
a nightmare in code generator, so I dropped this idea.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> include/qobject/qlit.h | 12 ++++++++++++
>> qobject/qlit.c | 10 ++++++++--
>> 2 files changed, 20 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/qobject/qlit.h b/include/qobject/qlit.h
>> index c0676d5daf2..3b66c22013c 100644
>> --- a/include/qobject/qlit.h
>> +++ b/include/qobject/qlit.h
>> @@ -28,25 +28,37 @@ struct QLitObject {
>> QLitDictEntry *qdict;
>> QLitObject *qlist;
>> } value;
>> + bool hidden;
>> };
>>
>> struct QLitDictEntry {
>> const char *key;
>> QLitObject value;
>> + bool hidden;
>> };
>>
>> #define QLIT_QNULL \
>> { .type = QTYPE_QNULL }
>> #define QLIT_QBOOL(val) \
>> { .type = QTYPE_QBOOL, .value.qbool = (val) }
>> +#define QLIT_QBOOL_HIDDEN(val, cond) \
>> + { .type = QTYPE_QBOOL, .value.qbool = (val), .hidden = (cond) }
>> #define QLIT_QNUM(val) \
>> { .type = QTYPE_QNUM, .value.qnum = (val) }
>> +#define QLIT_QNUM_HIDDEN(val, cond) \
>> + { .type = QTYPE_QNUM, .value.qnum = (val), .hidden = (cond) }
>> #define QLIT_QSTR(val) \
>> { .type = QTYPE_QSTRING, .value.qstr = (val) }
>> +#define QLIT_QSTR_HIDDEN(val, cond) \
>> + { .type = QTYPE_QSTRING, .value.qstr = (val), .hidden = (cond) }
>> #define QLIT_QDICT(val) \
>> { .type = QTYPE_QDICT, .value.qdict = (val) }
>> +#define QLIT_QDICT_HIDDEN(val, cond) \
>> + { .type = QTYPE_QDICT, .value.qdict = (val), .hidden = (cond) }
>> #define QLIT_QLIST(val) \
>> { .type = QTYPE_QLIST, .value.qlist = (val) }
>> +#define QLIT_QLIST_HIDDEN(val, cond) \
>> + { .type = QTYPE_QLIST, .value.qlist = (val), .hidden = (cond) }
>>
>> bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs);
>>
>> diff --git a/qobject/qlit.c b/qobject/qlit.c
>> index a44f47eaa57..7b372c5ebaa 100644
>> --- a/qobject/qlit.c
>> +++ b/qobject/qlit.c
>> @@ -90,6 +90,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs)
>>
>> QObject *qobject_from_qlit(const QLitObject *qlit)
>> {
>> + g_assert(!qlit->hidden);
>> +
>> switch (qlit->type) {
>> case QTYPE_QNULL:
>> return QOBJECT(qnull());
>> @@ -102,7 +104,9 @@ QObject *qobject_from_qlit(const QLitObject *qlit)
>> QLitDictEntry *e;
>>
>> for (e = qlit->value.qdict; e->key; e++) {
>> - qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value));
>> + if (!e->hidden) {
>> + qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value));
>> + }
>> }
>> return QOBJECT(qdict);
>> }
>> @@ -111,7 +115,9 @@ QObject *qobject_from_qlit(const QLitObject *qlit)
>> QLitObject *e;
>>
>> for (e = qlit->value.qlist; e->type != QTYPE_NONE; e++) {
>> - qlist_append_obj(qlist, qobject_from_qlit(e));
>> + if (!e->hidden) {
>> + qlist_append_obj(qlist, qobject_from_qlit(e));
>> + }
>> }
>> return QOBJECT(qlist);
>> }
>> --
>> 2.47.2
>>
>
> With regards,
> Daniel
next prev parent reply other threads:[~2025-05-08 20:25 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 23:14 [PATCH 00/13] single-binary: make QAPI generated files common Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 01/13] qapi: introduce 'runtime_if' for QAPI json Pierrick Bouvier
2025-05-08 6:53 ` Philippe Mathieu-Daudé
2025-05-08 20:22 ` Pierrick Bouvier
2025-05-15 4:39 ` Markus Armbruster
2025-05-15 15:42 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 02/13] qapi/introspect: generate schema as a QObject directly Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 03/13] qobject/qlit: allow to hide dict or list entries Pierrick Bouvier
2025-05-08 14:21 ` Daniel P. Berrangé
2025-05-08 20:25 ` Pierrick Bouvier [this message]
2025-05-07 23:14 ` [PATCH 04/13] qapi/introspect: hide fields in schema Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 05/13] qapi/commands: register commands conditionally Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 06/13] qapi/visit: hide fields in JSON marshalling Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 07/13] qapi: add access to qemu/target-info.h Pierrick Bouvier
2025-05-08 6:57 ` Philippe Mathieu-Daudé
2025-05-07 23:14 ` [PATCH 08/13] qemu/target-info: implement missing helpers Pierrick Bouvier
2025-05-08 6:40 ` Philippe Mathieu-Daudé
2025-05-08 20:30 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 09/13] qapi: transform target specific 'if' in runtime checks Pierrick Bouvier
2025-05-08 6:44 ` Philippe Mathieu-Daudé
2025-05-08 14:40 ` Daniel P. Berrangé
2025-05-08 20:48 ` Pierrick Bouvier
2025-05-10 6:57 ` Markus Armbruster
2025-05-13 0:36 ` Pierrick Bouvier
2025-05-13 7:08 ` Markus Armbruster
2025-05-13 22:52 ` Pierrick Bouvier
2025-05-14 7:13 ` Markus Armbruster
2025-05-14 16:54 ` Pierrick Bouvier
2025-05-14 14:09 ` Markus Armbruster
2025-05-14 16:50 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 10/13] qapi: add weak stubs for target specific commands Pierrick Bouvier
2025-05-08 6:57 ` Philippe Mathieu-Daudé
2025-05-08 20:33 ` Pierrick Bouvier
2025-05-07 23:14 ` [PATCH 11/13] qapi: make all generated files common Pierrick Bouvier
2025-05-08 6:57 ` Philippe Mathieu-Daudé
2025-05-07 23:14 ` [PATCH 13/13] [ANNEX] build/qapi: after series Pierrick Bouvier
2025-05-07 23:33 ` [PATCH 00/13] single-binary: make QAPI generated files common Pierrick Bouvier
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=49dc014b-bfd1-43de-8d0c-c916e178432a@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=jsnow@redhat.com \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
/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).