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.
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 struct_frozen(Structure):
                 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 @@ def _write_atomic(path, data, mode=0o666):
 #     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 @@ def _write_atomic(path, data, mode=0o666):
 # 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 @@ def func2():
                 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 = """\