Author: whitequark <whitequ...@whitequark.org> Branch: fix-literal-prev_digit-underscore Changeset: r96607:2c00b58bf83c Date: 2019-05-13 03:34 +0000 http://bitbucket.org/pypy/pypy/changeset/2c00b58bf83c/
Log: Fix a crash on literals like 0xffff_ffff_ff20_0000. diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py --- a/pypy/interpreter/astcompiler/test/test_compiler.py +++ b/pypy/interpreter/astcompiler/test/test_compiler.py @@ -126,6 +126,9 @@ for c in expressions.constants: yield (self.simple_test, "x="+c, "x", eval(c)) + def test_const_underscore(self): + yield (self.simple_test, "x=0xffff_ffff_ff20_0000", "x", 0xffffffffff200000) + def test_neg_sys_maxint(self): import sys stmt = "x = %s" % (-sys.maxint-1) diff --git a/rpython/rlib/rstring.py b/rpython/rlib/rstring.py --- a/rpython/rlib/rstring.py +++ b/rpython/rlib/rstring.py @@ -579,6 +579,11 @@ assert i >= 0 self.i = i c = self.s[i] + if self.allow_underscores and c == '_': + i = self.i - 1 + assert i >= 0 + self.i = i + c = self.s[i] digit = ord(c) if '0' <= c <= '9': digit -= ord('0') _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit