Skip to content

Commit 17c5361

Browse files
authored
Merge pull request RustPython#4554 from howjmay/co_stacksize
Add co_stacksize to code objects
2 parents 9b55505 + 95e863c commit 17c5361

File tree

2 files changed

+5
-48
lines changed

2 files changed

+5
-48
lines changed

Lib/test/test_compile.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -849,17 +849,13 @@ def compile_snippet(i):
849849
self.fail("stack sizes diverge with # of consecutive snippets: "
850850
"%s\n%s\n%s" % (sizes, snippet, out.getvalue()))
851851

852-
# TODO: RUSTPYTHON
853-
@unittest.expectedFailure
854852
def test_if(self):
855853
snippet = """
856854
if x:
857855
a
858856
"""
859857
self.check_stack_size(snippet)
860858

861-
# TODO: RUSTPYTHON
862-
@unittest.expectedFailure
863859
def test_if_else(self):
864860
snippet = """
865861
if x:
@@ -871,8 +867,6 @@ def test_if_else(self):
871867
"""
872868
self.check_stack_size(snippet)
873869

874-
# TODO: RUSTPYTHON
875-
@unittest.expectedFailure
876870
def test_try_except_bare(self):
877871
snippet = """
878872
try:
@@ -882,8 +876,6 @@ def test_try_except_bare(self):
882876
"""
883877
self.check_stack_size(snippet)
884878

885-
# TODO: RUSTPYTHON
886-
@unittest.expectedFailure
887879
def test_try_except_qualified(self):
888880
snippet = """
889881
try:
@@ -897,8 +889,6 @@ def test_try_except_qualified(self):
897889
"""
898890
self.check_stack_size(snippet)
899891

900-
# TODO: RUSTPYTHON
901-
@unittest.expectedFailure
902892
def test_try_except_as(self):
903893
snippet = """
904894
try:
@@ -912,8 +902,6 @@ def test_try_except_as(self):
912902
"""
913903
self.check_stack_size(snippet)
914904

915-
# TODO: RUSTPYTHON
916-
@unittest.expectedFailure
917905
def test_try_finally(self):
918906
snippet = """
919907
try:
@@ -923,17 +911,13 @@ def test_try_finally(self):
923911
"""
924912
self.check_stack_size(snippet)
925913

926-
# TODO: RUSTPYTHON
927-
@unittest.expectedFailure
928914
def test_with(self):
929915
snippet = """
930916
with x as y:
931917
a
932918
"""
933919
self.check_stack_size(snippet)
934920

935-
# TODO: RUSTPYTHON
936-
@unittest.expectedFailure
937921
def test_while_else(self):
938922
snippet = """
939923
while x:
@@ -943,17 +927,13 @@ def test_while_else(self):
943927
"""
944928
self.check_stack_size(snippet)
945929

946-
# TODO: RUSTPYTHON
947-
@unittest.expectedFailure
948930
def test_for(self):
949931
snippet = """
950932
for x in y:
951933
a
952934
"""
953935
self.check_stack_size(snippet)
954936

955-
# TODO: RUSTPYTHON
956-
@unittest.expectedFailure
957937
def test_for_else(self):
958938
snippet = """
959939
for x in y:
@@ -963,8 +943,6 @@ def test_for_else(self):
963943
"""
964944
self.check_stack_size(snippet)
965945

966-
# TODO: RUSTPYTHON
967-
@unittest.expectedFailure
968946
def test_for_break_continue(self):
969947
snippet = """
970948
for x in y:
@@ -979,8 +957,6 @@ def test_for_break_continue(self):
979957
"""
980958
self.check_stack_size(snippet)
981959

982-
# TODO: RUSTPYTHON
983-
@unittest.expectedFailure
984960
def test_for_break_continue_inside_try_finally_block(self):
985961
snippet = """
986962
for x in y:
@@ -998,8 +974,6 @@ def test_for_break_continue_inside_try_finally_block(self):
998974
"""
999975
self.check_stack_size(snippet)
1000976

1001-
# TODO: RUSTPYTHON
1002-
@unittest.expectedFailure
1003977
def test_for_break_continue_inside_finally_block(self):
1004978
snippet = """
1005979
for x in y:
@@ -1017,8 +991,6 @@ def test_for_break_continue_inside_finally_block(self):
1017991
"""
1018992
self.check_stack_size(snippet)
1019993

