[v3,1/2] scripts: Add "|" operator support to glibcpp's parsing

Message ID 20221127173825.3106-2-shahab@synopsys.com
State Committed
Commit 987f8647e8d6206cebc613e5c162ff8b4d014d40
Headers
Series Update ARC definitions in elf/elf.h |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Shahab Vahedi Nov. 27, 2022, 5:38 p.m. UTC
  From the tests point of view, this is a necessary step for another
patch [1] and allows parsing macros such as "#define A | B".  Without
it, a few tests [2] choke when the other patch [1] is applied:

/src/glibc/scripts/../elf/elf.h:4167: error: uninterpretable macro
token sequence: ( EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK )
Traceback (most recent call last):
    File "/src/glibc/elf/tst-glibcelf.py", line 23, in <module>
      import glibcelf
    File "/src/glibc/scripts/glibcelf.py", line 226, in <module>
      _elf_h = _parse_elf_h()
               ^^^^^^^^^^^^^^
    File "/src/glibc/scripts/glibcelf.py", line 223, in _parse_elf_h
      raise IOError('parse error in elf.h')
  OSError: parse error in elf.h

[1] ARC: update definitions in elf/elf.h
https://sourceware.org/pipermail/libc-alpha/2022-November/143503.html

[2]
tst-glibcelf, tst-relro-ldso, and tst-relro-libc

Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
---
 scripts/glibcpp.py     | 1 +
 support/tst-glibcpp.py | 1 +
 2 files changed, 2 insertions(+)
  

Comments

Florian Weimer Nov. 27, 2022, 6:21 p.m. UTC | #1
* Shahab Vahedi:

> From the tests point of view, this is a necessary step for another
> patch [1] and allows parsing macros such as "#define A | B".  Without
> it, a few tests [2] choke when the other patch [1] is applied:
>
> /src/glibc/scripts/../elf/elf.h:4167: error: uninterpretable macro
> token sequence: ( EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK )
> Traceback (most recent call last):
>     File "/src/glibc/elf/tst-glibcelf.py", line 23, in <module>
>       import glibcelf
>     File "/src/glibc/scripts/glibcelf.py", line 226, in <module>
>       _elf_h = _parse_elf_h()
>                ^^^^^^^^^^^^^^
>     File "/src/glibc/scripts/glibcelf.py", line 223, in _parse_elf_h
>       raise IOError('parse error in elf.h')
>   OSError: parse error in elf.h
>
> [1] ARC: update definitions in elf/elf.h
> https://sourceware.org/pipermail/libc-alpha/2022-November/143503.html
>
> [2]
> tst-glibcelf, tst-relro-ldso, and tst-relro-libc
>
> Signed-off-by: Shahab Vahedi <shahab@synopsys.com>

This okay and can go in separately, thanks.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Florian
  
Vineet Gupta Nov. 30, 2022, 2:11 a.m. UTC | #2
On 11/27/22 10:21, Florian Weimer via Libc-alpha wrote:
> * Shahab Vahedi:
> 
>>  From the tests point of view, this is a necessary step for another
>> patch [1] and allows parsing macros such as "#define A | B".  Without
>> it, a few tests [2] choke when the other patch [1] is applied:
>>
>> /src/glibc/scripts/../elf/elf.h:4167: error: uninterpretable macro
>> token sequence: ( EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK )
>> Traceback (most recent call last):
>>      File "/src/glibc/elf/tst-glibcelf.py", line 23, in <module>
>>        import glibcelf
>>      File "/src/glibc/scripts/glibcelf.py", line 226, in <module>
>>        _elf_h = _parse_elf_h()
>>                 ^^^^^^^^^^^^^^
>>      File "/src/glibc/scripts/glibcelf.py", line 223, in _parse_elf_h
>>        raise IOError('parse error in elf.h')
>>    OSError: parse error in elf.h
>>
>> [1] ARC: update definitions in elf/elf.h
>> https://sourceware.org/pipermail/libc-alpha/2022-November/143503.html
>>
>> [2]
>> tst-glibcelf, tst-relro-ldso, and tst-relro-libc
>>
>> Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
> 
> This okay and can go in separately, thanks.
> 
> Reviewed-by: Florian Weimer <fweimer@redhat.com>

Committed !

Thx,
-Vineet
  

Patch

diff --git a/scripts/glibcpp.py b/scripts/glibcpp.py
index 455459a609..2f39979894 100644
--- a/scripts/glibcpp.py
+++ b/scripts/glibcpp.py
@@ -346,6 +346,7 @@  RE_SPLIT_INTEGER_SUFFIX = re.compile(r'([^ullULL]+)([ullULL]*)')
 BINARY_OPERATORS = {
     '+': operator.add,
     '<<': operator.lshift,
+    '|': operator.or_,
 }
 
 # Use the general-purpose dict type if it is order-preserving.
diff --git a/support/tst-glibcpp.py b/support/tst-glibcpp.py
index a2db1916cc..cca8bd6c44 100644
--- a/support/tst-glibcpp.py
+++ b/support/tst-glibcpp.py
@@ -131,6 +131,7 @@  check_macro_eval('#define A 1', {'A': 1})
 check_macro_eval('#define A (1)', {'A': 1})
 check_macro_eval('#define A (1 + 1)', {'A': 2})
 check_macro_eval('#define A (1U << 31)', {'A': 1 << 31})
+check_macro_eval('#define A (1 | 2)', {'A': 1 | 2})
 check_macro_eval('''\
 #define A (B + 1)
 #define B 10