[Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper

Marc-André Lureau posted 14 patches 8 years, 5 months ago
[Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper
Posted by Marc-André Lureau 8 years, 5 months ago
A step towards completeness.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 include/qapi/qmp/qdict.h | 4 +++-
 target/i386/cpu.c        | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 363e431106..6588c7f0c8 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -53,13 +53,15 @@ void qdict_destroy_obj(QObject *obj);
 #define qdict_put(qdict, key, obj) \
         qdict_put_obj(qdict, key, QOBJECT(obj))
 
-/* Helpers for int, bool, and string */
+/* Helpers for int, bool, null, and string */
 #define qdict_put_int(qdict, key, value) \
         qdict_put(qdict, key, qnum_from_int(value))
 #define qdict_put_bool(qdict, key, value) \
         qdict_put(qdict, key, qbool_from_bool(value))
 #define qdict_put_str(qdict, key, value) \
         qdict_put(qdict, key, qstring_from_str(value))
+#define qdict_put_null(qdict, key) \
+        qdict_put(qdict, key, qnull())
 
 /* High level helpers */
 double qdict_get_double(const QDict *qdict, const char *key);
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ddc45abd70..bec2009a9c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2454,7 +2454,7 @@ static QDict *x86_cpu_static_props(void)
 
     d = qdict_new();
     for (i = 0; props[i]; i++) {
-        qdict_put(d, props[i], qnull());
+        qdict_put_null(d, props[i]);
     }
 
     for (w = 0; w < FEATURE_WORDS; w++) {
@@ -2464,7 +2464,7 @@ static QDict *x86_cpu_static_props(void)
             if (!fi->feat_names[bit]) {
                 continue;
             }
-            qdict_put(d, fi->feat_names[bit], qnull());
+            qdict_put_null(d, fi->feat_names[bit]);
         }
     }
 
-- 
2.14.1.146.gd35faa819


Re: [Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper
Posted by Eduardo Habkost 8 years, 5 months ago
On Fri, Aug 25, 2017 at 12:59:00PM +0200, Marc-André Lureau wrote:
> A step towards completeness.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>

Now replying to the latest version:

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

-- 
Eduardo

Re: [Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper
Posted by Eric Blake 8 years, 5 months ago
On 08/25/2017 05:59 AM, Marc-André Lureau wrote:
> A step towards completeness.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
>  include/qapi/qmp/qdict.h | 4 +++-
>  target/i386/cpu.c        | 4 ++--
>  2 files changed, 5 insertions(+), 3 deletions(-)

Is it worth touching up scripts/coccinelle/qobject.cocci at the same time?

I guess we don't care about a qlist_append_null() variant?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper
Posted by Markus Armbruster 8 years, 5 months ago
Eric Blake <eblake@redhat.com> writes:

> On 08/25/2017 05:59 AM, Marc-André Lureau wrote:
>> A step towards completeness.
>> 
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  include/qapi/qmp/qdict.h | 4 +++-
>>  target/i386/cpu.c        | 4 ++--
>>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> Is it worth touching up scripts/coccinelle/qobject.cocci at the same time?

Let's keep it up-to-date.  I can do it when I apply.

> I guess we don't care about a qlist_append_null() variant?

Only if we have users.

Re: [Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper
Posted by Eric Blake 8 years, 5 months ago
On 08/30/2017 07:01 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
> 
>> On 08/25/2017 05:59 AM, Marc-André Lureau wrote:
>>> A step towards completeness.
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>>  include/qapi/qmp/qdict.h | 4 +++-
>>>  target/i386/cpu.c        | 4 ++--
>>>  2 files changed, 5 insertions(+), 3 deletions(-)
>>
>> Is it worth touching up scripts/coccinelle/qobject.cocci at the same time?
> 
> Let's keep it up-to-date.  I can do it when I apply.
> 
>> I guess we don't care about a qlist_append_null() variant?
> 
> Only if we have users.

Most (all?) of our qlist_ users tend to be heterogenous; we insert list
members that have the same type. I don't see anyone wanting a list of
all null objects any time soon; about the only reason to support it
would be if we wanted a list of the StrOrNull alternate type, where some
list elements can be null.  But you're right that we don't have to add
it now.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH v2 01/14] qdict: add qdict_put_null() helper
Posted by Markus Armbruster 8 years, 5 months ago
Markus Armbruster <armbru@redhat.com> writes:

> Eric Blake <eblake@redhat.com> writes:
>
>> On 08/25/2017 05:59 AM, Marc-André Lureau wrote:
>>> A step towards completeness.
>>> 
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> Reviewed-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>>  include/qapi/qmp/qdict.h | 4 +++-
>>>  target/i386/cpu.c        | 4 ++--
>>>  2 files changed, 5 insertions(+), 3 deletions(-)
>>
>> Is it worth touching up scripts/coccinelle/qobject.cocci at the same time?
>
> Let's keep it up-to-date.  I can do it when I apply.

Squashing in the appended patch.  I verified it produces exactly the
change to target/i386/cpu.c Marc-André did manually, and no others.


diff --git a/scripts/coccinelle/qobject.cocci b/scripts/coccinelle/qobject.cocci
index c518caf7b1..1120eb1a42 100644
--- a/scripts/coccinelle/qobject.cocci
+++ b/scripts/coccinelle/qobject.cocci
@@ -20,6 +20,9 @@ expression Obj, Key, E;
 |
 - qdict_put(Obj, Key, qstring_from_str(E));
 + qdict_put_str(Obj, Key, E);
+|
+- qdict_put(Obj, Key, qnull());
++ qdict_put_null(Obj, Key);
 )
 
 // Use QList macros where they make sense