qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast
@ 2018-04-26 15:28 Markus Armbruster
  2018-04-26 15:49 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Markus Armbruster @ 2018-04-26 15:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcandre.lureau, eblake

The proper way to convert from (abstract) QObject to a (concrete)
subtype is qobject_to().  Look for offenders that type cast instead:

    $ git-grep '(Q[A-Z][a-z]* \*)'
    hmp.c:    qmp_device_add((QDict *)qdict, NULL, &err);
    include/qapi/qmp/qobject.h:        return (QObject *)obj;
    qobject/qobject.c:static void (*qdestroy[QTYPE__MAX])(QObject *) = {
    tests/check-qdict.c:    dst = (QDict *)qdict_crumple(src, &error_abort);

The first two cast away const, the third isn't a type cast.  Fix the
fourth.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 tests/check-qdict.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/check-qdict.c b/tests/check-qdict.c
index a0e0454684..eba5d3528e 100644
--- a/tests/check-qdict.c
+++ b/tests/check-qdict.c
@@ -657,7 +657,7 @@ static void qdict_crumple_test_empty(void)
 
     src = qdict_new();
 
-    dst = (QDict *)qdict_crumple(src, &error_abort);
+    dst = qobject_to(QDict, qdict_crumple(src, &error_abort));
 
     g_assert_cmpint(qdict_size(dst), ==, 0);
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast
  2018-04-26 15:28 [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast Markus Armbruster
@ 2018-04-26 15:49 ` Eric Blake
  2018-04-26 18:59 ` Marc-André Lureau
  2018-05-02  8:30 ` Markus Armbruster
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2018-04-26 15:49 UTC (permalink / raw)
  To: Markus Armbruster, qemu-devel; +Cc: marcandre.lureau

[-- Attachment #1: Type: text/plain, Size: 929 bytes --]

On 04/26/2018 10:28 AM, Markus Armbruster wrote:
> The proper way to convert from (abstract) QObject to a (concrete)
> subtype is qobject_to().  Look for offenders that type cast instead:
> 
>     $ git-grep '(Q[A-Z][a-z]* \*)'
>     hmp.c:    qmp_device_add((QDict *)qdict, NULL, &err);
>     include/qapi/qmp/qobject.h:        return (QObject *)obj;
>     qobject/qobject.c:static void (*qdestroy[QTYPE__MAX])(QObject *) = {
>     tests/check-qdict.c:    dst = (QDict *)qdict_crumple(src, &error_abort);
> 
> The first two cast away const, the third isn't a type cast.  Fix the
> fourth.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  tests/check-qdict.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast
  2018-04-26 15:28 [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast Markus Armbruster
  2018-04-26 15:49 ` Eric Blake
@ 2018-04-26 18:59 ` Marc-André Lureau
  2018-05-02  8:30 ` Markus Armbruster
  2 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2018-04-26 18:59 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, Blake, Eric

On Thu, Apr 26, 2018 at 5:28 PM, Markus Armbruster <armbru@redhat.com> wrote:
> The proper way to convert from (abstract) QObject to a (concrete)
> subtype is qobject_to().  Look for offenders that type cast instead:
>
>     $ git-grep '(Q[A-Z][a-z]* \*)'
>     hmp.c:    qmp_device_add((QDict *)qdict, NULL, &err);
>     include/qapi/qmp/qobject.h:        return (QObject *)obj;
>     qobject/qobject.c:static void (*qdestroy[QTYPE__MAX])(QObject *) = {
>     tests/check-qdict.c:    dst = (QDict *)qdict_crumple(src, &error_abort);
>
> The first two cast away const, the third isn't a type cast.  Fix the
> fourth.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  tests/check-qdict.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/check-qdict.c b/tests/check-qdict.c
> index a0e0454684..eba5d3528e 100644
> --- a/tests/check-qdict.c
> +++ b/tests/check-qdict.c
> @@ -657,7 +657,7 @@ static void qdict_crumple_test_empty(void)
>
>      src = qdict_new();
>
> -    dst = (QDict *)qdict_crumple(src, &error_abort);
> +    dst = qobject_to(QDict, qdict_crumple(src, &error_abort));
>
>      g_assert_cmpint(qdict_size(dst), ==, 0);
>
> --
> 2.13.6
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast
  2018-04-26 15:28 [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast Markus Armbruster
  2018-04-26 15:49 ` Eric Blake
  2018-04-26 18:59 ` Marc-André Lureau
@ 2018-05-02  8:30 ` Markus Armbruster
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Armbruster @ 2018-05-02  8:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcandre.lureau, eblake

Applied to qapi-next.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-02  8:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-26 15:28 [Qemu-devel] [PATCH] qobject: Use qobject_to() instead of type cast Markus Armbruster
2018-04-26 15:49 ` Eric Blake
2018-04-26 18:59 ` Marc-André Lureau
2018-05-02  8:30 ` Markus Armbruster

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).