Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] GH-94739: Backport GH-94958 to 311 #94965

Merged
merged 3 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ read_obj(uint16_t *p)
return (PyObject *)val;
}

/* See Objects/exception_handling_notes.txt for details.
*/
static inline unsigned char *
parse_varint(unsigned char *p, int *result) {
int val = p[0] & 63;
while (p[0] & 64) {
p++;
val = (val << 6) | (p[0] & 63);
}
*result = val;
return p+1;
}

static inline int
write_varint(uint8_t *ptr, unsigned int val)
{
Expand Down
47 changes: 29 additions & 18 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ def test_jump_out_of_block_backwards(output):
output.append(6)
output.append(7)

@async_jump_test(4, 5, [3], (ValueError, 'into'))
@async_jump_test(4, 5, [3, 5])
async def test_jump_out_of_async_for_block_forwards(output):
for i in [1]:
async for i in asynciter([1, 2]):
Expand Down Expand Up @@ -1921,7 +1921,7 @@ def test_jump_in_nested_finally(output):
output.append(8)
output.append(9)

@jump_test(6, 7, [2], (ValueError, 'within'))
@jump_test(6, 7, [2, 7], (ZeroDivisionError, ''))
def test_jump_in_nested_finally_2(output):
try:
output.append(2)
Expand All @@ -1932,7 +1932,7 @@ def test_jump_in_nested_finally_2(output):
output.append(7)
output.append(8)

@jump_test(6, 11, [2], (ValueError, 'within'))
@jump_test(6, 11, [2, 11], (ZeroDivisionError, ''))
def test_jump_in_nested_finally_3(output):
try:
output.append(2)
Expand Down Expand Up @@ -2043,8 +2043,8 @@ def test_jump_backwards_out_of_try_except_block(output):
output.append(5)
raise

@jump_test(5, 7, [4], (ValueError, 'within'))
def test_no_jump_between_except_blocks(output):
@jump_test(5, 7, [4, 7, 8])
def test_jump_between_except_blocks(output):
try:
1/0
except ZeroDivisionError:
Expand All @@ -2054,8 +2054,19 @@ def test_no_jump_between_except_blocks(output):
output.append(7)
output.append(8)

@jump_test(5, 6, [4], (ValueError, 'within'))
def test_no_jump_within_except_block(output):
@jump_test(5, 7, [4, 7, 8])
def test_jump_from_except_to_finally(output):
try:
1/0
except ZeroDivisionError:
output.append(4)
output.append(5)
finally:
output.append(7)
output.append(8)

@jump_test(5, 6, [4, 6, 7])
def test_jump_within_except_block(output):
try:
1/0
except:
Expand Down Expand Up @@ -2290,7 +2301,7 @@ def test_no_jump_backwards_into_for_block(output):
output.append(2)
output.append(3)

@async_jump_test(3, 2, [2, 2], (ValueError, 'within'))
@async_jump_test(3, 2, [2, 2], (ValueError, "can't jump into the body of a for loop"))
async def test_no_jump_backwards_into_async_for_block(output):
async for i in asynciter([1, 2]):
output.append(2)
Expand Down Expand Up @@ -2355,8 +2366,8 @@ def test_jump_backwards_into_try_except_block(output):
output.append(6)

# 'except' with a variable creates an implicit finally block
@jump_test(5, 7, [4], (ValueError, 'within'))
def test_no_jump_between_except_blocks_2(output):
@jump_test(5, 7, [4, 7, 8])
def test_jump_between_except_blocks_2(output):
try:
1/0
except ZeroDivisionError:
Expand Down Expand Up @@ -2392,23 +2403,23 @@ def test_jump_out_of_finally_block(output):
finally:
output.append(5)

@jump_test(1, 5, [], (ValueError, "into an exception"))
@jump_test(1, 5, [], (ValueError, "can't jump into an 'except' block as there's no exception"))
def test_no_jump_into_bare_except_block(output):
output.append(1)
try:
output.append(3)
except:
output.append(5)

@jump_test(1, 5, [], (ValueError, "into an exception"))
@jump_test(1, 5, [], (ValueError, "can't jump into an 'except' block as there's no exception"))
def test_no_jump_into_qualified_except_block(output):
output.append(1)
try:
output.append(3)
except Exception:
output.append(5)

@jump_test(3, 6, [2, 5, 6], (ValueError, "into an exception"))
@jump_test(3, 6, [2, 5, 6], (ValueError, "can't jump into an 'except' block as there's no exception"))
def test_no_jump_into_bare_except_block_from_try_block(output):
try:
output.append(2)
Expand All @@ -2419,7 +2430,7 @@ def test_no_jump_into_bare_except_block_from_try_block(output):
raise
output.append(8)

@jump_test(3, 6, [2], (ValueError, "into an exception"))
@jump_test(3, 6, [2], (ValueError, "can't jump into an 'except' block as there's no exception"))
def test_no_jump_into_qualified_except_block_from_try_block(output):
try:
output.append(2)
Expand All @@ -2430,8 +2441,8 @@ def test_no_jump_into_qualified_except_block_from_try_block(output):
raise
output.append(8)

@jump_test(7, 1, [1, 3, 6], (ValueError, "within"))
def test_no_jump_out_of_bare_except_block(output):
@jump_test(7, 1, [1, 3, 6, 1, 3, 6, 7])
def test_jump_out_of_bare_except_block(output):
output.append(1)
try:
output.append(3)
Expand All @@ -2440,8 +2451,8 @@ def test_no_jump_out_of_bare_except_block(output):
output.append(6)
output.append(7)

@jump_test(7, 1, [1, 3, 6], (ValueError, "within"))
def test_no_jump_out_of_qualified_except_block(output):
@jump_test(7, 1, [1, 3, 6, 1, 3, 6, 7])
def test_jump_out_of_qualified_except_block(output):
output.append(1)
try:
output.append(3)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow jumping within, out of, and across exception handlers in the debugger.
Loading