1. 31 8月, 2018 1 次提交
  2. 04 7月, 2018 1 次提交
  3. 03 7月, 2018 1 次提交
  4. 22 6月, 2018 1 次提交
    • A
      qapi: allow empty branches in flat unions · 800877bb
      Anton Nefedov 提交于
      It often happens that just a few discriminator values imply extra data in
      a flat union. Existing checks did not make possible to leave other values
      uncovered. Such cases had to be worked around by either stating a dummy
      (empty) type or introducing another (subset) discriminator enumeration.
      
      Both options create redundant entities in qapi files for little profit.
      
      With this patch it is not necessary anymore to add designated union
      fields for every possible value of a discriminator enumeration.
      Signed-off-by: NAnton Nefedov <anton.nefedov@virtuozzo.com>
      Message-Id: <1529311206-76847-2-git-send-email-anton.nefedov@virtuozzo.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      800877bb
  5. 31 5月, 2018 1 次提交
  6. 27 3月, 2018 1 次提交
  7. 24 7月, 2017 1 次提交
  8. 19 6月, 2017 1 次提交
  9. 31 5月, 2017 2 次提交
    • M
      qapi: Reject alternates that can't work with keyval_parse() · c0644771
      Markus Armbruster 提交于
      Alternates are sum types like unions, but use the JSON type on the
      wire / QType in QObject instead of an explicit tag.  That's why we
      require alternate members to have distinct QTypes.
      
      The recently introduced keyval_parse() (commit d454dbe0) can only
      produce string scalars.  The qobject_input_visitor_new_keyval() input
      visitor mostly hides the difference, so code using a QObject input
      visitor doesn't have to care whether its input was parsed from JSON or
      KEY=VALUE,...  The difference leaks for alternates, as noted in commit
      0ee9ae7c: a non-string, non-enum scalar alternate value can't currently
      be expressed.
      
      In part, this is just our insufficiently sophisticated implementation.
      Consider alternate type 'GuestFileWhence'.  It has an integer member
      and a 'QGASeek' member.  The latter is an enumeration with values
      'set', 'cur', 'end'.  The meaning of b=set, b=cur, b=end, b=0, b=1 and
      so forth is perfectly obvious.  However, our current implementation
      falls apart at run time for b=0, b=1, and so forth.  Fixable, but not
      today; add a test case and a TODO comment.
      
      Now consider an alternate type with a string and an integer member.
      What's the meaning of a=42?  Is it the string "42" or the integer 42?
      Whichever meaning you pick makes the other inexpressible.  This isn't
      just an implementation problem, it's fundamental.  Our current
      implementation will pick string.
      
      So far, we haven't needed such alternates.  To make sure we stop and
      think before we add one that cannot sanely work with keyval_parse(),
      let's require alternate members to have sufficiently distinct
      representation in KEY=VALUE,... syntax:
      
      * A string member clashes with any other scalar member
      
      * An enumeration member clashes with bool members when it has value
        'on' or 'off'.
      
      * An enumeration member clashes with numeric members when it has a
        value that starts with '-', '+', or a decimal digit.  This is a
        rather lazy approximation of the actual number syntax accepted by
        the visitor.
      
        Note that enumeration values starting with '-' and '+' are rejected
        elsewhere already, but better safe than sorry.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1495471335-23707-5-git-send-email-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      c0644771
    • M
      tests/qapi-schema: Avoid 'str' in alternate test cases · 8168ca8e
      Markus Armbruster 提交于
      The next commit is going to make alternate members of type 'str'
      conflict with other scalar types.  Would break a few test cases that
      don't actually require 'str'.  Flip them from 'str' to 'bool' or
      'EnumOne'.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1495471335-23707-4-git-send-email-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      8168ca8e
  10. 16 3月, 2017 2 次提交
  11. 16 1月, 2017 1 次提交
    • M
      qapi: add qapi2texi script · 3313b612
      Marc-André Lureau 提交于
      As the name suggests, the qapi2texi script converts JSON QAPI
      description into a texi file suitable for different target
      formats (info/man/txt/pdf/html...).
      
      It parses the following kind of blocks:
      
      Free-form:
      
        ##
        # = Section
        # == Subsection
        #
        # Some text foo with *emphasis*
        # 1. with a list
        # 2. like that
        #
        # And some code:
        # | $ echo foo
        # | -> do this
        # | <- get that
        #
        ##
      
      Symbol description:
      
        ##
        # @symbol:
        #
        # Symbol body ditto ergo sum. Foo bar
        # baz ding.
        #
        # @param1: the frob to frobnicate
        # @param2: #optional how hard to frobnicate
        #
        # Returns: the frobnicated frob.
        #          If frob isn't frobnicatable, GenericError.
        #
        # Since: version
        # Notes: notes, comments can have
        #        - itemized list
        #        - like this
        #
        # Example:
        #
        # -> { "execute": "quit" }
        # <- { "return": {} }
        #
        ##
      
      That's roughly following the following EBNF grammar:
      
      api_comment = "##\n" comment "##\n"
      comment = freeform_comment | symbol_comment
      freeform_comment = { "# " text "\n" | "#\n" }
      symbol_comment = "# @" name ":\n" { member | tag_section | freeform_comment }
      member = "# @" name ':' [ text ] "\n" freeform_comment
      tag_section = "# " ( "Returns:", "Since:", "Note:", "Notes:", "Example:", "Examples:" ) [ text ]  "\n" freeform_comment
      text = free text with markup
      
      Note that the grammar is ambiguous: a line "# @foo:\n" can be parsed
      both as freeform_comment and as symbol_comment.  The actual parser
      recognizes symbol_comment.
      
      See docs/qapi-code-gen.txt for more details.
      
      Deficiencies and limitations:
      - the generated QMP documentation includes internal types
      - union type support is lacking
      - type information is lacking in generated documentation
      - doc comment error message positions are imprecise, they point
        to the beginning of the comment.
      - a few minor issues, all marked TODO/FIXME in the code
      Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20170113144135.5150-16-marcandre.lureau@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      [test-qapi.py tweaked to avoid trailing empty lines in .out]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      3313b612
  12. 19 7月, 2016 1 次提交
    • E
      qapi: Implement boxed types for commands/events · c818408e
      Eric Blake 提交于
      Turn on the ability to pass command and event arguments in
      a single boxed parameter, which must name a non-empty type
      (although the type can be a struct with all optional members).
      For structs, it makes it possible to pass a single qapi type
      instead of a breakout of all struct members (useful if the
      arguments are already in a struct or if the number of members
      is large); for other complex types, it is now possible to use
      a union or alternate as the data for a command or event.
      
      The empty type may be technically feasible if needed down the
      road, but it's easier to forbid it now and relax things to allow
      it later, than it is to allow it now and have to special case
      how the generated 'q_empty' type is handled (see commit 7ce106a9
      for reasons why nothing is generated for the empty type).  An
      alternate type is never considered empty, but now that a boxed
      type can be either an object or an alternate, we have to provide
      a trivial QAPISchemaAlternateType.is_empty().  The new call to
      arg_type.is_empty() during QAPISchemaCommand.check() requires
      that we first check the type in question; but there is no chance
      of introducing a cycle since objects do not refer back to commands.
      
      We still have a split in syntax checking between ad-hoc parsing
      up front (merely validates that 'boxed' has a sane value) and
      during .check() methods (if 'boxed' is set, then 'data' must name
      a non-empty user-defined type).
      
      Generated code is unchanged, as long as no client uses the
      new feature.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1468468228-27827-10-git-send-email-eblake@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      [Test files renamed to *-boxed-*]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      c818408e
  13. 18 3月, 2016 2 次提交
    • E
      qapi: Allow anonymous base for flat union · ac4338f8
      Eric Blake 提交于
      Rather than requiring all flat unions to explicitly create
      a separate base struct, we can allow the qapi schema to specify
      the common members via an inline dictionary. This is similar to
      how commands can specify an inline anonymous type for its 'data'.
      We already have several struct types that only exist to serve as
      a single flat union's base; the next commit will clean them up.
      In particular, this patch's change to the BlockdevOptions example
      in qapi-code-gen.txt will actually be done in the real QAPI schema.
      
      Now that anonymous bases are legal, we need to rework the
      flat-union-bad-base negative test (as previously written, it
      forms what is now valid QAPI; tweak it to now provide coverage
      of a new error message path), and add a positive test in
      qapi-schema-test to use an anonymous base (making the integer
      argument optional, for even more coverage).
      
      Note that this patch only allows anonymous bases for flat unions;
      simple unions are already enough syntactic sugar that we do not
      want to burden them further.  Meanwhile, while it would be easy
      to also allow an anonymous base for structs, that would be quite
      redundant, as the members can be put right into the struct
      instead.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1458254921-17042-15-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      ac4338f8
    • E
      qapi: Fix command with named empty argument type · 972a1101
      Eric Blake 提交于
      The generator special-cased
      
       { 'command':'foo', 'data': {} }
      
      to avoid emitting a visitor variable, but failed to see that
      
       { 'struct':'NamedEmptyType, 'data': {} }
       { 'command':'foo', 'data':'NamedEmptyType' }
      
      needs the same treatment.  There, the generator happily generates a
      visitor to get no arguments, and a visitor to destroy no arguments;
      and the compiler isn't happy with that, as demonstrated by the updated
      qapi-schema-test.json:
      
        tests/test-qmp-marshal.c: In function ‘qmp_marshal_user_def_cmd0’:
        tests/test-qmp-marshal.c:264:14: error: variable ‘v’ set but not used [-Werror=unused-but-set-variable]
             Visitor *v;
                      ^
      
      No change to generated code except for the testsuite addition.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1458254921-17042-3-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      972a1101
  14. 05 3月, 2016 1 次提交
  15. 19 2月, 2016 2 次提交
    • E
      qapi: Add tests of complex objects within alternate · 68d07839
      Eric Blake 提交于
      Upcoming patches will adjust how we visit an object branch of an
      alternate; but we were completely lacking testsuite coverage.
      Rectify this, so that the future patches will be able to highlight
      the changes and still prove that we avoided regressions.
      
      In particular, the use of a flat union UserDefFlatUnion rather
      than a simple struct UserDefA as the branch will give us coverage
      of an object with variants.  And visiting an alternate as both
      the top level and as a nested member gives confidence in correct
      memory allocation handling, especially if the test is run under
      valgrind.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1455778109-6278-5-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      68d07839
    • 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
  16. 17 12月, 2015 1 次提交
    • E
      qapi: Fix c_name() munging · c43567c1
      Eric Blake 提交于
      The method c_name() is supposed to do two different actions: munge
      '-' into '_', and add a 'q_' prefix to ticklish names.  But it did
      these steps out of order, making it possible to submit input that
      is not ticklish until after munging, where the output then lacked
      the desired prefix.
      
      The failure is exposed easily if you have a compiler that recognizes
      C11 keywords, and try to name a member '_Thread-local', as it would
      result in trying to compile the declaration 'uint64_t _Thread_local;'
      which is not valid.  However, this name violates our conventions
      (ultimately, want to enforce that no qapi names start with single
      underscore), so the test is slightly weaker by instead testing
      'wchar-t'; the declaration 'uint64_t wchar_t;' is valid in C (where
      wchar_t is only a typedef) but would fail with a C++ compiler (where
      it is a keyword).
      
      Fix things by reversing the order of actions within c_name().
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-18-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      c43567c1
  17. 09 11月, 2015 1 次提交
    • E
      qapi: Use generated TestStruct machinery in tests · 748053c9
      Eric Blake 提交于
      Commit d88f5fd1 and friends first introduced the various test-qmp-*
      tests in 2011, with duplicated hand-rolled TestStruct machinery,
      to make sure the qapi visitor interface was tested.  Later, commit
      4f193e34 in 2013 added a .json file for further testing use by the
      files, but without consolidating any of the existing hand-rolled
      visitors.  And with four copies, subtle differences have crept in,
      between the tests themselves (mainly whitespace differences, but
      also a question of whether to use NULL or "TestStruct" when
      calling visit_start_struct()) and from what the generator produces
      (the hand-rolled versions did not cater to partially-allocated
      objects, because they did not have a deallocation usage).
      
      Of course, just because the visitor interface is tested does not
      mean it is a sane interface; and future patches will be changing
      some of the visitor contracts.  Rather than having to duplicate
      the cleanup work in each copy of the TestStruct visitor, and keep
      each hand-rolled copy in sync with what the generator supplies, we
      might as well just test what the generator should give us in the
      first place.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1446791754-23823-2-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      748053c9
  18. 02 11月, 2015 1 次提交
    • E
      tests/qapi-schema: Test for reserved names, empty struct · 19767083
      Eric Blake 提交于
      Add some testsuite coverage to ensure future patches are on
      the right track:
      
      Our current C representation of qapi arrays is done by appending
      'List' to the element name; but we are not preventing the
      creation of an object type with the same name.  Add
      reserved-type-list.json to test this.  Then rename
      enum-union-clash.json to reserved-type-kind.json to cover the
      reservation that we DO detect, and shorten it to match the fact
      that the name is reserved even if there is no clash.
      
      We are failing to detect a collision between a dictionary member
      and the implicit 'has_*' flag for another optional member. The
      easiest fix would be for a future patch to reserve the entire
      "has[-_]" namespace for member names (the collision is also
      possible for branch names within flat unions, but only as long as
      branch names can collide with (non-variant) members; however,
      since future patches are about to remove that, it is not worth
      testing here). Add reserved-member-has.json to test this.
      
      A similar collision exists between a dictionary member where
      c_name() munges what might otherwise be a reserved name to start
      with 'q_', and another member explicitly starts with "q[-_]".
      Again, the easiest solution for a future patch will be reserving
      the entire namespace, but here for commands as well as members.
      Add reserved-member-q.json and reserved-command-q.json to test
      this; separate tests since arguably our munging of command 'unix'
      to 'qmp_q_unix()' could be done without a q_, which is different
      than the munging of a member 'unix' to 'foo.q_unix'.
      
      Finally, our testsuite does not have any compilation coverage
      of struct inheritance with empty qapi structs.  Update
      qapi-schema-test.json to test this.
      
      Note that there is currently no technical reason to forbid type
      name patterns from member names, or member name patterns from
      types, since the two are not in the same namespace in C and
      won't collide; but it's not worth adding positive tests of these
      corner cases at this time, especially while there is other churn
      pending in patches that rearrange which collisions actually
      happen.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1445898903-12082-2-git-send-email-eblake@redhat.com>
      [Commit message tweaked slightly]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      19767083
  19. 15 10月, 2015 4 次提交
    • E
      qapi: Lazy creation of array types · 9f08c8ec
      Eric Blake 提交于
      Commit ac88219a had several TODO markers about whether we needed
      to automatically create the corresponding array type alongside
      any other type.  It turns out that most of the time, we don't!
      
      There are a few exceptions: 1) We have a few situations where we
      use an array type in internal code but do not expose that type
      through QMP; fix it by declaring a dummy type that forces the
      generator to see that we want to use the array type.
      
      2) The builtin arrays (such as intList for QAPI ['int']) must
      always be generated, because of the way our QAPI_TYPES_BUILTIN
      compile guard works: we have situations (at the very least
      tests/test-qmp-output-visitor.c) that include both top-level
      "qapi-types.h" (via "error.h") and a secondary
      "test-qapi-types.h". If we were to only emit the builtin types
      when used locally, then the first .h file would not include all
      types, but the second .h does not declare anything at all because
      the first .h set QAPI_TYPES_BUILTIN, and we would end up with
      compilation error due to things like unknown type 'int8List'.
      
      Actually, we may need to revisit how we do type guards, and
      change from a single QAPI_TYPES_BUILTIN over to a different
      usage pattern that does one #ifdef per qapi type - right now,
      the only types that are declared multiple times between two qapi
      .json files for inclusion by a single .c file happen to be the
      builtin arrays.  But now that we have QAPI 'include' statements,
      it is logical to assume that we will soon reach a point where
      we want to reuse non-builtin types (yes, I'm thinking about what
      it will take to add introspection to QGA, where we will want to
      reuse the SchemaInfo type and friends).  One #ifdef per type
      will help ensure that generating the same qapi type into more
      than one qapi-types.h won't cause collisions when both are
      included in the same .c file; but we also have to solve how to
      avoid creating duplicate qapi-types.c entry points.  So that
      is a problem left for another day.
      
      Generated code for qapi-types and qapi-visit is drastically
      reduced; less than a third of the arrays that were blindly
      created were actually needed (a quick grep shows we dropped
      from 219 to 69 *List types), and the .o files lost more than
      30% of their bulk.  [For best results, diff the generated
      files with 'git diff --patience --no-index pre post'.]
      
      Interestingly, the introspection output is unchanged - this is
      because we already cull all types that are not indirectly
      reachable from a command or event, so introspection was already
      using only a subset of array types.  The subset of types
      introspected is now a much larger percentage of the overall set
      of array types emitted in qapi-types.h (since the larger set
      shrunk), but still not 100% (evidence that the array types
      emitted for our new Dummy structs, and the new struct itself,
      don't affect QMP).
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1444710158-8723-9-git-send-email-eblake@redhat.com>
      [Moved array info tracking to a later patch]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      9f08c8ec
    • E
      qapi: Drop redundant flat-union-reverse-define test · 70478cef
      Eric Blake 提交于
      As of commit 8c3f8e77, we test compilation of forward references
      for a struct base type (UserDefOne), flat union base type
      (UserDefUnionBase), and flat union branch type
      (UserDefFlatUnion2). The only remaining forward reference being
      tested for parsing in flat-union-reverse-define was a forward
      enum declaration.  Once we make sure that always compiles,
      the smaller parse-only test is redundant and can be deleted.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1444710158-8723-7-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      70478cef
    • E
      qapi: Drop redundant returns-int test · cae95eae
      Eric Blake 提交于
      qapi-schema-test was already testing that we could have a
      command returning int, but burned a command name in the whitelist.
      Merge the redundant positive test returns-int, and pick a name
      that reduces the whitelist size.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1444710158-8723-6-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      cae95eae
    • E
      qapi: Move empty-enum to compile-time test · 625b251c
      Eric Blake 提交于
      Rather than just asserting that we can parse an empty enum,
      let's also make sure we can compile it, by including it in
      qapi-schema-test.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1444710158-8723-5-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      625b251c
  20. 13 10月, 2015 2 次提交
    • E
      qapi: Test use of 'number' within alternates · 9c51b441
      Eric Blake 提交于
      Add some testsuite exposure for use of a 'number' as part of
      an alternate.  The current state of the tree has a few bugs
      exposed by this: our input parser depends on the ordering of
      how the qapi schema declared the alternate, and the parser
      does not accept integers for a 'number' in an alternate even
      though it does for numbers outside of an alternate.
      
      Mixing 'int' and 'number' in the same alternate is unusual,
      since both are supplied by json-numbers, but there does not
      seem to be a technical reason to forbid it given that our
      json lexer distinguishes between json-numbers that can be
      represented as an int vs. those that cannot.
      
      Improve the existing test_visitor_in_alternate() to match the
      style of the new test_visitor_in_alternate_number(), and to
      ensure full coverage of all possible qtype parsing.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-9-git-send-email-eblake@redhat.com>
      [Eric's follow-up fixes squashed in]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      9c51b441
    • E
      qapi: Test for various name collisions · d220fbcd
      Eric Blake 提交于
      Expose some weaknesses in the generator: we don't always forbid
      the generation of structs that contain multiple members that map
      to the same C or QMP name.  This has already been marked FIXME in
      qapi.py in commit d90675fa, but having more tests will make sure
      future patches produce desired behavior; and updating existing
      patches to better document things doesn't hurt, either.  Some of
      these collisions are already caught in the old-style parser
      checks, but ultimately we want all collisions to be caught in the
      new-style QAPISchema*.check() methods.
      
      This patch focuses on C struct members, and does not consider
      collisions between commands and events (affecting C function
      names), or even collisions between generated C type names with
      user type names (for things like automatic FOOList struct
      representing array types or FOOKind for an implicit enum).
      
      There are two types of struct collisions we want to catch:
       1) Collision between two keys in a JSON object. qapi.py prevents
          that within a single struct (see test duplicate-key), but it is
          possible to have collisions between a type's members and its
          base type's members (existing tests struct-base-clash,
          struct-base-clash-deep), and its flat union variant members
          (renamed test flat-union-clash-member).
       2) Collision between two members of the C struct that is generated
          for a given QAPI type:
          a) Multiple QAPI names map to the same C name (new test
             args-name-clash)
          b) A QAPI name maps to a C name that is used for another purpose
             (new tests flat-union-clash-branch, struct-base-clash-base,
             union-clash-data). We already fixed some such cases in commit
             0f61af3e and 1e6c1616, but more remain.
          c) Two C names generated for other purposes clash
             (updated test alternate-clash, new test union-clash-branches,
             union-clash-type, flat-union-clash-type)
      
      Ultimately, if we need to have a flat union where a tag value
      clashes with a base member name, we could change the generator to
      name the union (using 'foo.u.value' rather than 'foo.value') or
      otherwise munge the C name corresponding to tag values.  But
      unless such a need arises, it will probably be easier to just
      forbid these collisions.
      
      Some of these negative tests will be deleted later, and positive
      tests added to qapi-schema-test.json in their place, when the
      generator code is reworked to avoid particular code generation
      collisions in class 2).
      
      [Note that viewing this patch with git rename detection enabled
      may see some confusion due to renaming some tests while adding
      others, but where the content is similar enough that git picks
      the wrong pre- and post-patch files to associate]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1443565276-4535-6-git-send-email-eblake@redhat.com>
      [Improve commit message and comments a bit, drop an unrelated test]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      d220fbcd
  21. 21 9月, 2015 4 次提交
    • M
      qapi: Introduce a first class 'any' type · 28770e05
      Markus Armbruster 提交于
      It's first class, because unlike '**', it actually works, i.e. doesn't
      require 'gen': false.
      
      '**' will go away next.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      28770e05
    • M
      qapi-event: Convert to QAPISchemaVisitor, fixing data with base · 05f43a96
      Markus Armbruster 提交于
      Fixes events whose data is struct with base to include the struct's
      base members.  Test case is qapi-schema-test.json's event
      __org.qemu_x-command:
      
          { 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
      
          { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
            'data': { '__org.qemu_x-member2': 'str' } }
      
          { 'struct': '__org.qemu_x-Base',
            'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
      
      Patch's effect on generated qapi_event_send___org_qemu_x_event():
      
          -void qapi_event_send___org_qemu_x_event(const char *__org_qemu_x_member2,
          +void qapi_event_send___org_qemu_x_event(__org_qemu_x_Enum __org_qemu_x_member1,
          +                                        const char *__org_qemu_x_member2,
                                                   Error **errp)
           {
               QDict *qmp;
          @@ -224,6 +225,10 @@ void qapi_event_send___org_qemu_x_event(
                   goto clean;
               }
      
          +    visit_type___org_qemu_x_Enum(v, &__org_qemu_x_member1, "__org.qemu_x-member1", &local_err);
          +    if (local_err) {
          +        goto clean;
          +    }
               visit_type_str(v, (char **)&__org_qemu_x_member2, "__org.qemu_x-member2", &local_err);
               if (local_err) {
                   goto clean;
      
      Code is generated in a different order now, but that doesn't matter.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      05f43a96
    • M
      qapi-visit: Convert to QAPISchemaVisitor, fixing bugs · 441cbac0
      Markus Armbruster 提交于
      Fixes flat unions to visit the base's base members (the previous
      commit merely added them to the struct).  Same test case.
      
      Patch's effect on visit_type_UserDefFlatUnion():
      
           static void visit_type_UserDefFlatUnion_fields(Visitor *m, UserDefFlatUnion **obj, Error **errp)
           {
               Error *err = NULL;
      
          +    visit_type_int(m, &(*obj)->integer, "integer", &err);
          +    if (err) {
          +        goto out;
          +    }
               visit_type_str(m, &(*obj)->string, "string", &err);
               if (err) {
                   goto out;
      
      Test cases updated for the bug fix.
      
      Fixes alternates to generate a visitor for their implicit enumeration
      type.  None of them are currently used, obviously.  Example:
      block-core.json's BlockdevRef now generates
      visit_type_BlockdevRefKind().
      
      Code is generated in a different order now, and therefore has got a
      few new forward declarations.  Doesn't matter.
      
      The guard QAPI_VISIT_BUILTIN_VISITOR_DECL is renamed to
      QAPI_VISIT_BUILTIN.
      
      The previous commit's two ugly special cases exist here, too.  Mark
      both TODO.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      441cbac0
    • M
      qapi-types: Convert to QAPISchemaVisitor, fixing flat unions · 2b162ccb
      Markus Armbruster 提交于
      Fixes flat unions to get the base's base members.  Test case is from
      commit 2fc00432, in qapi-schema-test.json:
      
          { 'union': 'UserDefFlatUnion',
            'base': 'UserDefUnionBase',
            'discriminator': 'enum1',
            'data': { 'value1' : 'UserDefA',
                      'value2' : 'UserDefB',
                      'value3' : 'UserDefB' } }
      
          { 'struct': 'UserDefUnionBase',
            'base': 'UserDefZero',
            'data': { 'string': 'str', 'enum1': 'EnumOne' } }
      
          { 'struct': 'UserDefZero',
            'data': { 'integer': 'int' } }
      
      Patch's effect on UserDefFlatUnion:
      
           struct UserDefFlatUnion {
               /* Members inherited from UserDefUnionBase: */
          +    int64_t integer;
               char *string;
               EnumOne enum1;
               /* Own members: */
               union { /* union tag is @enum1 */
                   void *data;
                   UserDefA *value1;
                   UserDefB *value2;
                   UserDefB *value3;
               };
           };
      
      Flat union visitors remain broken.  They'll be fixed next.
      
      Code is generated in a different order now, but that doesn't matter.
      
      The two guards QAPI_TYPES_BUILTIN_STRUCT_DECL and
      QAPI_TYPES_BUILTIN_CLEANUP_DECL are replaced by just
      QAPI_TYPES_BUILTIN.
      
      Two ugly special cases for simple unions now stand out like sore
      thumbs:
      
      1. The type tag is named 'type' everywhere, except in generated C,
         where it's 'kind'.
      
      2. QAPISchema lowers simple unions to semantically equivalent flat
         unions.  However, the C generated for a simple unions differs from
         the C generated for its equivalent flat union, and we therefore
         need special code to preserve that pointless difference for now.
      
      Mark both TODO.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NDaniel P. Berrange <berrange@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      2b162ccb
  22. 15 9月, 2015 1 次提交
    • D
      qapi: allow override of default enum prefix naming · 351d36e4
      Daniel P. Berrange 提交于
      The camel_to_upper() method applies some heuristics to turn
      a mixed case type name into an all-uppercase name. This is
      used for example, to generate enum constant name prefixes.
      
      The heuristics don't also generate a satisfactory name
      though. eg
      
        { 'enum': 'QCryptoTLSCredsEndpoint',
          'data': ['client', 'server']}
      
      Results in Q_CRYPTOTLS_CREDS_ENDPOINT_CLIENT. This has
      an undesirable _ after the initial Q and is missing an
      _ between the CRYPTO & TLS strings.
      
      Rather than try to add more and more heuristics to try
      to cope with this, simply allow the QAPI schema to
      specify the desired enum constant prefix explicitly.
      
      eg
      
        { 'enum': 'QCryptoTLSCredsEndpoint',
          'prefix': 'QCRYPTO_TLS_CREDS_ENDPOINT',
          'data': ['client', 'server']}
      
      Now gives the QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT name.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      351d36e4
  23. 04 9月, 2015 4 次提交
  24. 15 5月, 2015 3 次提交