Skip to content

GH-93621: reorder code in with/async-with exception exit path to reduce the size of the exception table #93622

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

Merged
merged 6 commits into from
Jun 10, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add some checks for the exception table in dis output
  • Loading branch information
iritkatriel committed Jun 9, 2022
commit 946a191a62e13e17f8ba564c43b2571812687abb
20 changes: 20 additions & 0 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def bug42562():
POP_EXCEPT
RERAISE 1
ExceptionTable:
4 rows
""" % (TRACEBACK_CODE.co_firstlineno,
TRACEBACK_CODE.co_firstlineno + 1,
TRACEBACK_CODE.co_firstlineno + 2,
Expand Down Expand Up @@ -464,6 +465,7 @@ def _with(c):
POP_EXCEPT
RERAISE 1
ExceptionTable:
2 rows
""" % (_with.__code__.co_firstlineno,
_with.__code__.co_firstlineno + 1,
_with.__code__.co_firstlineno + 2,
Expand Down Expand Up @@ -536,6 +538,7 @@ async def _asyncwith(c):
POP_EXCEPT
RERAISE 1
ExceptionTable:
2 rows
""" % (_asyncwith.__code__.co_firstlineno,
_asyncwith.__code__.co_firstlineno + 1,
_asyncwith.__code__.co_firstlineno + 2,
Expand Down Expand Up @@ -580,6 +583,7 @@ def _tryfinallyconst(b):
POP_EXCEPT
RERAISE 1
ExceptionTable:
2 rows
""" % (_tryfinally.__code__.co_firstlineno,
_tryfinally.__code__.co_firstlineno + 1,
_tryfinally.__code__.co_firstlineno + 2,
Expand Down Expand Up @@ -609,6 +613,7 @@ def _tryfinallyconst(b):
POP_EXCEPT
RERAISE 1
ExceptionTable:
1 row
""" % (_tryfinallyconst.__code__.co_firstlineno,
_tryfinallyconst.__code__.co_firstlineno + 1,
_tryfinallyconst.__code__.co_firstlineno + 2,
Expand Down Expand Up @@ -803,6 +808,18 @@ def assert_offsets_increasing(self, text, delta):
self.assertGreaterEqual(offset, expected_offset, line)
expected_offset = offset + delta

def assert_exception_table_increasing(self, lines):
prev_start, prev_end = -1, -1
count = 0
for line in lines:
m = re.match(r' (\d+) to (\d+) -> \d+ \[\d+\]', line)
start, end = [int(g) for g in m.groups()]
self.assertGreaterEqual(end, start)
self.assertGreater(start, prev_end)
prev_start, prev_end = start, end
count += 1
return count

def strip_offsets(self, text):
lines = text.splitlines(True)
start, end = self.find_offset_column(lines)
Expand All @@ -816,6 +833,9 @@ def strip_offsets(self, text):
res.append(line)
else:
res.append(line[:start] + line[end:])
num_rows = self.assert_exception_table_increasing(lines)
if num_rows:
res.append(f"{num_rows} row{'s' if num_rows > 1 else ''}\n")
return "".join(res)

def do_disassembly_compare(self, got, expected, with_offsets=False):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy