summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-04-29 12:12:51 (GMT)
committerGitHub <noreply@github.com>2021-04-29 12:12:51 (GMT)
commitc76da79b37d2bcbe575cc927ba0a9b7a9ce465db (patch)
treecf5e884131b3f44f038355ff4980cfbb97a6e228 /Lib
parent53dd6c99b39d90935c00bc1558582e494641248e (diff)
downloadcpython-c76da79b37d2bcbe575cc927ba0a9b7a9ce465db.zip
cpython-c76da79b37d2bcbe575cc927ba0a9b7a9ce465db.tar.gz
cpython-c76da79b37d2bcbe575cc927ba0a9b7a9ce465db.tar.bz2
bpo-42739: Don't use sentinels to mark end of line table. (GH-25657)
* Add length parameter to PyLineTable_InitAddressRange and doen't use sentinel values at end of table. Makes the line number table more robust. * Update PyCodeAddressRange to match PEP 626.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/ctypes/test/test_values.py6
-rw-r--r--Lib/importlib/_bootstrap_external.py3
-rw-r--r--Lib/test/test_code.py6
-rw-r--r--Lib/test/test_dis.py2
4 files changed, 12 insertions, 5 deletions
diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py
index b38b63f..7514fe8 100644
--- a/Lib/ctypes/test/test_values.py
+++ b/Lib/ctypes/test/test_values.py
@@ -80,9 +80,9 @@ class PythonValuesTestCase(unittest.TestCase):
continue
items.append((entry.name.decode("ascii"), entry.size))
- expected = [("__hello__", 139),
- ("__phello__", -139),
- ("__phello__.spam", 139),
+ expected = [("__hello__", 137),
+ ("__phello__", -137),
+ ("__phello__.spam", 137),
]
self.assertEqual(items, expected, "PyImport_FrozenModules example "
"in Doc/library/ctypes.rst may be out of date")
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 6620b24..2b28187 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -350,6 +350,7 @@ _code_type = type(_write_atomic.__code__)
# Python 3.10a7 3435 Use instruction offsets (as opposed to byte offsets).
# Python 3.10b1 3436 (Add GEN_START bytecode #43683)
# Python 3.10b1 3437 (Undo making 'annotations' future by default - We like to dance among core devs!)
+# Python 3.10b1 3438 Safer line number table handling.
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -359,7 +360,7 @@ _code_type = type(_write_atomic.__code__)
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3437).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3438).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 467e8e5..6aaf04c 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -264,6 +264,12 @@ class CodeTest(unittest.TestCase):
new_code = code.replace(**{attr: value})
self.assertEqual(getattr(new_code, attr), value)
+ def test_empty_linetable(self):
+ def func():
+ pass
+ new_code = code = func.__code__.replace(co_linetable=b'')
+ self.assertEqual(list(new_code.co_lines()), [])
+
def isinterned(s):
return s is sys.intern(('_' + s + '_')[1:-1])
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 8e36ae2..8d05935 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -172,7 +172,7 @@ def bug42562():
# Set line number for 'pass' to None
-bug42562.__code__ = bug42562.__code__.replace(co_linetable=b'\x04\x80\xff\x80')
+bug42562.__code__ = bug42562.__code__.replace(co_linetable=b'\x04\x80')
dis_bug42562 = """\