Skip to content

Commit

Permalink
[3.11] gh-98925: Lower marshal recursion depth for WASI (GH-98938) (G…
Browse files Browse the repository at this point in the history
…H-98979)

* 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 9711265)

Co-authored-by: Brett Cannon <brett@python.org>
  • Loading branch information
miss-islington and brettcannon authored Nov 1, 2022
1 parent cd6655a commit 39e0627
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ PCbuild/win32/
Tools/unicode/data/
/autom4te.cache
/build/
/builddir/
/config.cache
/config.log
/config.status
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Lower the recursion depth for marshal on WASI to support
wasmtime 2.0/main.
2 changes: 2 additions & 0 deletions Python/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 39e0627

Please sign in to comment.