bug 581516 - stop handling octal literals in Preprocessor.py. r=pike a=blocking

--HG--
extra : rebase_source : e5db5f9cf7e2f87c56bfe7710e73fc7f37108f2e
This commit is contained in:
Ted Mielczarek 2010-07-29 11:30:56 -04:00
parent 4a5b609e6f
commit 06277defeb
3 changed files with 45 additions and 12 deletions

View File

@ -109,10 +109,7 @@ class Expression:
rv = None
word_len = re.match('[0-9]*', self.content).end()
if word_len:
if self.content[0] == '0':
value = int(self.content[:word_len], 8)
else:
value = int(self.content[:word_len])
value = int(self.content[:word_len])
rv = Expression.__ASTLeaf('int', value)
else:
word_len = re.match('\w*', self.content).end()

View File

@ -182,10 +182,7 @@ class Preprocessor:
# strip escaped string values
vals[1] = vals[1][1:-1]
elif numberValue.match(vals[1]):
if vals[1][0] == '0':
vals[1] = int(vals[1], 8)
else:
vals[1] = int(vals[1])
vals[1] = int(vals[1])
self.context[vals[0]] = vals[1]
def handleU(option, opt, value, parser):
del self.context[value]
@ -247,10 +244,7 @@ class Preprocessor:
if m.group('value'):
val = m.group('value')
try:
if val[0] == '0':
val = int(val, 8)
else:
val = int(val)
val = int(val)
except:
pass
self.context[m.group('name')] = val

View File

@ -448,5 +448,47 @@ octal value is not equal
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "octal value is equal\n")
def test_value_quoted_expansion(self):
"""
Quoted values on the commandline don't currently have quotes stripped.
Pike says this is for compat reasons.
"""
f = NamedIO("value_quoted_expansion.in", """#filter substitution
@FOO@
""")
self.pp.handleCommandLine(['-DFOO="ABCD"'])
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), '"ABCD"\n')
def test_octal_value_quoted_expansion(self):
f = NamedIO("value_quoted_expansion.in", """#filter substitution
@FOO@
""")
self.pp.handleCommandLine(['-DFOO="0100"'])
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), '"0100"\n')
def test_number_value_not_equals_quoted_defines(self):
f = NamedIO("number_value_not_equals_quoted_defines.in", """#if FOO == 1000
number value is equal
#else
number value is not equal
#endif
""")
self.pp.handleCommandLine(['-DFOO="1000"'])
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "number value is not equal\n")
def test_octal_value_not_equals_quoted_defines(self):
f = NamedIO("octal_value_not_equals_quoted_defines.in", """#if FOO == 0100
octal value is equal
#else
octal value is not equal
#endif
""")
self.pp.handleCommandLine(['-DFOO="0100"'])
self.pp.do_include(f)
self.assertEqual(self.pp.out.getvalue(), "octal value is not equal\n")
if __name__ == '__main__':
unittest.main()