Skip to content

Commit b2afdf3

Browse files
committed
Add co_stacksize to code objects
Closes #4545
1 parent 6d71f75 commit b2afdf3

File tree

2 files changed

+5
-86
lines changed

2 files changed

+5
-86
lines changed

Lib/test/test_compile.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ def test_other_newlines(self):
3131
compile("hi\r\nstuff\r\ndef f():\n pass\r", "<test>", "exec")
3232
compile("this_is\rreally_old_mac\rdef f():\n pass", "<test>", "exec")
3333

34-
# TODO: RUSTPYTHON
35-
@unittest.expectedFailure
3634
def test_debug_assignment(self):
3735
# catch assignments to __debug__
3836
self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single')
@@ -151,8 +149,6 @@ def test_indentation(self):
151149
pass"""
152150
compile(s, "<string>", "exec")
153151

154-
# TODO: RUSTPYTHON
155-
@unittest.expectedFailure
156152
# This test is probably specific to CPython and may not generalize
157153
# to other implementations. We are trying to ensure that when
158154
# the first line of code starts after 256, correct line numbers
@@ -316,8 +312,6 @@ def test_lambda_doc(self):
316312
l = lambda: "foo"
317313
self.assertIsNone(l.__doc__)
318314

319-
# TODO: RUSTPYTHON
320-
@unittest.expectedFailure
321315
def test_encoding(self):
322316
code = b'# -*- coding: badencoding -*-\npass\n'
323317
self.assertRaises(SyntaxError, compile, code, 'tmp', 'exec')
@@ -430,8 +424,6 @@ def f():
430424
self.assertIn("_A__mangled_mod", A.f.__code__.co_varnames)
431425
self.assertIn("__package__", A.f.__code__.co_varnames)
432426

433-
# TODO: RUSTPYTHON
434-
@unittest.expectedFailure
435427
def test_compile_ast(self):
436428
fname = __file__
437429
if fname.lower().endswith('pyc'):
@@ -478,8 +470,6 @@ def f():
478470
d = {f(): f(), f(): f()}
479471
self.assertEqual(d, {1: 2, 3: 4})
480472

481-
# TODO: RUSTPYTHON
482-
@unittest.expectedFailure
483473
def test_compile_filename(self):
484474
for filename in 'file.py', b'file.py':
485475
code = compile('pass', filename, 'exec')
@@ -514,8 +504,6 @@ def test_single_statement(self):
514504
self.compile_single("if x:\n f(x)\nelse:\n g(x)")
515505
self.compile_single("class T:\n pass")
516506

517-
# TODO: RUSTPYTHON
518-
@unittest.expectedFailure
519507
def test_bad_single_statement(self):
520508
self.assertInvalidSingle('1\n2')
521509
self.assertInvalidSingle('def f(): pass')
@@ -526,8 +514,6 @@ def test_bad_single_statement(self):
526514
self.assertInvalidSingle('f()\nxy # blah\nblah()')
527515
self.assertInvalidSingle('x = 5 # comment\nx = 6\n')
528516

529-
# TODO: RUSTPYTHON
530-
@unittest.expectedFailure
531517
def test_particularly_evil_undecodable(self):
532518
# Issue 24022
533519
src = b'0000\x00\n00000000000\n\x00\n\x9e\n'
@@ -538,8 +524,6 @@ def test_particularly_evil_undecodable(self):
538524
res = script_helper.run_python_until_end(fn)[0]
539525
self.assertIn(b"Non-UTF-8", res.err)
540526

541-
# TODO: RUSTPYTHON
542-
@unittest.expectedFailure
543527
def test_yet_more_evil_still_undecodable(self):
544528
# Issue #25388
545529
src = b"#\x00\n#\xfd\n"
@@ -576,8 +560,6 @@ def check_limit(prefix, repeated):
576560
check_limit("a", "[0]")
577561
check_limit("a", "*a")
578562

579-
# TODO: RUSTPYTHON
580-
@unittest.expectedFailure
581563
def test_null_terminated(self):
582564
# The source code is null-terminated internally, but bytes-like
583565
# objects are accepted, which could be not terminated.
@@ -669,8 +651,6 @@ def unused_code_at_end():
669651
'RETURN_VALUE',
670652
list(dis.get_instructions(unused_code_at_end))[-1].opname)
671653

672-
# TODO: RUSTPYTHON
673-
@unittest.expectedFailure
674654
def test_dont_merge_constants(self):
675655
# Issue #25843: compile() must not merge constants which are equal
676656
# but have a different type.
@@ -711,8 +691,6 @@ def check_different_constants(const1, const2):
711691
self.assertTrue(f1(0))
712692
self.assertTrue(f2(0.0))
713693

714-
# TODO: RUSTPYTHON
715-
@unittest.expectedFailure
716694
def test_path_like_objects(self):
717695
# An implicit test for PyUnicode_FSDecoder().
718696
compile("42", FakePath("test_compile_pathlike"), "single")
@@ -756,8 +734,6 @@ def unused_block_while_else():
756734
self.assertEqual(None, opcodes[0].argval)
757735
self.assertEqual('RETURN_VALUE', opcodes[1].opname)
758736

759-
# TODO: RUSTPYTHON
760-
@unittest.expectedFailure
761737
def test_false_while_loop(self):
762738
def break_in_while():
763739
while False:
@@ -791,38 +767,24 @@ def check_stack_size(self, code):
791767
max_size = math.ceil(math.log(len(code.co_code)))
792768
self.assertLessEqual(code.co_stacksize, max_size)
793769

794-
# TODO: RUSTPYTHON
795-
@unittest.expectedFailure
796770
def test_and(self):
797771
self.check_stack_size("x and " * self.N + "x")
798772

799-
# TODO: RUSTPYTHON
800-
@unittest.expectedFailure
801773
def test_or(self):
802774
self.check_stack_size("x or " * self.N + "x")
803775

804-
# TODO: RUSTPYTHON
805-
@unittest.expectedFailure
806776
def test_and_or(self):
807777
self.check_stack_size("x and x or " * self.N + "x")
808778

809-
# TODO: RUSTPYTHON
810-
@unittest.expectedFailure
811779
def test_chained_comparison(self):
812780
self.check_stack_size("x < " * self.N + "x")
813781

814-
# TODO: RUSTPYTHON
815-
@unittest.expectedFailure
816782
def test_if_else(self):
817783
self.check_stack_size("x if x else " * self.N + "x")
818784

819-
# TODO: RUSTPYTHON
820-
@unittest.expectedFailure
821785
def test_binop(self):
822786
self.check_stack_size("x + " * self.N + "x")
823787

824-
# TODO: RUSTPYTHON
825-
@unittest.expectedFailure
826788
def test_func_and(self):
827789
code = "def f(x):\n"
828790
code += " x and x\n" * self.N
@@ -851,17 +813,13 @@ def compile_snippet(i):
851813
self.fail("stack sizes diverge with # of consecutive snippets: "
852814
"%s\n%s\n%s" % (sizes, snippet, out.getvalue()))
853815

854-
# TODO: RUSTPYTHON
855-
@unittest.expectedFailure
856816
def test_if(self):
857817
snippet = """
858818
if x:
859819
a
860820
"""
861821
self.check_stack_size(snippet)
862822

863-
# TODO: RUSTPYTHON
864-
@unittest.expectedFailure
865823
def test_if_else(self):
866824
snippet = """
867825
if x:
@@ -873,8 +831,6 @@ def test_if_else(self):
873831
"""
874832
self.check_stack_size(snippet)
875833

876-
# TODO: RUSTPYTHON
877-
@unittest.expectedFailure
878834
def test_try_except_bare(self):
879835
snippet = """
880836
try:
@@ -884,8 +840,6 @@ def test_try_except_bare(self):
884840
"""
885841
self.check_stack_size(snippet)
886842

887-
# TODO: RUSTPYTHON
888-
@unittest.expectedFailure
889843
def test_try_except_qualified(self):
890844
snippet = """
891845
try:
@@ -899,8 +853,6 @@ def test_try_except_qualified(self):
899853
"""
900854
self.check_stack_size(snippet)
901855

902-
# TODO: RUSTPYTHON
903-
@unittest.expectedFailure
904856
def test_try_except_as(self):
905857
snippet = """
906858
try:
@@ -914,8 +866,6 @@ def test_try_except_as(self):
914866
"""
915867
self.check_stack_size(snippet)
916868

917-
# TODO: RUSTPYTHON
918-
@unittest.expectedFailure
919869
def test_try_finally(self):
920870
snippet = """
921871
try:
@@ -925,17 +875,13 @@ def test_try_finally(self):
925875
"""
926876
self.check_stack_size(snippet)
927877

928-
# TODO: RUSTPYTHON
929-
@unittest.expectedFailure
930878
def test_with(self):
931879
snippet = """
932880
with x as y:
933881
a
934882
"""
935883
self.check_stack_size(snippet)
936884

937-
# TODO: RUSTPYTHON
938-
@unittest.expectedFailure
939885
def test_while_else(self):
940886
snippet = """
941887
while x:
@@ -945,17 +891,13 @@ def test_while_else(self):
945891
"""
946892
self.check_stack_size(snippet)
947893

948-
# TODO: RUSTPYTHON
949-
@unittest.expectedFailure
950894
def test_for(self):
951895
snippet = """
952896
for x in y:
953897
a
954898
"""
955899
self.check_stack_size(snippet)
956900

957-
# TODO: RUSTPYTHON
958-
@unittest.expectedFailure
959901
def test_for_else(self):
960902
snippet = """
961903
for x in y:
@@ -965,8 +907,6 @@ def test_for_else(self):
965907
"""
966908
self.check_stack_size(snippet)
967909

968-
# TODO: RUSTPYTHON
969-
@unittest.expectedFailure
970910
def test_for_break_continue(self):
971911
snippet = """
972912
for x in y:
@@ -981,8 +921,6 @@ def test_for_break_continue(self):
981921
"""
982922
self.check_stack_size(snippet)
983923

984-
# TODO: RUSTPYTHON
985-
@unittest.expectedFailure
986924
def test_for_break_continue_inside_try_finally_block(self):
987925
snippet = """
988926
for x in y:
@@ -1000,8 +938,6 @@ def test_for_break_continue_inside_try_finally_block(self):
1000938
"""
1001939
self.check_stack_size(snippet)
1002940

1003-
# TODO: RUSTPYTHON
1004-
@unittest.expectedFailure
1005941
def test_for_break_continue_inside_finally_block(self):
1006942
snippet = """
1007943
for x in y:
@@ -1019,8 +955,6 @@ def test_for_break_continue_inside_finally_block(self):
1019955
"""
1020956
self.check_stack_size(snippet)
1021957

1022-
# TODO: RUSTPYTHON
1023-
@unittest.expectedFailure
1024958
def test_for_break_continue_inside_except_block(self):
1025959
snippet = """
1026960
for x in y:
@@ -1038,8 +972,6 @@ def test_for_break_continue_inside_except_block(self):
1038972
"""
1039973
self.check_stack_size(snippet)
1040974

1041-
# TODO: RUSTPYTHON
1042-
@unittest.expectedFailure
1043975
def test_for_break_continue_inside_with_block(self):
1044976
snippet = """
1045977
for x in y:
@@ -1055,8 +987,6 @@ def test_for_break_continue_inside_with_block(self):
1055987
"""
1056988
self.check_stack_size(snippet)
1057989

1058-
# TODO: RUSTPYTHON
1059-
@unittest.expectedFailure
1060990
def test_return_inside_try_finally_block(self):
1061991
snippet = """
1062992
try:
@@ -1069,8 +999,6 @@ def test_return_inside_try_finally_block(self):
1069999
"""
10701000
self.check_stack_size(snippet)
10711001

1072-
# TODO: RUSTPYTHON
1073-
@unittest.expectedFailure
10741002
def test_return_inside_finally_block(self):
10751003
snippet = """
10761004
try:
@@ -1083,8 +1011,6 @@ def test_return_inside_finally_block(self):
10831011
"""
10841012
self.check_stack_size(snippet)
10851013

1086-
# TODO: RUSTPYTHON
1087-
@unittest.expectedFailure
10881014
def test_return_inside_except_block(self):
10891015
snippet = """
10901016
try:
@@ -1097,8 +1023,6 @@ def test_return_inside_except_block(self):
10971023
"""
10981024
self.check_stack_size(snippet)
10991025

1100-
# TODO: RUSTPYTHON
1101-
@unittest.expectedFailure
11021026
def test_return_inside_with_block(self):
11031027
snippet = """
11041028
with c:
@@ -1109,26 +1033,20 @@ def test_return_inside_with_block(self):
11091033
"""
11101034
self.check_stack_size(snippet)
11111035

1112-
# TODO: RUSTPYTHON
1113-
@unittest.expectedFailure
11141036
def test_async_with(self):
11151037
snippet = """
11161038
async with x as y:
11171039
a
11181040
"""
11191041
self.check_stack_size(snippet, async_=True)
11201042

1121-
# TODO: RUSTPYTHON
1122-
@unittest.expectedFailure
11231043
def test_async_for(self):
11241044
snippet = """
11251045
async for x in y:
11261046
a
11271047
"""
11281048
self.check_stack_size(snippet, async_=True)
11291049

1130-
# TODO: RUSTPYTHON
1131-
@unittest.expectedFailure
11321050
def test_async_for_else(self):
11331051
snippet = """
11341052
async for x in y:
@@ -1138,8 +1056,6 @@ def test_async_for_else(self):
11381056
"""
11391057
self.check_stack_size(snippet, async_=True)
11401058

1141-
# TODO: RUSTPYTHON
1142-
@unittest.expectedFailure
11431059
def test_for_break_continue_inside_async_with_block(self):
11441060
snippet = """
11451061
for x in y:
@@ -1155,8 +1071,6 @@ def test_for_break_continue_inside_async_with_block(self):
11551071
"""
11561072
self.check_stack_size(snippet, async_=True)
11571073

1158-
# TODO: RUSTPYTHON
1159-
@unittest.expectedFailure
11601074
def test_return_inside_async_with_block(self):
11611075
snippet = """
11621076
async with c:

vm/src/builtins/code.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ impl PyRef<PyCode> {
213213
self.code.arg_count
214214
}
215215

216+
#[pygetset]
217+
fn co_stacksize(self) -> u32 {
218+
self.code.max_stackdepth
219+
}
220+
216221
#[pygetset]
217222
pub fn co_filename(self) -> PyStrRef {
218223
self.code.source_path.to_owned()

0 commit comments

Comments
 (0)