Skip to content

Commit bf82cd3

Browse files
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546)
Under some conditions the earlier fix for bpo-18075, "Infinite recursion tests triggering a segfault on Mac OS X", now causes failures on macOS when attempting to change stack limit with resource.setrlimit resource.RLIMIT_STACK, like regrtest does when running the test suite. The reverted change had specified a non-default stack size when linking the python executable on macOS. As of macOS 10.14.4, the previous code causes a hard failure when running tests, although similar failures had been seen under some conditions under some earlier systems. Reverting the change to the interpreter stack size at link time helped for release builds but caused some tests to fail when built --with-pydebug. Try the opposite approach: continue to build the interpreter with an increased stack size on macOS and remove the failing setrlimit call in regrtest initialization. This will definitely avoid the resource.RLIMIT_STACK error and should have no, or fewer, side effects. (cherry picked from commit 5bbbc73) Co-authored-by: Ned Deily <[email protected]>
1 parent f3130fa commit bf82cd3

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

Lib/test/libregrtest/setup.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,6 @@ def setup_tests(ns):
5858
if getattr(module, '__file__', None):
5959
module.__file__ = os.path.abspath(module.__file__)
6060

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-
7761
if ns.huntrleaks:
7862
unittest.BaseTestSuite._cleanup = False
7963

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9541,6 +9541,12 @@ then
95419541
# -u libsys_s pulls in all symbols in libsys
95429542
Darwin/*)
95439543
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+
95449550
if test "$enable_framework"
95459551
then
95469552
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,12 @@ then
27082708
# -u libsys_s pulls in all symbols in libsys
27092709
Darwin/*)
27102710
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+
27112717
if test "$enable_framework"
27122718
then
27132719
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'

0 commit comments

Comments
 (0)