]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] GH-94438: Restore ability to jump over None tests (GH-111338)
authorSavannah Ostrowski <sostrowski@microsoft.com>
Wed, 25 Oct 2023 20:47:16 +0000 (13:47 -0700)
committerGitHub <noreply@github.com>
Wed, 25 Oct 2023 20:47:16 +0000 (20:47 +0000)
(cherry picked from commit 6640f1d)

Lib/test/test_sys_settrace.py
Misc/ACKS
Misc/NEWS.d/next/Core and Builtins/2023-10-23-22-11-09.gh-issue-94438.y2pITu.rst [new file with mode: 0644]
Objects/frameobject.c

index 3540192b5bb5bb8bdb8246ea07fc66d739592a15..e97e122534a2f398bfbb2edd6b9066caa9834024 100644 (file)
@@ -1952,6 +1952,40 @@ class JumpTestCase(unittest.TestCase):
         output.append(1)
         output.append(2)
 
+    @jump_test(1, 4, [5])
+    def test_jump_is_none_forwards(output):
+        x = None
+        if x is None:
+            output.append(3)
+        else:
+            output.append(5)
+
+    @jump_test(6, 5, [3, 5, 6])
+    def test_jump_is_none_backwards(output):
+        x = None
+        if x is None:
+            output.append(3)
+        else:
+            output.append(5)
+        output.append(6)
+
+    @jump_test(1, 4, [5])
+    def test_jump_is_not_none_forwards(output):
+        x = None
+        if x is not None:
+            output.append(3)
+        else:
+            output.append(5)
+
+    @jump_test(6, 5, [5, 5, 6])
+    def test_jump_is_not_none_backwards(output):
+        x = None
+        if x is not None:
+            output.append(3)
+        else:
+            output.append(5)
+        output.append(6)
+
     @jump_test(3, 5, [2, 5])
     def test_jump_out_of_block_forwards(output):
         for i in 1, 2:
index 6eff2cc1f19e2849ac34059a8b2137cf3654a772..7efa01db59e7ea1dfc27b2096b6bba3d2507fe92 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1324,6 +1324,7 @@ Michele Orrù
 Tomáš Orsava
 Oleg Oshmyan
 Denis Osipov
+Savannah Ostrowski
 Denis S. Otkidach
 Peter Otten
 Michael Otteneder
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-10-23-22-11-09.gh-issue-94438.y2pITu.rst b/Misc/NEWS.d/next/Core and Builtins/2023-10-23-22-11-09.gh-issue-94438.y2pITu.rst
new file mode 100644 (file)
index 0000000..b6e147a
--- /dev/null
@@ -0,0 +1 @@
+Fix a regression that prevented jumping across ``is None`` and ``is not None`` when debugging. Patch by Savannah Ostrowski.
index 425749d14cf0144c2024e5c7cec4d8c8d3952756..c95e8711880517e5b811e5ae25a1611a441cf74f 100644 (file)
@@ -315,19 +315,27 @@ mark_stacks(PyCodeObject *code_obj, int len)
                 case POP_JUMP_BACKWARD_IF_FALSE:
                 case POP_JUMP_FORWARD_IF_TRUE:
                 case POP_JUMP_BACKWARD_IF_TRUE:
+                case POP_JUMP_FORWARD_IF_NONE:
+                case POP_JUMP_BACKWARD_IF_NONE:
+                case POP_JUMP_FORWARD_IF_NOT_NONE:
+                case POP_JUMP_BACKWARD_IF_NOT_NONE:
                 {
                     int64_t target_stack;
                     int j = get_arg(code, i);
                     if (opcode == POP_JUMP_FORWARD_IF_FALSE ||
                         opcode == POP_JUMP_FORWARD_IF_TRUE ||
                         opcode == JUMP_IF_FALSE_OR_POP ||
-                        opcode == JUMP_IF_TRUE_OR_POP)
+                        opcode == JUMP_IF_TRUE_OR_POP ||
+                        opcode == POP_JUMP_FORWARD_IF_NONE ||
+                        opcode == POP_JUMP_FORWARD_IF_NOT_NONE)
                     {
                         j += i + 1;
                     }
                     else {
                         assert(opcode == POP_JUMP_BACKWARD_IF_FALSE ||
-                               opcode == POP_JUMP_BACKWARD_IF_TRUE);
+                               opcode == POP_JUMP_BACKWARD_IF_TRUE  ||
+                               opcode == POP_JUMP_BACKWARD_IF_NONE ||
+                               opcode == POP_JUMP_BACKWARD_IF_NOT_NONE);
                         j = i + 1 - j;
                     }
                     assert(j < len);