From f47aecae9f20f450f56e980ed1a832cc76e81c0a Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 27 Aug 2016 19:32:42 -0400 Subject: [PATCH] PYPY bugs and inspired changes ... verify.py: Show co_flags when different. pysource.py: PYPY also generates normal tryfinallystmt code test_pyenvlib.py: allow pypy-5.3.1 --- test/test_pyenvlib.py | 5 +++-- uncompyle6/semantics/pysource.py | 14 +++++++------- uncompyle6/verify.py | 9 +++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/test/test_pyenvlib.py b/test/test_pyenvlib.py index b904b0f3..3c305773 100755 --- a/test/test_pyenvlib.py +++ b/test/test_pyenvlib.py @@ -27,8 +27,9 @@ from fnmatch import fnmatch #----- configure this for your needs -TEST_VERSIONS=('2.3.7', '2.4.6', '2.5.6', '2.6.9', 'pypy-2.6.1', - 'pypy-5.0.1', +TEST_VERSIONS=('2.3.7', '2.4.6', '2.5.6', '2.6.9', + 'pypy-2.4.0', 'pypy-2.6.1', + 'pypy-5.0.1', 'pypy-5.3.1', '2.7.10', '2.7.11', '3.2.6', '3.3.5', '3.4.2', '3.5.1') diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index a6f9f2b3..4559c523 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -312,12 +312,13 @@ TABLE_DIRECT = { 'forelselaststmtl': ( '%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, 1, 4, -2), 'trystmt': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ), - 'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ), - 'tryelsestmtc': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ), - 'tryelsestmtl': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ), - 'tf_trystmt': ( '%c%-%c%+', 1, 3 ), - 'tf_tryelsestmt': ( '%c%-%c%|else:\n%+%c', 1, 3, 4 ), - 'except': ('%|except:\n%+%c%-', 3 ), + 'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ), + 'tryelsestmtc': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ), + 'tryelsestmtl': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ), + 'tf_trystmt': ( '%c%-%c%+', 1, 3 ), + 'tf_tryelsestmt': ( '%c%-%c%|else:\n%+%c', 1, 3, 4 ), + 'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 5 ), + 'except': ( '%|except:\n%+%c%-', 3 ), 'except_cond1': ( '%|except %c:\n', 1 ), 'except_cond2': ( '%|except %c as %c:\n', 1, 5 ), 'except_suite': ( '%+%c%-%C', 0, (1, maxint, '') ), @@ -533,7 +534,6 @@ class SourceWalker(GenericASTTraversal, object): 'assert': ( '%|assert %c\n' , 0 ), 'assert2': ( '%|assert %c, %c\n' , 0, 3 ), 'trystmt': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ), - 'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 5 ), 'assign2': ( '%|%c, %c = %c, %c\n', 3, 4, 0, 1 ), 'assign3': ( '%|%c, %c, %c = %c, %c, %c\n', 5, 6, 7, 0, 1, 2 ), }) diff --git a/uncompyle6/verify.py b/uncompyle6/verify.py index d18719dd..946d64a3 100755 --- a/uncompyle6/verify.py +++ b/uncompyle6/verify.py @@ -16,6 +16,7 @@ from uncompyle6 import PYTHON3 from xdis.code import iscode from xdis.magics import PYTHON_MAGIC_INT from xdis.load import load_file, load_module +from xdis.util import pretty_flags # FIXME: DRY if PYTHON3: @@ -335,6 +336,14 @@ def cmp_code_objects(version, is_pypy, code_obj1, code_obj2, name=''): for c1, c2 in zip(codes1, codes2): cmp_code_objects(version, is_pypy, c1, c2, name=name) + elif member == 'co_flags': + # For PYPY for now we don't care about PYPY_SOURCE_IS_UTF8: + flags1 = code_obj1.co_flags | 0x0100 # PYPY_SOURCE_IS_UTF8 + flags2 = code_obj2.co_flags + if flags1 != flags2: + raise CmpErrorMember(name, 'co_flags', + pretty_flags(flags1), + pretty_flags(flags2)) else: # all other members must be equal if getattr(code_obj1, member) != getattr(code_obj2, member):