From e910418fb8b462bc440fa57a8e1cb960866b96f9 Mon Sep 17 00:00:00 2001 From: Julian Gilbey Date: Sun, 26 Jun 2022 11:18:13 +0100 Subject: [PATCH] Update bytecode to 0.13.0 and simplify patch --- _pydevd_frame_eval/pydevd_modify_bytecode.py | 4 +- _pydevd_frame_eval/vendored/README.txt | 6 +- .../bytecode-0.13.0.dev0.dist-info/COPYING | 21 - .../bytecode-0.13.0.dev0.dist-info/INSTALLER | 1 - .../bytecode-0.13.0.dev0.dist-info/METADATA | 77 -- .../bytecode-0.13.0.dev0.dist-info/RECORD | 42 - .../bytecode-0.13.0.dev0.dist-info/REQUESTED | 0 .../bytecode-0.13.0.dev0.dist-info/WHEEL | 5 - .../direct_url.json | 1 - .../vendored/bytecode.egg-info/PKG-INFO | 76 ++ .../vendored/bytecode.egg-info/SOURCES.txt | 38 + .../bytecode.egg-info/dependency_links.txt | 1 + .../top_level.txt | 0 .../vendored/bytecode/__init__.py | 22 +- .../vendored/bytecode/concrete.py | 29 +- .../bytecode/tests/long_lines_example.py | 1053 +++++++++++++++++ .../vendored/bytecode/tests/test_concrete.py | 24 +- .../vendored/pydevd_offset_patch.diff | 86 ++ 18 files changed, 1305 insertions(+), 181 deletions(-) delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/COPYING delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/INSTALLER delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/METADATA delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/RECORD delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/REQUESTED delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/WHEEL delete mode 100644 _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/direct_url.json create mode 100644 _pydevd_frame_eval/vendored/bytecode.egg-info/PKG-INFO create mode 100644 _pydevd_frame_eval/vendored/bytecode.egg-info/SOURCES.txt create mode 100644 _pydevd_frame_eval/vendored/bytecode.egg-info/dependency_links.txt rename _pydevd_frame_eval/vendored/{bytecode-0.13.0.dev0.dist-info => bytecode.egg-info}/top_level.txt (100%) create mode 100644 _pydevd_frame_eval/vendored/bytecode/tests/long_lines_example.py create mode 100644 _pydevd_frame_eval/vendored/pydevd_offset_patch.diff diff --git a/_pydevd_frame_eval/pydevd_modify_bytecode.py b/_pydevd_frame_eval/pydevd_modify_bytecode.py index ba84b5cc9..497575338 100644 --- a/_pydevd_frame_eval/pydevd_modify_bytecode.py +++ b/_pydevd_frame_eval/pydevd_modify_bytecode.py @@ -1,4 +1,5 @@ from collections import namedtuple +import contextlib import dis from functools import partial import itertools @@ -36,7 +37,8 @@ def _get_filename(self, op_number=None, prefix=''): def write_bytecode(self, b, op_number=None, prefix=''): filename, op_number = self._get_filename(op_number, prefix) with open(filename, 'w') as stream: - bytecode.dump_bytecode(b, stream=stream, lineno=True) + with contextlib.redirect_stdout(stream): + bytecode.dump_bytecode(b, lineno=True) return op_number def write_dis(self, code_to_modify, op_number=None, prefix=''): diff --git a/_pydevd_frame_eval/vendored/README.txt b/_pydevd_frame_eval/vendored/README.txt index d15aa2091..9fbd00709 100644 --- a/_pydevd_frame_eval/vendored/README.txt +++ b/_pydevd_frame_eval/vendored/README.txt @@ -13,6 +13,8 @@ python -m pip install https://github.com/MatthieuDartiailh/bytecode/archive/main Then run 'pydevd_fix_code.py' to fix the imports on the vendored file, run its tests (to see if things are still ok) and commit. -Then, to finish, apply the patch to add the offset to the instructions (bcb8a28669e9178f96f5d71af7259e0674acc47c) +Then, to finish, apply the patch to add the offset to the instructions +found in the file pydevd_offset_patch.diff; this applies to version +0.13.0 of the 'bytecode' library. -Note: commit the egg-info as a note of the license (force if needed). \ No newline at end of file +Note: commit the egg-info as a note of the license (force if needed). diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/COPYING b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/COPYING deleted file mode 100644 index 81d7e37c3..000000000 --- a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/COPYING +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) -Copyright (c) 2016 Red Hat. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/INSTALLER b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/INSTALLER deleted file mode 100644 index a1b589e38..000000000 --- a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/INSTALLER +++ /dev/null @@ -1 +0,0 @@ -pip diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/METADATA b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/METADATA deleted file mode 100644 index e1d5e0120..000000000 --- a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/METADATA +++ /dev/null @@ -1,77 +0,0 @@ -Metadata-Version: 2.1 -Name: bytecode -Version: 0.13.0.dev0 -Summary: Python module to generate and modify bytecode -Home-page: https://github.com/MatthieuDartiailh/bytecode -Author: Victor Stinner -Author-email: victor.stinner@gmail.com -Maintainer: Matthieu C. Dartiailh -Maintainer-email: m.dartiailh@gmail.com -License: MIT license -Platform: UNKNOWN -Classifier: Development Status :: 4 - Beta -Classifier: Intended Audience :: Developers -Classifier: License :: OSI Approved :: MIT License -Classifier: Natural Language :: English -Classifier: Operating System :: OS Independent -Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.6 -Classifier: Programming Language :: Python :: 3.7 -Classifier: Programming Language :: Python :: 3.8 -Classifier: Programming Language :: Python :: 3.9 -Classifier: Topic :: Software Development :: Libraries :: Python Modules -Requires-Python: >=3.6 - -******** -bytecode -******** - -.. image:: https://img.shields.io/pypi/v/bytecode.svg - :alt: Latest release on the Python Cheeseshop (PyPI) - :target: https://pypi.python.org/pypi/bytecode - -.. image:: https://github.com/MatthieuDartiailh/bytecode/workflows/Continuous%20Integration/badge.svg - :target: https://github.com/MatthieuDartiailh/bytecode/actions - :alt: Continuous integration - -.. image:: https://github.com/MatthieuDartiailh/bytecode/workflows/Documentation%20building/badge.svg - :target: https://github.com/MatthieuDartiailh/bytecode/actions - :alt: Documentation building - -.. image:: https://img.shields.io/codecov/c/github/MatthieuDartiailh/bytecode/master.svg - :alt: Code coverage of bytecode on codecov.io - :target: https://codecov.io/github/MatthieuDartiailh/bytecode - -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :alt: Code formatted using Black - :target: https://github.com/psf/black - -``bytecode`` is a Python module to generate and modify bytecode. - -* `bytecode project homepage at GitHub - `_ (code, bugs) -* `bytecode documentation - `_ -* `Download latest bytecode release at the Python Cheeseshop (PyPI) - `_ - -Install bytecode: ``python3 -m pip install bytecode``. It requires Python 3.6 -or newer. The latest release that supports Python 3.5 is 0.12.0. For Python 2.7 -support, have a look at `dead-bytecode -`_ instead. - -Example executing ``print('Hello World!')``: - -.. code:: python - - from bytecode import Instr, Bytecode - - bytecode = Bytecode([Instr("LOAD_NAME", 'print'), - Instr("LOAD_CONST", 'Hello World!'), - Instr("CALL_FUNCTION", 1), - Instr("POP_TOP"), - Instr("LOAD_CONST", None), - Instr("RETURN_VALUE")]) - code = bytecode.to_code() - exec(code) - diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/RECORD b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/RECORD deleted file mode 100644 index 3890ece18..000000000 --- a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/RECORD +++ /dev/null @@ -1,42 +0,0 @@ -bytecode-0.13.0.dev0.dist-info/COPYING,sha256=baWkm-Te2LLURwK7TL0zOkMSVjVCU_ezvObHBo298Tk,1074 -bytecode-0.13.0.dev0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 -bytecode-0.13.0.dev0.dist-info/METADATA,sha256=9XadDK6YTQ-FPowYI5DS4ieA7hRGnRP_fM5Z9ioPkEQ,2929 -bytecode-0.13.0.dev0.dist-info/RECORD,, -bytecode-0.13.0.dev0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 -bytecode-0.13.0.dev0.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92 -bytecode-0.13.0.dev0.dist-info/direct_url.json,sha256=s58Rb4KXRlMKxk-mzpvr_tJRQ-Hx8-DHsU6NdohCnAg,93 -bytecode-0.13.0.dev0.dist-info/top_level.txt,sha256=9BhdB7HqYZ-PvHNoWX6ilwLYWQqcgEOLwdb3aXm5Gys,9 -bytecode/__init__.py,sha256=d-yk4Xh4SwOWq9NgoD2rmBLG6RhUFNljeqs-NjMNSYM,3885 -bytecode/__pycache__/__init__.cpython-38.pyc,, -bytecode/__pycache__/bytecode.cpython-38.pyc,, -bytecode/__pycache__/cfg.cpython-38.pyc,, -bytecode/__pycache__/concrete.cpython-38.pyc,, -bytecode/__pycache__/flags.cpython-38.pyc,, -bytecode/__pycache__/instr.cpython-38.pyc,, -bytecode/__pycache__/peephole_opt.cpython-38.pyc,, -bytecode/bytecode.py,sha256=IMCcatHMtQ7M31nwj4r3drcvQuGVJAOP0d7C0O8P_SE,6894 -bytecode/cfg.py,sha256=RmJGJqwCxR-XYaPH9YGY4wNDycdtLvIBJb1OGSmxcN0,15274 -bytecode/concrete.py,sha256=0eb6Yh_NDLmzJNcMs2TFom0EqFVSM1cO3inMH90YE-s,21683 -bytecode/flags.py,sha256=hAvM_B2yQKRw44leHP0oCae0aaJraAbDDTpqIf4I1CM,5987 -bytecode/instr.py,sha256=HYc65LjNSOB3GCWkNkCSkee1rRzUyr89rgdjbKBaTpE,11616 -bytecode/peephole_opt.py,sha256=W-cFVPOZN-JKfDV3aImsYenDSZkSNBDTVQqeMrGPU18,15712 -bytecode/tests/__init__.py,sha256=BAdOXXNRdMVX4D8TuRYPlG9PHU7Cb0bzvyfA9s435kM,4968 -bytecode/tests/__pycache__/__init__.cpython-38.pyc,, -bytecode/tests/__pycache__/test_bytecode.cpython-38.pyc,, -bytecode/tests/__pycache__/test_cfg.cpython-38.pyc,, -bytecode/tests/__pycache__/test_code.cpython-38.pyc,, -bytecode/tests/__pycache__/test_concrete.cpython-38.pyc,, -bytecode/tests/__pycache__/test_flags.cpython-38.pyc,, -bytecode/tests/__pycache__/test_instr.cpython-38.pyc,, -bytecode/tests/__pycache__/test_misc.cpython-38.pyc,, -bytecode/tests/__pycache__/test_peephole_opt.cpython-38.pyc,, -bytecode/tests/__pycache__/util_annotation.cpython-38.pyc,, -bytecode/tests/test_bytecode.py,sha256=buvtlDC0NwoQ3zuZ7OENIIDngSqtiO9WkAa2-UvxGkI,15584 -bytecode/tests/test_cfg.py,sha256=c0xT8OfV-mDHu-DIDWr6LVlZQyK4GfgLSmT5AsodbMk,28194 -bytecode/tests/test_code.py,sha256=XCOH29rOXSoQz130s-AIC62r23e9qNjk8Y2xDB2LmSc,2100 -bytecode/tests/test_concrete.py,sha256=qT2qvabkF0yC7inniNx53cMSDN-2Qi0IE3pwBZSzF8g,49253 -bytecode/tests/test_flags.py,sha256=DY9U3c6tJdxJFm0jEm_To1Cc0I99EidQv_0guud-4oE,5684 -bytecode/tests/test_instr.py,sha256=rYeF8u-L0aW8bLPBxTUSy_T7KP6SaXyJKv9OhC8k6aA,11295 -bytecode/tests/test_misc.py,sha256=wyK1wpVPHRfaXgo-EqUI-F1nyB9-UACerHsHbExAo1U,6758 -bytecode/tests/test_peephole_opt.py,sha256=niUfhgEbiFR7IAmdQ_N9Qgh7D3wdRQ_zS0V8mKC4EzI,32640 -bytecode/tests/util_annotation.py,sha256=wKq6yPWrzkNlholl5Y10b3VjuCkoiYVgvcIjk_8jzf8,485 diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/REQUESTED b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/REQUESTED deleted file mode 100644 index e69de29bb..000000000 diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/WHEEL b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/WHEEL deleted file mode 100644 index 385faab05..000000000 --- a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/WHEEL +++ /dev/null @@ -1,5 +0,0 @@ -Wheel-Version: 1.0 -Generator: bdist_wheel (0.36.2) -Root-Is-Purelib: true -Tag: py3-none-any - diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/direct_url.json b/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/direct_url.json deleted file mode 100644 index 3c32b5716..000000000 --- a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/direct_url.json +++ /dev/null @@ -1 +0,0 @@ -{"archive_info": {}, "url": "https://github.com/MatthieuDartiailh/bytecode/archive/main.zip"} \ No newline at end of file diff --git a/_pydevd_frame_eval/vendored/bytecode.egg-info/PKG-INFO b/_pydevd_frame_eval/vendored/bytecode.egg-info/PKG-INFO new file mode 100644 index 000000000..3b0f641ca --- /dev/null +++ b/_pydevd_frame_eval/vendored/bytecode.egg-info/PKG-INFO @@ -0,0 +1,76 @@ +Metadata-Version: 1.2 +Name: bytecode +Version: 0.13.0 +Summary: Python module to generate and modify bytecode +Home-page: https://github.com/MatthieuDartiailh/bytecode +Author: Victor Stinner +Author-email: victor.stinner@gmail.com +Maintainer: Matthieu C. Dartiailh +Maintainer-email: m.dartiailh@gmail.com +License: MIT license +Description: ******** + bytecode + ******** + + .. image:: https://img.shields.io/pypi/v/bytecode.svg + :alt: Latest release on the Python Cheeseshop (PyPI) + :target: https://pypi.python.org/pypi/bytecode + + .. image:: https://github.com/MatthieuDartiailh/bytecode/workflows/Continuous%20Integration/badge.svg + :target: https://github.com/MatthieuDartiailh/bytecode/actions + :alt: Continuous integration + + .. image:: https://github.com/MatthieuDartiailh/bytecode/workflows/Documentation%20building/badge.svg + :target: https://github.com/MatthieuDartiailh/bytecode/actions + :alt: Documentation building + + .. image:: https://img.shields.io/codecov/c/github/MatthieuDartiailh/bytecode/master.svg + :alt: Code coverage of bytecode on codecov.io + :target: https://codecov.io/github/MatthieuDartiailh/bytecode + + .. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :alt: Code formatted using Black + :target: https://github.com/psf/black + + ``bytecode`` is a Python module to generate and modify bytecode. + + * `bytecode project homepage at GitHub + `_ (code, bugs) + * `bytecode documentation + `_ + * `Download latest bytecode release at the Python Cheeseshop (PyPI) + `_ + + Install bytecode: ``python3 -m pip install bytecode``. It requires Python 3.6 + or newer. The latest release that supports Python 3.5 is 0.12.0. For Python 2.7 + support, have a look at `dead-bytecode + `_ instead. + + Example executing ``print('Hello World!')``: + + .. code:: python + + from bytecode import Instr, Bytecode + + bytecode = Bytecode([Instr("LOAD_NAME", 'print'), + Instr("LOAD_CONST", 'Hello World!'), + Instr("CALL_FUNCTION", 1), + Instr("POP_TOP"), + Instr("LOAD_CONST", None), + Instr("RETURN_VALUE")]) + code = bytecode.to_code() + exec(code) +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: MIT License +Classifier: Natural Language :: English +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 +Classifier: Programming Language :: Python :: 3.10 +Classifier: Topic :: Software Development :: Libraries :: Python Modules +Requires-Python: >=3.6 diff --git a/_pydevd_frame_eval/vendored/bytecode.egg-info/SOURCES.txt b/_pydevd_frame_eval/vendored/bytecode.egg-info/SOURCES.txt new file mode 100644 index 000000000..d11ba247f --- /dev/null +++ b/_pydevd_frame_eval/vendored/bytecode.egg-info/SOURCES.txt @@ -0,0 +1,38 @@ +COPYING +MANIFEST.in +README.rst +setup.py +tox.ini +bytecode/__init__.py +bytecode/bytecode.py +bytecode/cfg.py +bytecode/concrete.py +bytecode/flags.py +bytecode/instr.py +bytecode/peephole_opt.py +bytecode.egg-info/PKG-INFO +bytecode.egg-info/SOURCES.txt +bytecode.egg-info/dependency_links.txt +bytecode.egg-info/top_level.txt +bytecode/tests/__init__.py +bytecode/tests/long_lines_example.py +bytecode/tests/test_bytecode.py +bytecode/tests/test_cfg.py +bytecode/tests/test_code.py +bytecode/tests/test_concrete.py +bytecode/tests/test_flags.py +bytecode/tests/test_instr.py +bytecode/tests/test_misc.py +bytecode/tests/test_peephole_opt.py +bytecode/tests/util_annotation.py +doc/Makefile +doc/api.rst +doc/byteplay_codetransformer.rst +doc/cfg.rst +doc/changelog.rst +doc/conf.py +doc/index.rst +doc/make.bat +doc/peephole.rst +doc/todo.rst +doc/usage.rst \ No newline at end of file diff --git a/_pydevd_frame_eval/vendored/bytecode.egg-info/dependency_links.txt b/_pydevd_frame_eval/vendored/bytecode.egg-info/dependency_links.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/_pydevd_frame_eval/vendored/bytecode.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/_pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/top_level.txt b/_pydevd_frame_eval/vendored/bytecode.egg-info/top_level.txt similarity index 100% rename from _pydevd_frame_eval/vendored/bytecode-0.13.0.dev0.dist-info/top_level.txt rename to _pydevd_frame_eval/vendored/bytecode.egg-info/top_level.txt diff --git a/_pydevd_frame_eval/vendored/bytecode/__init__.py b/_pydevd_frame_eval/vendored/bytecode/__init__.py index f970fbc00..8ae00857f 100644 --- a/_pydevd_frame_eval/vendored/bytecode/__init__.py +++ b/_pydevd_frame_eval/vendored/bytecode/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.13.0.dev" +__version__ = "0.13.0" __all__ = [ "Label", @@ -35,9 +35,9 @@ _ConvertBytecodeToConcrete, ) from _pydevd_frame_eval.vendored.bytecode.cfg import BasicBlock, ControlFlowGraph # noqa -import sys -def dump_bytecode(bytecode, *, lineno=False, stream=sys.stdout): + +def dump_bytecode(bytecode, *, lineno=False): def format_line(index, line): nonlocal cur_lineno, prev_lineno if lineno: @@ -87,7 +87,7 @@ def format_instr(instr, labels=None): else: fields.append("% 3s %s" % (offset, format_instr(instr))) line = "".join(fields) - print(line, file=stream) + print(line) offset += instr.size elif isinstance(bytecode, Bytecode): @@ -101,30 +101,30 @@ def format_instr(instr, labels=None): label = labels[instr] line = "%s:" % label if index != 0: - print(file=stream) + print() else: if instr.lineno is not None: cur_lineno = instr.lineno line = format_instr(instr, labels) line = indent + format_line(index, line) - print(line, file=stream) - print(file=stream) + print(line) + print() elif isinstance(bytecode, ControlFlowGraph): labels = {} for block_index, block in enumerate(bytecode, 1): labels[id(block)] = "block%s" % block_index for block_index, block in enumerate(bytecode, 1): - print("%s:" % labels[id(block)], file=stream) + print("%s:" % labels[id(block)]) prev_lineno = None for index, instr in enumerate(block): if instr.lineno is not None: cur_lineno = instr.lineno line = format_instr(instr, labels) line = indent + format_line(index, line) - print(line, file=stream) + print(line) if block.next_block is not None: - print(indent + "-> %s" % labels[id(block.next_block)], file=stream) - print(file=stream) + print(indent + "-> %s" % labels[id(block.next_block)]) + print() else: raise TypeError("unknown bytecode class") diff --git a/_pydevd_frame_eval/vendored/bytecode/concrete.py b/_pydevd_frame_eval/vendored/bytecode/concrete.py index bd756cba7..621259feb 100644 --- a/_pydevd_frame_eval/vendored/bytecode/concrete.py +++ b/_pydevd_frame_eval/vendored/bytecode/concrete.py @@ -1,25 +1,24 @@ import dis import inspect -import opcode as _opcode import struct import sys import types # alias to keep the 'bytecode' variable free from _pydevd_frame_eval.vendored import bytecode as _bytecode +import opcode as _opcode from _pydevd_frame_eval.vendored.bytecode.instr import ( UNSET, + CellVar, + Compare, + FreeVar, Instr, Label, SetLineno, - FreeVar, - CellVar, - Compare, - const_key, _check_arg_int, + const_key, ) - # - jumps use instruction # - lineno use bytes (dis.findlinestarts(code)) # - dis displays bytes @@ -284,8 +283,8 @@ def _assemble_lnotab(first_lineno, linenos): return b"".join(lnotab) @staticmethod - def _pack_linetable(doff, dlineno, linetable): - + def _pack_linetable(linetable, doff, dlineno): + # Ensure linenos are between -126 and +126, by using 127 lines jumps with a 0 byte offset while dlineno < -127: linetable.append(struct.pack("Bb", 0, -127)) dlineno -= -127 @@ -294,7 +293,12 @@ def _pack_linetable(doff, dlineno, linetable): linetable.append(struct.pack("Bb", 0, 127)) dlineno -= 127 + # Ensure offsets are less than 255. + # If an offset is larger, we first mark the line change with an offset of 254 + # then use as many 254 offset with no line change to reduce the offset to + # less than 254. if doff > 254: + linetable.append(struct.pack("Bb", 254, dlineno)) doff -= 254 @@ -309,16 +313,15 @@ def _pack_linetable(doff, dlineno, linetable): assert 0 <= doff <= 254 assert -127 <= dlineno <= 127 - def _assemble_linestable(self, first_lineno, linenos): if not linenos: return b"" linetable = [] old_offset = 0 - + iter_in = iter(linenos) - + offset, i_size, old_lineno = next(iter_in) old_dlineno = old_lineno - first_lineno for offset, i_size, lineno in iter_in: @@ -330,12 +333,12 @@ def _assemble_linestable(self, first_lineno, linenos): doff = offset - old_offset old_offset = offset - self._pack_linetable(doff, old_dlineno, linetable) + self._pack_linetable(linetable, doff, old_dlineno) old_dlineno = dlineno # Pack the line of the last instruction. doff = offset + i_size - old_offset - self._pack_linetable(doff, old_dlineno, linetable) + self._pack_linetable(linetable, doff, old_dlineno) return b"".join(linetable) diff --git a/_pydevd_frame_eval/vendored/bytecode/tests/long_lines_example.py b/_pydevd_frame_eval/vendored/bytecode/tests/long_lines_example.py new file mode 100644 index 000000000..d17d223cf --- /dev/null +++ b/_pydevd_frame_eval/vendored/bytecode/tests/long_lines_example.py @@ -0,0 +1,1053 @@ +# flake8: noqa +# fmt: off +def long_lines(): + a = 1 + b = 1 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + + # Notice the huge space here to the next instruction (we want to hit some odd conditions + # in the line table generation, which is why this sample file has such long lines). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + c = 1 if b > 1 else 2 if b > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + + d = 1 if c > 1 else 2 if c > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 if a > 1 else 2 if a > 0 else 3 if a > 4 else 23 + e = d + 1 + return e +# fmt: on diff --git a/_pydevd_frame_eval/vendored/bytecode/tests/test_concrete.py b/_pydevd_frame_eval/vendored/bytecode/tests/test_concrete.py index 510f6cd55..3c8db3b89 100644 --- a/_pydevd_frame_eval/vendored/bytecode/tests/test_concrete.py +++ b/_pydevd_frame_eval/vendored/bytecode/tests/test_concrete.py @@ -4,26 +4,26 @@ from tests_python.debug_constants import TEST_CYTHON pytestmark = pytest.mark.skipif(not IS_PY36_OR_GREATER or not IS_CPYTHON or not TEST_CYTHON, reason='Requires CPython >= 3.6') #!/usr/bin/env python3 -import opcode import sys import textwrap import types import unittest +import opcode from _pydevd_frame_eval.vendored.bytecode import ( UNSET, - Label, - Instr, - SetLineno, Bytecode, CellVar, - FreeVar, CompilerFlags, - ConcreteInstr, ConcreteBytecode, + ConcreteInstr, + FreeVar, + Instr, + Label, + SetLineno, ) from _pydevd_frame_eval.vendored.bytecode.concrete import OFFSET_AS_INSTRUCTION -from _pydevd_frame_eval.vendored.bytecode.tests import get_code, TestCase +from _pydevd_frame_eval.vendored.bytecode.tests import TestCase, get_code class ConcreteInstrTests(TestCase): @@ -1508,6 +1508,16 @@ def f(): f.__code__ = code.to_code() self.assertEqual(f(), (obj1, obj2, obj3, obj4)) + def test_packing_lines(self): + from _pydevd_frame_eval.vendored.bytecode.tests.long_lines_example import long_lines + import dis + + line_starts = list(dis.findlinestarts(long_lines.__code__)) + + concrete = ConcreteBytecode.from_code(long_lines.__code__) + as_code = concrete.to_code() + self.assertEqual(line_starts, list(dis.findlinestarts(as_code))) + if __name__ == "__main__": unittest.main() # pragma: no cover diff --git a/_pydevd_frame_eval/vendored/pydevd_offset_patch.diff b/_pydevd_frame_eval/vendored/pydevd_offset_patch.diff new file mode 100644 index 000000000..bc333263f --- /dev/null +++ b/_pydevd_frame_eval/vendored/pydevd_offset_patch.diff @@ -0,0 +1,86 @@ +This patch was applied to bytecode version 0.13.0 before calling +pydevd_fix_code.py to add an offset argument. + +--- a/bytecode/concrete.py ++++ b/bytecode/concrete.py +@@ -41,14 +41,15 @@ + It has a read-only size attribute. + """ + +- __slots__ = ("_size", "_extended_args") ++ __slots__ = ("_size", "_extended_args", "offset") + +- def __init__(self, name, arg=UNSET, *, lineno=None, extended_args=None): ++ def __init__(self, name, arg=UNSET, *, lineno=None, extended_args=None, offset=None): + # Allow to remember a potentially meaningless EXTENDED_ARG emitted by + # Python to properly compute the size and avoid messing up the jump + # targets + self._extended_args = extended_args + self._set(name, arg, lineno) ++ self.offset = offset + + def _check_arg(self, name, opcode, arg): + if opcode >= _opcode.HAVE_ARGUMENT: +@@ -111,7 +112,10 @@ + else: + arg = UNSET + name = _opcode.opname[op] +- return cls(name, arg, lineno=lineno) ++ # fabioz: added offset to ConcreteBytecode ++ # Need to keep an eye on https://github.com/MatthieuDartiailh/bytecode/issues/48 in ++ # case the library decides to add this in some other way. ++ return cls(name, arg, lineno=lineno, offset=index) + + + class ConcreteBytecode(_bytecode._BaseBytecodeList): +@@ -376,6 +380,7 @@ + arg, + lineno=instr.lineno, + extended_args=nb_extended_args, ++ offset=instr.offset, + ) + instructions[index] = instr + nb_extended_args = 0 +@@ -491,7 +496,7 @@ + arg = Compare(arg) + + if jump_target is None: +- instr = Instr(instr.name, arg, lineno=lineno) ++ instr = Instr(instr.name, arg, lineno=lineno, offset=instr.offset) + else: + instr_index = len(instructions) + instructions.append(instr) +@@ -505,7 +510,7 @@ + instr = instructions[index] + # FIXME: better error reporting on missing label + label = labels[jump_target] +- instructions[index] = Instr(instr.name, label, lineno=instr.lineno) ++ instructions[index] = Instr(instr.name, label, lineno=instr.lineno, offset=instr.offset) + + bytecode = _bytecode.Bytecode() + bytecode._copy_attr_from(self) +--- a/bytecode/instr.py ++++ b/bytecode/instr.py +@@ -165,10 +165,11 @@ + class Instr: + """Abstract instruction.""" + +- __slots__ = ("_name", "_opcode", "_arg", "_lineno") ++ __slots__ = ("_name", "_opcode", "_arg", "_lineno", "offset") + +- def __init__(self, name, arg=UNSET, *, lineno=None): ++ def __init__(self, name, arg=UNSET, *, lineno=None, offset=None): + self._set(name, arg, lineno) ++ self.offset = offset + + def _check_arg(self, name, opcode, arg): + if name == "EXTENDED_ARG": +@@ -344,7 +345,7 @@ + ) + + def copy(self): +- return self.__class__(self._name, self._arg, lineno=self._lineno) ++ return self.__class__(self._name, self._arg, lineno=self._lineno, offset=self.offset) + + def __repr__(self): + if self._arg is not UNSET: