From 1f0134854c492ab82f2ceb5379dda70dcc120c82 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 13 Dec 2021 18:06:44 -0800 Subject: [PATCH] Parse settings on the command line passed in as hex I ran into this issue when working on #15763. We have code interally that converts `=-1` to `=0x7FFFFFFF` for the MIN_XX_VERSION settings. However, this was then being interpreted interally as a string. When read from JS there is no differenence but from python code the value of this setting would appear as the string "0x7FFFFFFF" and not the number 0x7FFFFFFF. --- emcc.py | 6 +++++- tests/test_other.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/emcc.py b/emcc.py index b65bdda854ae4..2c014e2c31d4c 100755 --- a/emcc.py +++ b/emcc.py @@ -3812,7 +3812,11 @@ def parse_string_list(text): return parse_string_list(text) try: - return int(text) + if text.startswith('0x'): + base = 16 + else: + base = 10 + return int(text, base) except ValueError: return parse_string_value(text) diff --git a/tests/test_other.py b/tests/test_other.py index c2f07c70d202b..ae997216f33b7 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -6556,6 +6556,11 @@ def test_dash_s_no_space(self): err = self.expect_fail([EMXX, test_file('hello_world.cpp'), '-sEXPORTED_FUNCTIONS=foo']) self.assertContained('error: undefined exported symbol: "foo"', err) + def test_dash_s_hex(self): + self.run_process([EMCC, test_file('hello_world.c'), '-nostdlib', '-sERROR_ON_UNDEFINED_SYMBOLS=0']) + # Ensure that 0x0 is parsed as a zero and not as the string '0x0'. + self.run_process([EMCC, test_file('hello_world.c'), '-nostdlib', '-sERROR_ON_UNDEFINED_SYMBOLS=0x0']) + def test_zeroinit(self): create_file('src.c', r''' #include