diff options
author | Thomas Wouters <thomas@python.org> | 2024-01-17 15:19:08 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2024-01-17 15:19:08 (GMT) |
commit | 8cf37f244fa88b4e860e853ecb59b75f3f218191 (patch) | |
tree | e041227ef6570ce382ec14a5056523cc5ec7a60b | |
parent | 1a2e18b23c61f5e5de49e617ca2e454cdedce418 (diff) | |
parent | 5c351fc85afd2ed167694a7dfe066741a5cdab53 (diff) | |
download | cpython-8cf37f244fa88b4e860e853ecb59b75f3f218191.zip cpython-8cf37f244fa88b4e860e853ecb59b75f3f218191.tar.gz cpython-8cf37f244fa88b4e860e853ecb59b75f3f218191.tar.bz2 |
Merge branch 'main' of https://github.com/python/cpython
-rw-r--r-- | Doc/whatsnew/3.12.rst | 12 | ||||
-rwxr-xr-x | Lib/pdb.py | 36 | ||||
-rw-r--r-- | Lib/test/test_lzma.py | 8 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-05-08-09-30-00.gh-issue-104282.h4c6Eb.rst | 3 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-11-24-19-08-50.gh-issue-112343.RarGFC.rst | 1 | ||||
-rw-r--r-- | Modules/_lzmamodule.c | 4 |
7 files changed, 71 insertions, 2 deletions
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 9a2ccf7..77b12f9 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -1374,6 +1374,18 @@ APIs: * :meth:`!unittest.TestProgram.usageExit` (:gh:`67048`) * :class:`!webbrowser.MacOSX` (:gh:`86421`) * :class:`classmethod` descriptor chaining (:gh:`89519`) +* :mod:`importlib.resources` deprecated methods: + + * ``contents()`` + * ``is_resource()`` + * ``open_binary()`` + * ``open_text()`` + * ``path()`` + * ``read_binary()`` + * ``read_text()`` + + Use :func:`importlib.resources.files()` instead. Refer to `importlib-resources: Migrating from Legacy + <https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy>`_ (:gh:`106531`) Pending Removal in Python 3.14 ------------------------------ @@ -76,6 +76,7 @@ import bdb import dis import code import glob +import token import codeop import pprint import signal @@ -601,6 +602,39 @@ class Pdb(bdb.Bdb, cmd.Cmd): except: self._error_exc() + def _replace_convenience_variables(self, line): + """Replace the convenience variables in 'line' with their values. + e.g. $foo is replaced by __pdb_convenience_variables["foo"]. + Note: such pattern in string literals will be skipped""" + + if "$" not in line: + return line + + dollar_start = dollar_end = -1 + replace_variables = [] + try: + for t in tokenize.generate_tokens(io.StringIO(line).readline): + token_type, token_string, start, end, _ = t + if token_type == token.OP and token_string == '$': + dollar_start, dollar_end = start, end + elif start == dollar_end and token_type == token.NAME: + # line is a one-line command so we only care about column + replace_variables.append((dollar_start[1], end[1], token_string)) + except tokenize.TokenError: + return line + + if not replace_variables: + return line + + last_end = 0 + line_pieces = [] + for start, end, name in replace_variables: + line_pieces.append(line[last_end:start] + f'__pdb_convenience_variables["{name}"]') + last_end = end + line_pieces.append(line[last_end:]) + + return ''.join(line_pieces) + def precmd(self, line): """Handle alias expansion and ';;' separator.""" if not line.strip(): @@ -635,7 +669,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): line = line[:marker].rstrip() # Replace all the convenience variables - line = re.sub(r'\$([a-zA-Z_][a-zA-Z0-9_]*)', r'__pdb_convenience_variables["\1"]', line) + line = self._replace_convenience_variables(line) return line diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py index 13b2009..65e6488 100644 --- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -1401,6 +1401,14 @@ class MiscellaneousTestCase(unittest.TestCase): self.assertEqual(filterspec["lc"], 3) self.assertEqual(filterspec["dict_size"], 8 << 20) + # see gh-104282 + filters = [lzma.FILTER_X86, lzma.FILTER_POWERPC, + lzma.FILTER_IA64, lzma.FILTER_ARM, + lzma.FILTER_ARMTHUMB, lzma.FILTER_SPARC] + for f in filters: + filterspec = lzma._decode_filter_properties(f, b"") + self.assertEqual(filterspec, {"id": f}) + def test_filter_properties_roundtrip(self): spec1 = lzma._decode_filter_properties( lzma.FILTER_LZMA1, b"]\x00\x00\x80\x00") diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index d53fe3c..333d8a9 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -847,9 +847,12 @@ def test_convenience_variables(): >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ... '$_frame.f_lineno', # Check frame convenience variable + ... '$ _frame', # This should be a syntax error ... '$a = 10', # Set a convenience variable ... '$a', # Print its value + ... 'p "$a"', # Print the string $a ... 'p $a + 2', # Do some calculation + ... 'p f"$a = {$a}"', # Make sure $ in string is not converted and f-string works ... 'u', # Switch frame ... '$_frame.f_lineno', # Make sure the frame changed ... '$a', # Make sure the value persists @@ -869,11 +872,17 @@ def test_convenience_variables(): -> try: (Pdb) $_frame.f_lineno 3 + (Pdb) $ _frame + *** SyntaxError: invalid syntax (Pdb) $a = 10 (Pdb) $a 10 + (Pdb) p "$a" + '$a' (Pdb) p $a + 2 12 + (Pdb) p f"$a = {$a}" + '$a = 10' (Pdb) u > <doctest test.test_pdb.test_convenience_variables[1]>(2)test_function() -> util_function() diff --git a/Misc/NEWS.d/next/Library/2023-05-08-09-30-00.gh-issue-104282.h4c6Eb.rst b/Misc/NEWS.d/next/Library/2023-05-08-09-30-00.gh-issue-104282.h4c6Eb.rst new file mode 100644 index 0000000..569ce66 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-08-09-30-00.gh-issue-104282.h4c6Eb.rst @@ -0,0 +1,3 @@ +Fix null pointer dereference in :func:`lzma._decode_filter_properties` +due to improper handling of BCJ filters with properties of zero length. +Patch by Radislav Chugunov. diff --git a/Misc/NEWS.d/next/Library/2023-11-24-19-08-50.gh-issue-112343.RarGFC.rst b/Misc/NEWS.d/next/Library/2023-11-24-19-08-50.gh-issue-112343.RarGFC.rst new file mode 100644 index 0000000..aaa50fc --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-24-19-08-50.gh-issue-112343.RarGFC.rst @@ -0,0 +1 @@ +Improve handling of pdb convenience variables to avoid replacing string contents. diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index eb90c30..f6bfbfa 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -492,7 +492,9 @@ build_filter_spec(const lzma_filter *f) case LZMA_FILTER_ARMTHUMB: case LZMA_FILTER_SPARC: { lzma_options_bcj *options = f->options; - ADD_FIELD(options, start_offset); + if (options) { + ADD_FIELD(options, start_offset); + } break; } default: |