bug 581516 - stop handling octal literals in Preprocessor.py. r=pike a=blocking
authorTed Mielczarek <ted.mielczarek@gmail.com>
Thu, 29 Jul 2010 11:30:56 -0400
changeset 48352 10546102321180933b5997c0870cff21cedc2e8a
parent 48351 b26489e738182b36d815226d85fa1dc4b2d6c5d1
child 48353 06b578dfadc9db8b683090e0e110ba75b84fb766
push idunknown
push userunknown
push dateunknown
reviewerspike, blocking
bugs581516
milestone2.0b3pre
bug 581516 - stop handling octal literals in Preprocessor.py. r=pike a=blocking
config/Expression.py
config/Preprocessor.py
config/tests/unit-Preprocessor.py
--- a/config/Expression.py
+++ b/config/Expression.py
@@ -104,20 +104,17 @@ class Expression:
     Production: ( [0-9]+ | \w+)
     Note that the order is important, and the expression is kind-of
     ambiguous as \w includes 0-9. One could make it unambiguous by
     removing 0-9 from the first char of a string literal.
     """
     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()
       if word_len:
         rv = Expression.__ASTLeaf('string', self.content[:word_len])
       else:
         raise Expression.ParseError, self
     self.__strip(word_len)
--- a/config/Preprocessor.py
+++ b/config/Preprocessor.py
@@ -177,20 +177,17 @@ class Preprocessor:
     def handleD(option, opt, value, parser):
       vals = value.split('=', 1)
       if len(vals) == 1:
         vals.append(1)
       elif unescapeDefines and escapedValue.match(vals[1]):
         # 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]
     def handleF(option, opt, value, parser):
       self.do_filter(value)
     def handleLE(option, opt, value, parser):
       self.setLineEndings(value)
     def handleMarker(option, opt, value, parser):
@@ -242,20 +239,17 @@ class Preprocessor:
   def do_define(self, args):
     m = re.match('(?P<name>\w+)(?:\s(?P<value>.*))?', args, re.U)
     if not m:
       raise Preprocessor.Error(self, 'SYNTAX_DEF', args)
     val = 1
     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
   def do_undef(self, args):
     m = re.match('(?P<name>\w+)$', args, re.U)
     if not m:
       raise Preprocessor.Error(self, 'SYNTAX_DEF', args)
     if args in self.context:
--- a/config/tests/unit-Preprocessor.py
+++ b/config/tests/unit-Preprocessor.py
@@ -443,10 +443,52 @@ 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 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()