Skip to content

Commit 6b34c22

Browse files
committed
improve test coverage!
1 parent d743a3d commit 6b34c22

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Lib/test/test_code.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,23 @@ def foo(a, b):
550550
co_framesize = _testinternalcapi.get_co_framesize(c)
551551
FRAME_SPECIALS_SIZE = co_framesize - c.co_stacksize - co_nlocalsplus
552552

553-
ptr_sizeof = ctypes.sizeof(ctypes.c_void_p) # sizeof(PyObject *)
553+
ps = ctypes.sizeof(ctypes.c_void_p) # sizeof(PyObject *)
554+
smallest_evil_co_stacksize = (
555+
(_testcapi.INT_MAX - co_nlocalsplus - FRAME_SPECIALS_SIZE) // ps
556+
)
554557

555558
for evil_co_stacksize in [
556559
_testcapi.INT_MAX,
557-
_testcapi.INT_MAX // ptr_sizeof,
558-
(_testcapi.INT_MAX - co_nlocalsplus - FRAME_SPECIALS_SIZE) // ptr_sizeof,
560+
_testcapi.INT_MAX // ps,
561+
smallest_evil_co_stacksize,
559562
]:
560563
with (
561564
self.subTest(evil_co_stacksize),
562565
self.assertRaisesRegex(OverflowError, "co_stacksize")
563566
):
564-
foo.__code__.__replace__(co_stacksize=evil_co_stacksize)
567+
c.__replace__(co_stacksize=evil_co_stacksize)
568+
569+
c.__replace__(co_stacksize=smallest_evil_co_stacksize - 1)
565570

566571

567572
def isinterned(s):

0 commit comments

Comments
 (0)