Merge branch 'fix_3303' into 'main'

mkenums: Allow , in a character literal

Closes #3103

See merge request GNOME/glib!3676
This commit is contained in:
Philip Withnall 2023-11-21 11:54:43 +00:00
commit 74d786e8bf
2 changed files with 32 additions and 0 deletions

View File

@ -223,6 +223,8 @@ def parse_entries(file, file_name):
(\w+)\s* # name
(\s+[A-Z]+_(?:AVAILABLE|DEPRECATED)_ENUMERATOR_IN_[0-9_]+(?:_FOR\s*\(\s*\w+\s*\))?\s*)? # availability
(?:=( # value
\s*'[^']*'\s* # char
| # OR
\s*\w+\s*\(.*\)\s* # macro with multiple args
| # OR
(?:[^,/]|/(?!\*))* # anything but a comma or comment
@ -728,6 +730,10 @@ def process_file(curfilename):
# approximation to C constant folding
inum = eval(num, {}, c_namespace)
# Support character literals
if isinstance(inum, str) and len(inum) == 1:
inum = ord(inum)
# make sure it parsed to an integer
if not isinstance(inum, int):
sys.exit("Unable to parse enum value '%s'" % num)

View File

@ -785,6 +785,32 @@ comment: {standard_bottom_comment}
"7",
)
def test_comma_in_enum_value(self):
"""Test use of comma in enum value."""
h_contents = """
typedef enum {
ENUM_VALUE_WITH_COMMA = ',',
} TestCommaEnum;
"""
result = self.runMkenumsWithHeader(h_contents)
self.assertEqual("", result.err)
self.assertSingleEnum(
result,
"TestCommaEnum",
"test_comma_enum",
"TEST_COMMA_ENUM",
"COMMA_ENUM",
"TEST",
"",
"enum",
"Enum",
"ENUM",
"ENUM_VALUE_WITH_COMMA",
"comma",
44,
)
class TestRspMkenums(TestMkenums):
"""Run all tests again in @rspfile mode"""