bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546) · python/cpython@bf82cd3 (original) (raw)

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -58,22 +58,6 @@ def setup_tests(ns):
58 58 if getattr(module, '__file__', None):
59 59 module.__file__ = os.path.abspath(module.__file__)
60 60
61 -# MacOSX (a.k.a. Darwin) has a default stack size that is too small
62 -# for deeply recursive regular expressions. We see this as crashes in
63 -# the Python test suite when running test_re.py and test_sre.py. The
64 -# fix is to set the stack limit to 2048.
65 -# This approach may also be useful for other Unixy platforms that
66 -# suffer from small default stack limits.
67 -if sys.platform == 'darwin':
68 -try:
69 -import resource
70 -except ImportError:
71 -pass
72 -else:
73 -soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
74 -newsoft = min(hard, max(soft, 1024*2048))
75 -resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
76 -
77 61 if ns.huntrleaks:
78 62 unittest.BaseTestSuite._cleanup = False
79 63
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
1 +Avoid test suite failures on macOS by no longer calling resource.setrlimit
2 +to increase the process stack size limit at runtime. The runtime change is
3 +no longer needed since the interpreter is being built with a larger default
4 +stack size.
Original file line number Diff line number Diff line change
@@ -9541,6 +9541,12 @@ then
9541 9541 # -u libsys_s pulls in all symbols in libsys
9542 9542 Darwin/*)
9543 9543 LINKFORSHARED="$extra_undefs -framework CoreFoundation"
9544 +
9545 +# Issue #18075: the default maximum stack size (8MBytes) is too
9546 +# small for the default recursion limit. Increase the stack size
9547 +# to ensure that tests don't crash
9548 + LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
9549 +
9544 9550 if test "$enable_framework"
9545 9551 then
9546 9552 LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
Original file line number Diff line number Diff line change
@@ -2708,6 +2708,12 @@ then
2708 2708 # -u libsys_s pulls in all symbols in libsys
2709 2709 Darwin/*)
2710 2710 LINKFORSHARED="$extra_undefs -framework CoreFoundation"
2711 +
2712 +# Issue #18075: the default maximum stack size (8MBytes) is too
2713 +# small for the default recursion limit. Increase the stack size
2714 +# to ensure that tests don't crash
2715 + LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
2716 +
2711 2717 if test "$enable_framework"
2712 2718 then
2713 2719 LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'