[PATCH v4 1/2] qapi: Avoid generating C identifier 'linux'

zhenwei pi posted 2 patches 3 years, 7 months ago
Maintainers: Michael Roth <michael.roth@amd.com>, Konstantin Kostiuk <kkostiuk@redhat.com>, Markus Armbruster <armbru@redhat.com>
[PATCH v4 1/2] qapi: Avoid generating C identifier 'linux'
Posted by zhenwei pi 3 years, 7 months ago
'linux' is not usable as identifier, because C compilers targeting
Linux predefine it as a macro expanding to 1.  Add it to
@polluted_words. 'unix' is already there.

Suggested-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 scripts/qapi/common.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 489273574a..737b059e62 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -114,7 +114,7 @@ def c_name(name: str, protect: bool = True) -> str:
                      'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
                      'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
     # namespace pollution:
-    polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386'])
+    polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386', 'linux'])
     name = re.sub(r'[^A-Za-z0-9_]', '_', name)
     if protect and (name in (c89_words | c99_words | c11_words | gcc_words
                              | cpp_words | polluted_words)
-- 
2.20.1


Re: [PATCH v4 1/2] qapi: Avoid generating C identifier 'linux'
Posted by Markus Armbruster 3 years, 7 months ago
zhenwei pi <pizhenwei@bytedance.com> writes:

> 'linux' is not usable as identifier, because C compilers targeting
> Linux predefine it as a macro expanding to 1.  Add it to
> @polluted_words. 'unix' is already there.
>
> Suggested-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
> ---
>  scripts/qapi/common.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index 489273574a..737b059e62 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -114,7 +114,7 @@ def c_name(name: str, protect: bool = True) -> str:
>                       'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
>                       'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
>      # namespace pollution:
> -    polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386'])
> +    polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386', 'linux'])

If this list gets any longer, we better keep it in alphabetical order.

>      name = re.sub(r'[^A-Za-z0-9_]', '_', name)
>      if protect and (name in (c89_words | c99_words | c11_words | gcc_words
>                               | cpp_words | polluted_words)

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Re: Re: [PATCH v4 1/2] qapi: Avoid generating C identifier 'linux'
Posted by zhenwei pi 3 years, 7 months ago

On 7/7/22 14:26, Markus Armbruster wrote:
> zhenwei pi <pizhenwei@bytedance.com> writes:
> 
>> 'linux' is not usable as identifier, because C compilers targeting
>> Linux predefine it as a macro expanding to 1.  Add it to
>> @polluted_words. 'unix' is already there.
>>
>> Suggested-by: Markus Armbruster <armbru@redhat.com>
>> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
>> ---
>>   scripts/qapi/common.py | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
>> index 489273574a..737b059e62 100644
>> --- a/scripts/qapi/common.py
>> +++ b/scripts/qapi/common.py
>> @@ -114,7 +114,7 @@ def c_name(name: str, protect: bool = True) -> str:
>>                        'and', 'and_eq', 'bitand', 'bitor', 'compl', 'not',
>>                        'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
>>       # namespace pollution:
>> -    polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386'])
>> +    polluted_words = set(['unix', 'errno', 'mips', 'sparc', 'i386', 'linux'])
> 
> If this list gets any longer, we better keep it in alphabetical order.
> 

OK!

>>       name = re.sub(r'[^A-Za-z0-9_]', '_', name)
>>       if protect and (name in (c89_words | c99_words | c11_words | gcc_words
>>                                | cpp_words | polluted_words)
> 
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> 

-- 
zhenwei pi