1020-
# TODO: RUSTPYTHON
1021-
@unittest.expectedFailure
1022994
def test_for_break_continue_inside_except_block(self):
1023995
snippet = """
1024996
for x in y:
@@ -1036,8 +1008,6 @@ def test_for_break_continue_inside_except_block(self):
10361008
"""
10371009
self.check_stack_size(snippet)
10381010

1039-
# TODO: RUSTPYTHON
1040-
@unittest.expectedFailure
10411011
def test_for_break_continue_inside_with_block(self):
10421012
snippet = """
10431013
for x in y:
@@ -1053,8 +1023,6 @@ def test_for_break_continue_inside_with_block(self):
10531023
"""
10541024
self.check_stack_size(snippet)
10551025

1056-
# TODO: RUSTPYTHON
1057-
@unittest.expectedFailure
10581026
def test_return_inside_try_finally_block(self):
10591027
snippet = """
10601028
try:
@@ -1067,8 +1035,6 @@ def test_return_inside_try_finally_block(self):
10671035
"""
10681036
self.check_stack_size(snippet)
10691037

1070-
# TODO: RUSTPYTHON
1071-
@unittest.expectedFailure
10721038
def test_return_inside_finally_block(self):
10731039
snippet = """
10741040
try:
@@ -1081,8 +1047,6 @@ def test_return_inside_finally_block(self):
10811047
"""
10821048
self.check_stack_size(snippet)
10831049

1084-
# TODO: RUSTPYTHON
1085-
@unittest.expectedFailure
10861050
def test_return_inside_except_block(self):
10871051
snippet = """
10881052
try:
@@ -1095,8 +1059,6 @@ def test_return_inside_except_block(self):
10951059
"""
10961060
self.check_stack_size(snippet)
10971061

1098-
# TODO: RUSTPYTHON
1099-
@unittest.expectedFailure
11001062
def test_return_inside_with_block(self):
11011063
snippet = """
11021064
with c:
@@ -1107,26 +1069,20 @@ def test_return_inside_with_block(self):
11071069
"""
11081070
self.check_stack_size(snippet)
11091071

1110-
# TODO: RUSTPYTHON
1111-
@unittest.expectedFailure
11121072
def test_async_with(self):
11131073
snippet = """
11141074
async with x as y:
11151075
a
11161076
"""
11171077
self.check_stack_size(snippet, async_=True)
11181078

1119-
# TODO: RUSTPYTHON
1120-
@unittest.expectedFailure
11211079
def test_async_for(self):
11221080
snippet = """
11231081
async for x in y:
11241082
a
11251083
"""
11261084
self.check_stack_size(snippet, async_=True)
11271085

1128-
# TODO: RUSTPYTHON
1129-
@unittest.expectedFailure
11301086
def test_async_for_else(self):
11311087
snippet = """
11321088
async for x in y:
@@ -1136,8 +1092,6 @@ def test_async_for_else(self):
11361092
"""
11371093
self.check_stack_size(snippet, async_=True)
11381094

1139-
# TODO: RUSTPYTHON
1140-
@unittest.expectedFailure
11411095
def test_for_break_continue_inside_async_with_block(self):
11421096
snippet = """
11431097
for x in y:
@@ -1153,8 +1107,6 @@ def test_for_break_continue_inside_async_with_block(self):
11531107
"""
11541108
self.check_stack_size(snippet, async_=True)
11551109

1156-
# TODO: RUSTPYTHON
1157-
@unittest.expectedFailure
11581110
def test_return_inside_async_with_block(self):
11591111
snippet = """
11601112
async with c:

vm/src/builtins/code.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ impl PyRef<PyCode> {
247247
self.code.arg_count as usize
248248
}
249249

250+
#[pygetset]
251+
fn co_stacksize(self) -> u32 {
252+
self.code.max_stackdepth
253+
}
254+
250255
#[pygetset]
251256
pub fn co_filename(self) -> PyStrRef {
252257
self.code.source_path.to_owned()

0 commit comments

Comments
 (0)