Skip to content
  • Eric Blake's avatar
    c9e0a798
    qapi: Require valid names · c9e0a798
    Eric Blake authored
    
    
    Previous commits demonstrated that the generator overlooked various
    bad naming situations:
    - types, commands, and events need a valid name
    - enum members must be valid names, when combined with prefix
    - union and alternate branches cannot be marked optional
    
    Valid upstream names match [a-zA-Z][a-zA-Z0-9_-]*; valid downstream
    names match __[a-zA-Z][a-zA-Z0-9._-]*.  Enumerations match the
    weaker [a-zA-Z0-9._-]+ (in part thanks to QKeyCode picking an enum
    that starts with a digit, which we can't change now due to
    backwards compatibility).  Rather than call out three separate
    regex, this patch just uses a broader combination that allows both
    upstream and downstream names, as well as a small hack that
    realizes that any enum name is merely a suffix to an already valid
    name prefix (that is, any enum name is valid if prepending _ fits
    the normal rules).
    
    We could reject new enumeration names beginning with a digit by
    whitelisting existing exceptions.  We could also be stricter
    about the distinction between upstream names (no leading
    underscore, no use of dot) and downstream (mandatory leading
    double underscore), but it is probably not worth the bother.
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
    c9e0a798
    qapi: Require valid names
    Eric Blake authored
    
    
    Previous commits demonstrated that the generator overlooked various
    bad naming situations:
    - types, commands, and events need a valid name
    - enum members must be valid names, when combined with prefix
    - union and alternate branches cannot be marked optional
    
    Valid upstream names match [a-zA-Z][a-zA-Z0-9_-]*; valid downstream
    names match __[a-zA-Z][a-zA-Z0-9._-]*.  Enumerations match the
    weaker [a-zA-Z0-9._-]+ (in part thanks to QKeyCode picking an enum
    that starts with a digit, which we can't change now due to
    backwards compatibility).  Rather than call out three separate
    regex, this patch just uses a broader combination that allows both
    upstream and downstream names, as well as a small hack that
    realizes that any enum name is merely a suffix to an already valid
    name prefix (that is, any enum name is valid if prepending _ fits
    the normal rules).
    
    We could reject new enumeration names beginning with a digit by
    whitelisting existing exceptions.  We could also be stricter
    about the distinction between upstream names (no leading
    underscore, no use of dot) and downstream (mandatory leading
    double underscore), but it is probably not worth the bother.
    
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
Loading