1. 17 12月, 2015 23 次提交
    • E
      qapi: Don't let implicit enum MAX member collide · 7fb1cf16
      Eric Blake 提交于
      Now that we guarantee the user doesn't have any enum values
      beginning with a single underscore, we can use that for our
      own purposes.  Renaming ENUM_MAX to ENUM__MAX makes it obvious
      that the sentinel is generated.
      
      This patch was mostly generated by applying a temporary patch:
      
      |diff --git a/scripts/qapi.py b/scripts/qapi.py
      |index e6d014b..b862ec9 100644
      |--- a/scripts/qapi.py
      |+++ b/scripts/qapi.py
      |@@ -1570,6 +1570,7 @@ const char *const %(c_name)s_lookup[] = {
      |     max_index = c_enum_const(name, 'MAX', prefix)
      |     ret += mcgen('''
      |     [%(max_index)s] = NULL,
      |+// %(max_index)s
      | };
      | ''',
      |                max_index=max_index)
      
      then running:
      
      $ cat qapi-{types,event}.c tests/test-qapi-types.c |
          sed -n 's,^// \(.*\)MAX,s|\1MAX|\1_MAX|g,p' > list
      $ git grep -l _MAX | xargs sed -i -f list
      
      The only things not generated are the changes in scripts/qapi.py.
      
      Rejecting enum members named 'MAX' is now useless, and will be dropped
      in the next patch.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-23-git-send-email-eblake@redhat.com>
      Reviewed-by: NJuan Quintela <quintela@redhat.com>
      [Rebased to current master, commit message tweaked]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      7fb1cf16
    • E
      qapi: Tighten the regex on valid names · 59a92fee
      Eric Blake 提交于
      We already documented that qapi names should match specific
      patterns (such as starting with a letter unless it was an enum
      value or a downstream extension).  Tighten that from a suggestion
      into a hard requirement, which frees up names beginning with a
      single underscore for qapi internal usage.
      
      The tighter regex doesn't forbid everything insane that a user
      could provide (for example, a user could name a type 'Foo-lookup'
      to collide with the generated 'Foo_lookup[]' for an enum 'Foo'),
      but does a good job at protecting the most obvious uses, and
      also happens to reserve single leading underscore for later use.
      
      The handling of enum values starting with a digit is tricky:
      commit 9fb081e0 introduced a subtle bug by using c_name() on
      a munged value, which would allow an enum to include the
      member 'q-int' in spite of our reservation.  Furthermore,
      munging with a leading '_' would fail our tighter regex.  So
      fix it by only munging for leading digits (which are never
      ticklish in c_name()) and by using a different prefix (I
      picked 'D', although any letter should do).
      
      Add new tests, reserved-member-underscore and reserved-enum-q,
      to demonstrate the tighter checking.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-22-git-send-email-eblake@redhat.com>
      Message-Id: <1447883135-18020-1-git-send-email-eblake@redhat.com>
      [Eric's fixup squashed in]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      59a92fee
    • E
      blkdebug: Avoid '.' in enum values · 5be5b776
      Eric Blake 提交于
      Our qapi conventions document that '.' should only be used in
      the prefix of downstream names.  BlkdebugEvent was a lone
      exception to this.  Changing this is not backwards compatible
      to the 'blockdev-add' QMP command; however, that command is
      not yet fully stable.  It can also be argued that the testsuite
      is the biggest user of blkdebug, and that any other user can
      be taught to deal with the change by paying attention to
      introspection results.
      
      Done with:
      
      $ for str in \
           l1_grow.{alloc,write,activate}_table \
           l2_alloc.{cow_read,write} \
           refblock_alloc.{hookup,write,write_blocks,write_table,switch_table} \
           pwritev_rmw.{head,after_head,tail,after_tail}; do
         str1=$(echo "$str" | sed 's/\./\\./')
         str2=$(echo "$str" | sed 's/\./_/')
         git grep -l "$str1" | xargs -r sed -i "s/$str1/$str2/g"
       done
      
      followed by a manual touchup to test 77 to keep the test working.
      Reported-by: NMarkus Armbruster <armbru@redhat.com>
      CC: Kevin Wolf <kwolf@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-21-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      5be5b776
    • E
      blkdebug: Merge hand-rolled and qapi BlkdebugEvent enum · a31939e6
      Eric Blake 提交于
      No need to keep two separate enums, where editing one is likely
      to forget the other.  Now that we can specify a qapi enum prefix,
      we don't even have to change the bulk of the uses.
      
      get_event_by_name() could perhaps be replaced by qapi_enum_parse(),
      but I left that for another day.
      
      CC: Kevin Wolf <kwolf@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-20-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      a31939e6
    • E
      qapi: Remove dead visitor code · 75494572
      Eric Blake 提交于
      Commit cbc95538 removed unused start_handle() and end_handle(),
      but forgot to remove their declarations.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-19-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      75494572
    • 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
    • E
      qapi: Detect collisions in C member names · 27b60ab9
      Eric Blake 提交于
      Detect attempts to declare two object members that would result
      in the same C member name, by keying the 'seen' dictionary off
      of the C name rather than the qapi name.  It also requires passing
      info through the check_clash() methods.
      
      This addresses a TODO and fixes the previously-broken
      args-name-clash test.  The resulting error message demonstrates
      the utility of the .describe() method added previously.  No change
      to generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-17-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      27b60ab9
    • E
      qapi: Track owner of each object member · 88d4ef8b
      Eric Blake 提交于
      Future commits will migrate semantic checking away from parsing
      and over to the various QAPISchema*.check() methods.  But to
      report an error message about an incorrect semantic use of a
      member of an object type, it helps to know which type, command,
      or event owns the member.  In particular, when a member is
      inherited from a base type, it is desirable to associate the
      member name with the base type (and not the type calling
      member.check()).
      
      Rather than packing additional information into the seen array
      passed to each member.check() (as in seen[m.name] = {'member':m,
      'owner':type}), it is easier to have each member track the name
      of the owner type in the first place (keeping things simpler
      with the existing seen[m.name] = m).  The new member.owner field
      is set via a new set_owner() method, called when registering
      the members and variants arrays with an object or variant type.
      Track only a name, and not the actual type object, to avoid
      creating a circular python reference chain.
      
      Note that Variants.set_owner() method does not set the owner
      for the tag_member field; this field is set earlier either as
      part of an object's non-variant members, or explicitly by
      alternates.
      
      The source information is intended for human consumption in
      error messages, and a new describe() method is added to access
      the resulting information.  For example, given the qapi:
        { 'command': 'foo', 'data': { 'string': 'str' } }
      an implementation of visit_command() that calls
        arg_type.members[0].describe()
      will see "'string' (parameter of foo)".
      
      To make the human-readable name of implicit types work without
      duplicating efforts, the describe() method has to reverse the
      name of implicit types, via the helper _pretty_owner().
      
      No change to generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-16-git-send-email-eblake@redhat.com>
      [Incorrect & unused -wrapper case in _pretty_owner() dropped]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      88d4ef8b
    • E
      qapi: Remove outdated tests related to QMP/branch collisions · 61a94661
      Eric Blake 提交于
      Now that branches are in a separate C namespace, we can remove
      the restrictions in the parser that claim a branch name would
      collide with QMP, and delete the negative tests that are no
      longer problematic.  A separate patch can then add positive
      tests to qapi-schema-test to test that any corner cases will
      compile correctly.
      
      This reverts the scripts/qapi.py portion of commit 7b2a5c2f,
      now that the assertions that it plugged are no longer possible.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-15-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      61a94661
    • E
      qapi: Hoist tag collision check to Variants.check() · 10565ca9
      Eric Blake 提交于
      Checking that a given QAPISchemaObjectTypeVariant.name is a
      member of the corresponding QAPISchemaEnumType of the owning
      QAPISchemaObjectTypeVariants.tag_member ensures that there are
      no collisions in the generated C union for those tag values
      (since the enum itself should have no collisions).
      
      However, ever since its introduction in f51d8c3d, this was the
      only additional action of of Variant.check(), beyond calling
      the superclass Member.check().  This forces a difference in
      .check() signatures, just to pass the enum type down.
      
      Simplify things by instead doing the tag name check as part of
      Variants.check(), at which point we can rely on inheritance
      instead of overriding Variant.check().
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-14-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      10565ca9
    • E
      qapi: Factor out QAPISchemaObjectType.check_clash() · c2183d2e
      Eric Blake 提交于
      Consolidate two common sequences of clash detection into a
      new QAPISchemaObjectType.check_clash() helper method.
      
      No change to generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-13-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      c2183d2e
    • E
      qapi: Check for QAPI collisions involving variant members · b807a1e1
      Eric Blake 提交于
      Right now, our ad hoc parser ensures that we cannot have a
      flat union that introduces any members that would clash with
      non-variant members inherited from the union's base type (see
      flat-union-clash-member.json).  We want QAPISchemaObjectType.check()
      to make the same check, so we can later reduce some of the ad
      hoc checks.
      
      We already have a map 'seen' of all non-variant members. We
      still need to check for collisions between each variant type's
      members and the non-variant ones.
      
      To know the variant type's members, we need to call
      variant.type.check().  This also detects when a type contains
      itself in a variant, exactly like the existing base.check()
      detects when a type contains itself as a base.  (Except that
      we currently forbid anything but a struct as the type of a
      variant, so we can't actually trigger this type of loop yet.)
      
      Slight complication: an alternate's variant can have arbitrary
      type, but only an object type's check() may be called outside
      QAPISchema.check(). We could either skip the call for variants
      of alternates, or skip it for non-object types.  For now, do
      the latter, because it's easier.
      
      Then we call each variant member's check_clash() with the
      appropriate 'seen' map.  Since members of different variants
      can't clash, we have to clone a fresh seen for each variant.
      Wrap this in a new helper method
      QAPISchemaObjectTypeVariants.check_clash().
      
      Note that cloning 'seen' inside .check_clash() resembles
      the one we just removed from .check() in 'qapi: Drop
      obsolete tag value collision assertions'; the difference here is
      that we are now checking for clashes among the qapi members of
      the variant type, rather than for a single clash with the variant
      tag name itself.
      
      Note that, by construction, collisions can't actually happen for
      simple unions: each variant's type is a wrapper with a single
      member 'data', which will never collide with the only non-variant
      member 'type'.
      
      For alternates, there's nothing for a variant object type's
      members to clash with, and therefore no need to call the new
      variants.check_clash().
      
      No change to generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-12-git-send-email-eblake@redhat.com>
      [Commit message tweaked]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      b807a1e1
    • M
      qapi: Simplify QAPISchemaObjectTypeVariants.check() · 14ff8461
      Markus Armbruster 提交于
      Reduce the ugly flat union / simple union conditional by doing just
      the essential work here, namely setting self.tag_member.
      Move the rest to callers.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-7-git-send-email-armbru@redhat.com>
      [rebase to earlier changes that moved tag_member.check() of
      alternate types, and tweak commit title and wording]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-11-git-send-email-eblake@redhat.com>
      14ff8461
    • M
      qapi: Factor out QAPISchemaObjectTypeMember.check_clash() · 577de12d
      Markus Armbruster 提交于
      While there, stick in a TODO change key of seen from QAPI name to C
      name.  Can't do it right away, because it would fail the assertion for
      tests/qapi-schema/args-has-clash.json.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-6-git-send-email-armbru@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-10-git-send-email-eblake@redhat.com>
      577de12d
    • M
      qapi: Eliminate QAPISchemaObjectType.check() variable members · 23a4b2c6
      Markus Armbruster 提交于
      We can use seen.values() instead if we make it an OrderedDict.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-5-git-send-email-armbru@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-9-git-send-email-eblake@redhat.com>
      23a4b2c6
    • M
      qapi: Fix up commit 7618b91f's clash sanity checking change · 08683353
      Markus Armbruster 提交于
      This hunk
      
          @@ -964,6 +965,7 @@ class QAPISchemaObjectType(QAPISchemaType):
                       members = []
                   seen = {}
                   for m in members:
          +            assert c_name(m.name) not in seen
                       seen[m.name] = m
                   for m in self.local_members:
                       m.check(schema, members, seen)
      
      is plainly broken.
      
      Asserting the members inherited from base don't clash is somewhat
      redundant, because self.base.check() just checked that.  But it
      doesn't hurt.
      
      The idea to use c_name(m.name) instead of m.name for collision
      checking is sound, because we need to catch clashes between the m.name
      and between the c_name(m.name), and when two m.name clash, then their
      c_name() also clash.
      
      However, using c_name(m.name) instead of m.name in one of several
      places doesn't work.  See the very next line.
      
      Keep the assertion, but drop the c_name() for now.  A future commit
      will bring it back.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-4-git-send-email-armbru@redhat.com>
      [change TABs in commit message to space]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-8-git-send-email-eblake@redhat.com>
      08683353
    • M
      qapi: Clean up after previous commit · cdc5fa37
      Markus Armbruster 提交于
      QAPISchemaObjectTypeVariants.check() parameter members and
      QAPISchemaObjectTypeVariant.check() parameter seen are no longer used,
      drop them.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-3-git-send-email-armbru@redhat.com>
      [rebase to earlier changes that moved tag_member.check() of
      alternate types]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-7-git-send-email-eblake@redhat.com>
      cdc5fa37
    • M
      qapi: Simplify QAPISchemaObjectTypeMember.check() · e564e2dd
      Markus Armbruster 提交于
      QAPISchemaObjectTypeMember.check() currently does four things:
      
      1. Compute self.type
      
      2. Accumulate members in all_members
      
         Only one caller cares: QAPISchemaObjectType.check() uses it to
         compute self.members.  The other callers pass a throw-away
         accumulator.
      
      3. Accumulate a map from names to members in seen
      
         Only one caller cares: QAPISchemaObjectType.check() uses it to
         compute its local variable seen, for self.variants.check(), which
         uses it to compute self.variants.tag_member from
         self.variants.tag_name.  The other callers pass a throw-away
         accumulator.
      
      4. Check for collisions
      
         This piggybacks on 3: before adding a new entry, we assert it's new.
      
         Only one caller cares: QAPISchemaObjectType.check() uses it to
         assert non-variant members don't clash.
      
      Simplify QAPISchemaObjectType.check(): move 2.-4. to
      QAPISchemaObjectType.check(), and drop parameters all_members and
      seen.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-2-git-send-email-armbru@redhat.com>
      [rebase to earlier changes that moved tag_member.check() of
      alternate types, commit message typo fix]
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-6-git-send-email-eblake@redhat.com>
      e564e2dd
    • M
      qapi: Drop obsolete tag value collision assertions · fff5f231
      Markus Armbruster 提交于
      Union tag values can't clash with member names in generated C anymore
      since commit e4ba22b3, but QAPISchemaObjectTypeVariants.check() still
      asserts they don't.  Drop it.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1446559499-26984-1-git-send-email-armbru@redhat.com>
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-5-git-send-email-eblake@redhat.com>
      fff5f231
    • E
      qapi-types: Simplify gen_struct_field[s] · 7d9586f9
      Eric Blake 提交于
      Simplify gen_struct_fields() back to a single iteration over a
      list of fields (like it was prior to commit f87ab7f9), by moving
      the generated comments to gen_object().  Then, inline
      gen_struct_field() into its only caller.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-4-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      7d9586f9
    • E
      qapi-types: Consolidate gen_struct() and gen_union() · 570cd8d1
      Eric Blake 提交于
      These two methods are now close enough that we can finally merge
      them, relying on the fact that simple unions now provide a
      reasonable local_members.  Change gen_struct() to gen_object()
      that handles all forms of QAPISchemaObjectType, and rename and
      shrink gen_union() to gen_variants() to handle the portion of
      gen_object() needed when variants are present.
      
      gen_struct_fields() now has a single caller, so it no longer
      needs an optional parameter; however, I did not choose to inline
      it into the caller.
      
      No difference to generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-3-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      570cd8d1
    • E
      qapi: Track simple union tag in object.local_members · da34a9bd
      Eric Blake 提交于
      We were previously creating all unions with an empty list for
      local_members.  However, it will make it easier to unify struct
      and union generation if we include the generated tag member in
      local_members.  That way, we can have a common code pattern:
      visit the base (if any), visit the local members (if any), visit
      the variants (if any).  The local_members of a flat union
      remains empty (because the discriminator is already visited as
      part of the base).  Then, by visiting tag_member.check() during
      AlternateType.check(), we no longer need to call it during
      Variants.check().
      
      The various front end entities now exist as follows:
      struct: optional base, optional local_members, no variants
      simple union: no base, one-element local_members, variants with tag_member
        from local_members
      flat union: base, no local_members, variants with tag_member from base
      alternate: no base, no local_members, variants
      
      With the new local members, we require a bit of finesse to
      avoid assertions in the clients.
      
      No change to generated code.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1447836791-369-2-git-send-email-eblake@redhat.com>
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      da34a9bd
    • P
      Update version for v2.5.0 release · a8c40fa2
      Peter Maydell 提交于
      Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
      a8c40fa2
  2. 12 12月, 2015 1 次提交
  3. 11 12月, 2015 2 次提交
  4. 10 12月, 2015 4 次提交
  5. 08 12月, 2015 4 次提交
  6. 07 12月, 2015 6 次提交