From c1e2a00168a47905702ed0082bc0335328ae0cce Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 1 Nov 2022 15:51:05 -0700 Subject: [PATCH] gh-98925: Lower marshal recursion depth for WASI (GH-98938) For wasmtime 2.0, the stack depth cost is 6% higher. This causes the default max `marshal` recursion depth to blow the stack. As the default marshal depth is 2000 and Windows is set to 1000, split the difference and choose 1500 for WASI to be safe. (cherry picked from commit 9711265182f163ba381e7800e3748ac28710f9ef) Co-authored-by: Brett Cannon --- .gitignore | 1 + Lib/test/test_marshal.py | 2 ++ .../2022-10-31-18-03-10.gh-issue-98925.zpdjVd.rst | 2 ++ Python/marshal.c | 2 ++ 4 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-10-31-18-03-10.gh-issue-98925.zpdjVd.rst diff --git a/.gitignore b/.gitignore index b3b22f471c2765..d42e111666f1e9 100644 --- a/.gitignore +++ b/.gitignore @@ -114,6 +114,7 @@ PCbuild/win32/ Tools/unicode/data/ /autom4te.cache /build/ +/builddir/ /config.cache /config.log /config.status diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index aae86cc257d7e1..f5956fc3a15a00 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -259,6 +259,8 @@ def test_recursion_limit(self): #if os.name == 'nt' and hasattr(sys, 'gettotalrefcount'): if os.name == 'nt': MAX_MARSHAL_STACK_DEPTH = 1000 + elif sys.platform == 'wasi': + MAX_MARSHAL_STACK_DEPTH = 1500 else: MAX_MARSHAL_STACK_DEPTH = 2000 for i in range(MAX_MARSHAL_STACK_DEPTH - 2): diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-10-31-18-03-10.gh-issue-98925.zpdjVd.rst b/Misc/NEWS.d/next/Core and Builtins/2022-10-31-18-03-10.gh-issue-98925.zpdjVd.rst new file mode 100644 index 00000000000000..7c965dc752f70b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-10-31-18-03-10.gh-issue-98925.zpdjVd.rst @@ -0,0 +1,2 @@ +Lower the recursion depth for marshal on WASI to support (in-development) +wasmtime 2.0. diff --git a/Python/marshal.c b/Python/marshal.c index 90a44050918006..2690f55766c83b 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -34,6 +34,8 @@ module marshal */ #if defined(MS_WINDOWS) #define MAX_MARSHAL_STACK_DEPTH 1000 +#elif defined(__wasi__) +#define MAX_MARSHAL_STACK_DEPTH 1500 #else #define MAX_MARSHAL_STACK_DEPTH 2000 #endif