Skip to content

Commit 51c56f8

Browse files
authored
gh-93678: Address stack exhaustion on WASI (GH-95296)
1 parent 9af7f87 commit 51c56f8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Lib/test/test_compile.py

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __getitem__(self, key):
108108
exec('z = a', g, d)
109109
self.assertEqual(d['z'], 12)
110110

111+
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
111112
def test_extended_arg(self):
112113
# default: 1000 * 2.5 = 2500 repetitions
113114
repeat = int(sys.getrecursionlimit() * 2.5)
@@ -542,6 +543,7 @@ def test_yet_more_evil_still_undecodable(self):
542543
self.assertIn(b"Non-UTF-8", res.err)
543544

544545
@support.cpython_only
546+
@unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
545547
def test_compiler_recursion_limit(self):
546548
# Expected limit is sys.getrecursionlimit() * the scaling factor
547549
# in symtable.c (currently 3)

Lib/test/test_dynamic.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Test the most dynamic corner cases of Python's runtime semantics.
22

33
import builtins
4+
import sys
45
import unittest
56

67
from test.support import swap_item, swap_attr
@@ -139,12 +140,14 @@ class MyGlobals(dict):
139140
def __missing__(self, key):
140141
return int(key.removeprefix("_number_"))
141142

142-
code = "lambda: " + "+".join(f"_number_{i}" for i in range(1000))
143-
sum_1000 = eval(code, MyGlobals())
144-
expected = sum(range(1000))
143+
# 1,000 on most systems
144+
limit = sys.getrecursionlimit()
145+
code = "lambda: " + "+".join(f"_number_{i}" for i in range(limit))
146+
sum_func = eval(code, MyGlobals())
147+
expected = sum(range(limit))
145148
# Warm up the the function for quickening (PEP 659)
146149
for _ in range(30):
147-
self.assertEqual(sum_1000(), expected)
150+
self.assertEqual(sum_func(), expected)
148151

149152
if __name__ == "__main__":
150153
unittest.main()

0 commit comments

Comments
 (0)