Python 3.7 changes chained comparison code

fixes #206
This commit is contained in:
rocky
2019-01-13 19:37:41 -05:00
parent 37750814b9
commit a97d4003c7
5 changed files with 42 additions and 0 deletions

View File

@@ -64,10 +64,12 @@ check-3.5: check-bytecode
#: Run working tests from Python 3.6 #: Run working tests from Python 3.6
check-3.6: check-bytecode check-3.6: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.6 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.6 --weak-verify $(COMPILE)
$(PYTHON) test_pythonlib.py --bytecode-3.6-run --verify-run
#: Run working tests from Python 3.7 #: Run working tests from Python 3.7
check-3.7: check-bytecode check-3.7: check-bytecode
$(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify $(COMPILE) $(PYTHON) test_pythonlib.py --bytecode-3.7 --weak-verify $(COMPILE)
$(PYTHON) test_pythonlib.py --bytecode-3.7-run --verify-run
# FIXME # FIXME
#: this is called when running under pypy3.5-5.8.0 or pypy2-5.6.0 #: this is called when running under pypy3.5-5.8.0 or pypy2-5.6.0

Binary file not shown.

View File

@@ -0,0 +1,19 @@
# From Python 3.7 pickle.py
# Bug was different code generation for chained comparisons than prior Python versions
def chained_compare_a(protocol):
if not 0 <= protocol <= 7:
raise ValueError("pickle protocol must be <= %d" % 7)
def chained_compare_b(a, obj):
if a:
if -0x80000000 <= obj <= 0x7fffffff:
return 5
chained_compare_a(3)
try:
chained_compare_a(8)
except ValueError:
pass
chained_compare_b(True, 0x0)

View File

@@ -67,6 +67,17 @@ class Python37Parser(Python36Parser):
# FIXME: generalize and specialize # FIXME: generalize and specialize
call ::= expr CALL_METHOD_0 call ::= expr CALL_METHOD_0
testtrue ::= compare_chained37
compare_chained37 ::= expr compare_chained1a_37
compare_chained37 ::= expr compare_chained1b_37
compare_chained2a_37 ::= expr COMPARE_OP POP_JUMP_IF_TRUE JUMP_FORWARD
compare_chained2b_37 ::= expr COMPARE_OP POP_JUMP_IF_FALSE JUMP_FORWARD
compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
compare_chained2a_37 ELSE POP_TOP COME_FROM
compare_chained1b_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
compare_chained2b_37 ELSE POP_TOP JUMP_FORWARD COME_FROM
""" """
def customize_grammar_rules(self, tokens, customize): def customize_grammar_rules(self, tokens, customize):

View File

@@ -917,6 +917,16 @@ def customize_for_version3(self, version):
'async_for_stmt': ( 'async_for_stmt': (
'%|async for %c in %c:\n%+%c%-%-\n\n', '%|async for %c in %c:\n%+%c%-%-\n\n',
7, 1, 17), 7, 1, 17),
'compare_chained1a_37': ( ' %[3]{pattr.replace("-", " ")} %p %p',
(0, 19),
(-4, 19)),
'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p',
(0, 19),
(-5, 19)),
'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
}) })
pass pass
pass # version >= 3.6 pass # version >= 3.6