Skip to content

Commit 782854f

Browse files
bpo-34602: Avoid failures setting macOS stack resource limit (GH-14546) (GH-14549)
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 <nad@python.org>
1 parent 29d6905 commit 782854f

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
@@ -60,22 +60,6 @@ def setup_tests(ns):
6060
if getattr(module, '__file__', None):
6161
module.__file__ = os.path.abspath(module.__file__)
6262

63-
# MacOSX (a.k.a. Darwin) has a default stack size that is too small
64-
# for deeply recursive regular expressions. We see this as crashes in
65-
# the Python test suite when running test_re.py and test_sre.py. The
66-
# fix is to set the stack limit to 2048.
67-
# This approach may also be useful for other Unixy platforms that
68-
# suffer from small default stack limits.
69-
if sys.platform == 'darwin':
70-
try:
71-
import resource
72-
except ImportError:
73-
pass
74-
else:
75-
soft, hard = resource.getrlimit(resource.RLIMIT_STACK)
76-
newsoft = min(hard, max(soft, 1024*2048))
77-
resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
78-
7963
if ns.huntrleaks:
8064
unittest.BaseTestSuite._cleanup = False
8165

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
@@ -9504,6 +9504,12 @@ then
95049504
# -u libsys_s pulls in all symbols in libsys
95059505
Darwin/*)
95069506
LINKFORSHARED="$extra_undefs -framework CoreFoundation"
9507+
9508+
# Issue #18075: the default maximum stack size (8MBytes) is too
9509+
# small for the default recursion limit. Increase the stack size
9510+
# to ensure that tests don't crash
9511+
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
9512+
95079513
if test "$enable_framework"
95089514
then
95099515
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,6 +2697,12 @@ then
26972697
# -u libsys_s pulls in all symbols in libsys
26982698
Darwin/*)
26992699
LINKFORSHARED="$extra_undefs -framework CoreFoundation"
2700+
2701+
# Issue #18075: the default maximum stack size (8MBytes) is too
2702+
# small for the default recursion limit. Increase the stack size
2703+
# to ensure that tests don't crash
2704+
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
2705+
27002706
if test "$enable_framework"
27012707
then
27022708
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'

0 commit comments

Comments
 (0)