qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v10 05/25] qapi: Reserve 'q_*' and 'has_*' membe


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v10 05/25] qapi: Reserve 'q_*' and 'has_*' member names
Date: Fri, 23 Oct 2015 16:47:28 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Eric Blake <address@hidden> writes:

> On 10/23/2015 07:05 AM, Markus Armbruster wrote:
>> Eric Blake <address@hidden> writes:
>> 
>>> c_name() produces names starting with 'q_' when protecting
>>> a QMP member name that would fail to directly compile, but
>>> in doing so can cause clashes with any QMP name already
>>> beginning with 'q-' or 'q_'.  Likewise, we create a C name
>>> 'has_' for any optional member, that can clash with any QMP
>>> name beginning with 'has-' or 'has_'.
>>>
>>> Technically, rather than blindly reserving the namespace,
>>> we could try to complain about user names only when an actual
>>> collision occurs, or even teach c_name() how to munge names
>>> to avoid collisions.  But it is not trivial, especially when
>>> collisions can occur across multiple types (such as via
>>> inheritance or flat unions).  Besides, no existing .json
>>> files are trying to use these names.  So it's easier to just
>>> outright forbid the potential for collision.  We can always
>>> relax things in the future if a real need arises for QMP to
>>> express member names that have been forbidden here.
>>>
>>> 'has_' only has to be reserved for struct/union member names,
>>> while 'q_' is reserved everywhere (matching the fact that
>>> we only have optional members, but use c_name() everywhere).
>>>
>>> Update and add tests to cover the new error messages.
>>>
>>> Signed-off-by: Eric Blake <address@hidden>
>>>
>
>>> +++ b/scripts/qapi.py
>>> @@ -376,7 +376,9 @@ def check_name(expr_info, source, name, 
>>> allow_optional=False,
>>>      # code always prefixes it with the enum name
>>>      if enum_member:
>>>          membername = '_' + membername
>>> -    if not valid_name.match(membername):
>>> +    # Reserve the entire 'q_' namespace for c_name()
>>> +    if not valid_name.match(membername) or \
>>> +       membername.replace('-', '_').startswith('q_'):
>> 
>> Why not c_name(membername).startswith('q_')?
>
> Recursion.  c_name('unix') is 'q_unix', which would be rejected, even
> though we want to accept it. (And yes, that was my first try, before the
> approach you see here)

c_name(membername, False).startswith('q_')?

[...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]