[Python-checkins] gh-93678: Address stack exhaustion on WASI (GH-95296)

tiran webhook-mailer at python.org
Tue Jul 26 16:14:40 EDT 2022


https://github.com/python/cpython/commit/51c56f8d7242e98d5d6a3c7a7c51fe40f3da4512
commit: 51c56f8d7242e98d5d6a3c7a7c51fe40f3da4512
branch: main
author: Christian Heimes <christian at python.org>
committer: tiran <christian at python.org>
date: 2022-07-26T22:14:35+02:00
summary:

gh-93678: Address stack exhaustion on WASI (GH-95296)

files:
M Lib/test/test_compile.py
M Lib/test/test_dynamic.py

diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 11940bec492d8..e6194460b787d 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -108,6 +108,7 @@ def __getitem__(self, key):
         exec('z = a', g, d)
         self.assertEqual(d['z'], 12)
 
+    @unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
     def test_extended_arg(self):
         # default: 1000 * 2.5 = 2500 repetitions
         repeat = int(sys.getrecursionlimit() * 2.5)
@@ -542,6 +543,7 @@ def test_yet_more_evil_still_undecodable(self):
         self.assertIn(b"Non-UTF-8", res.err)
 
     @support.cpython_only
+    @unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
     def test_compiler_recursion_limit(self):
         # Expected limit is sys.getrecursionlimit() * the scaling factor
         # in symtable.c (currently 3)
diff --git a/Lib/test/test_dynamic.py b/Lib/test/test_dynamic.py
index 3e0fcf4d158f8..e896fc703c9a8 100644
--- a/Lib/test/test_dynamic.py
+++ b/Lib/test/test_dynamic.py
@@ -1,6 +1,7 @@
 # Test the most dynamic corner cases of Python's runtime semantics.
 
 import builtins
+import sys
 import unittest
 
 from test.support import swap_item, swap_attr
@@ -139,12 +140,14 @@ class MyGlobals(dict):
             def __missing__(self, key):
                 return int(key.removeprefix("_number_"))
 
-        code = "lambda: " + "+".join(f"_number_{i}" for i in range(1000))
-        sum_1000 = eval(code, MyGlobals())
-        expected = sum(range(1000))
+        # 1,000 on most systems
+        limit = sys.getrecursionlimit()
+        code = "lambda: " + "+".join(f"_number_{i}" for i in range(limit))
+        sum_func = eval(code, MyGlobals())
+        expected = sum(range(limit))
         # Warm up the the function for quickening (PEP 659)
         for _ in range(30):
-            self.assertEqual(sum_1000(), expected)
+            self.assertEqual(sum_func(), expected)
 
 if __name__ == "__main__":
     unittest.main()



More information about the Python-checkins mailing list