1. 20 3月, 2018 2 次提交
    • M
      qapi: Replace qobject_to_X(o) by qobject_to(X, o) · 7dc847eb
      Max Reitz 提交于
      This patch was generated using the following Coccinelle script:
      
      @@
      expression Obj;
      @@
      (
      - qobject_to_qnum(Obj)
      + qobject_to(QNum, Obj)
      |
      - qobject_to_qstring(Obj)
      + qobject_to(QString, Obj)
      |
      - qobject_to_qdict(Obj)
      + qobject_to(QDict, Obj)
      |
      - qobject_to_qlist(Obj)
      + qobject_to(QList, Obj)
      |
      - qobject_to_qbool(Obj)
      + qobject_to(QBool, Obj)
      )
      
      and a bit of manual fix-up for overly long lines and three places in
      tests/check-qjson.c that Coccinelle did not find.
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      Message-Id: <20180224154033.29559-4-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      [eblake: swap order from qobject_to(o, X), rebase to master, also a fix
      to latent false-positive compiler complaint about hw/i386/acpi-build.c]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7dc847eb
    • M
      qapi: Add qobject_to() · 1a56b1e2
      Max Reitz 提交于
      This is a dynamic casting macro that, given a QObject type, returns an
      object as that type or NULL if the object is of a different type (or
      NULL itself).
      
      The macro uses lower-case letters because:
      1. There does not seem to be a hard rule on whether qemu macros have to
         be upper-cased,
      2. The current situation in qapi/qmp is inconsistent (compare e.g.
         QINCREF() vs. qdict_put()),
      3. qobject_to() will evaluate its @obj parameter only once, thus it is
         generally not important to the caller whether it is a macro or not,
      4. I prefer it aesthetically.
      
      The macro parameter order is chosen with typename first for
      consistency with other QAPI macros like QAPI_CLONE(), as well as
      for legibility (read it as "qobject to" type "applied to" obj).
      Signed-off-by: NMax Reitz <mreitz@redhat.com>
      Message-Id: <20180224154033.29559-3-mreitz@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NAlberto Garcia <berto@igalia.com>
      [eblake: swap parameter order to list type first, avoid clang ubsan
      warning on QOBJECT(NULL) and container_of(NULL,type,base)]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      1a56b1e2
  2. 19 3月, 2018 38 次提交