Skip to content

Commit 12c7e50

Browse files
author
Savannah Ostrowski
authored
[3.11] GH-94438: Restore ability to jump over None tests (GH-111338)
(cherry picked from commit 6640f1d)
1 parent 6fea61a commit 12c7e50

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,40 @@ def test_jump_simple_backwards(output):
19521952
output.append(1)
19531953
output.append(2)
19541954

1955+
@jump_test(1, 4, [5])
1956+
def test_jump_is_none_forwards(output):
1957+
x = None
1958+
if x is None:
1959+
output.append(3)
1960+
else:
1961+
output.append(5)
1962+
1963+
@jump_test(6, 5, [3, 5, 6])
1964+
def test_jump_is_none_backwards(output):
1965+
x = None
1966+
if x is None:
1967+
output.append(3)
1968+
else:
1969+
output.append(5)
1970+
output.append(6)
1971+
1972+
@jump_test(1, 4, [5])
1973+
def test_jump_is_not_none_forwards(output):
1974+
x = None
1975+
if x is not None:
1976+
output.append(3)
1977+
else:
1978+
output.append(5)
1979+
1980+
@jump_test(6, 5, [5, 5, 6])
1981+
def test_jump_is_not_none_backwards(output):
1982+
x = None
1983+
if x is not None:
1984+
output.append(3)
1985+
else:
1986+
output.append(5)
1987+
output.append(6)
1988+
19551989
@jump_test(3, 5, [2, 5])
19561990
def test_jump_out_of_block_forwards(output):
19571991
for i in 1, 2:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ Michele Orrù
13241324
Tomáš Orsava
13251325
Oleg Oshmyan
13261326
Denis Osipov
1327+
Savannah Ostrowski
13271328
Denis S. Otkidach
13281329
Peter Otten
13291330
Michael Otteneder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a regression that prevented jumping across ``is None`` and ``is not None`` when debugging. Patch by Savannah Ostrowski.

Objects/frameobject.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,19 +315,27 @@ mark_stacks(PyCodeObject *code_obj, int len)
315315
case POP_JUMP_BACKWARD_IF_FALSE:
316316
case POP_JUMP_FORWARD_IF_TRUE:
317317
case POP_JUMP_BACKWARD_IF_TRUE:
318+
case POP_JUMP_FORWARD_IF_NONE:
319+
case POP_JUMP_BACKWARD_IF_NONE:
320+
case POP_JUMP_FORWARD_IF_NOT_NONE:
321+
case POP_JUMP_BACKWARD_IF_NOT_NONE:
318322
{
319323
int64_t target_stack;
320324
int j = get_arg(code, i);
321325
if (opcode == POP_JUMP_FORWARD_IF_FALSE ||
322326
opcode == POP_JUMP_FORWARD_IF_TRUE ||
323327
opcode == JUMP_IF_FALSE_OR_POP ||
324-
opcode == JUMP_IF_TRUE_OR_POP)
328+
opcode == JUMP_IF_TRUE_OR_POP ||
329+
opcode == POP_JUMP_FORWARD_IF_NONE ||
330+
opcode == POP_JUMP_FORWARD_IF_NOT_NONE)
325331
{
326332
j += i + 1;
327333
}
328334
else {
329335
assert(opcode == POP_JUMP_BACKWARD_IF_FALSE ||
330-
opcode == POP_JUMP_BACKWARD_IF_TRUE);
336+
opcode == POP_JUMP_BACKWARD_IF_TRUE ||
337+
opcode == POP_JUMP_BACKWARD_IF_NONE ||
338+
opcode == POP_JUMP_BACKWARD_IF_NOT_NONE);
331339
j = i + 1 - j;
332340
}
333341
assert(j < len);

0 commit comments

Comments
 (0)