1. 19 2月, 2016 3 次提交
    • E
      qapi: Forbid empty unions and useless alternates · 02a57ae3
      Eric Blake 提交于
      Empty unions serve no purpose, and while we compile with gcc
      which permits them, strict C99 forbids them.  We happen to inject
      a dummy 'void *data' member into the C unions that represent QAPI
      unions and alternates, but we want to get rid of that member (it
      pollutes the namespace for no good reason), which would leave us
      with an empty union if the user didn't provide any branches.  While
      empty structs make sense in QAPI, empty unions don't add any
      expressiveness to the QMP language.  So prohibit them at parse
      time.  Update the documentation and testsuite to match.
      
      Note that the documentation already mentioned that alternates
      should have "two or more JSON data types"; so this also fixes
      the code to enforce that.  However, we have existing uses of a
      union type with only one branch, so the 2-or-more strictness
      is intentionally limited to alternates.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1455778109-6278-3-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      02a57ae3
    • E
      qapi: Simplify excess input reporting in input visitors · f96493b1
      Eric Blake 提交于
      When reporting that an unvisited member remains at the end of an
      input visit for a struct, we were using g_hash_table_find()
      coupled with a callback function that always returns true, to
      locate an arbitrary member of the hash table.  But if all we
      need is an arbitrary entry, we can get that from a single-use
      iterator, without needing a tautological callback function.
      
      Technically, our cast of &(GQueue *) to (void **) is not strict
      C (while void * must be able to hold all other pointers, nothing
      says a void ** has to be the same width or representation as a
      GQueue **).  The kosher way to write it would be the verbose:
      
          void *tmp;
          GQueue *any;
          if (g_hash_table_iter_next(&iter, NULL, &tmp)) {
              any = tmp;
      
      But our code base (not to mention glib itself) already has other
      cases of assuming that ALL pointers have the same width and
      representation, where a compiler would have to go out of its way
      to mis-compile our borderline behavior.
      Suggested-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <1455778109-6278-2-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      f96493b1
    • E
      qapi-visit: Honor prefix of discriminator enum · 9d3524b3
      Eric Blake 提交于
      When we added support for a user-specified prefix for an enum
      type (commit 351d36e4), we forgot to teach the qapi-visit code
      to honor that prefix in the case of using a prefixed enum as
      the discriminator for a flat union.  While there is still some
      on-list debate on whether we want to keep prefixes, we should
      at least make it work as long as it is still part of the code
      base.
      Reported-by: NDaniel P. Berrange <berrange@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1455665965-27638-1-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      9d3524b3
  2. 18 2月, 2016 37 次提交