Skip to content

Commit bd92b94

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 9bd5479 commit bd92b94

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
@@ -9524,6 +9524,12 @@ then
95249524
# -u libsys_s pulls in all symbols in libsys
95259525
Darwin/*)
95269526
LINKFORSHARED="$extra_undefs -framework CoreFoundation"
9527+
9528+
# Issue #18075: the default maximum stack size (8MBytes) is too
9529+
# small for the default recursion limit. Increase the stack size
9530+
# to ensure that tests don't crash
9531+
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
9532+
95279533
if test "$enable_framework"
95289534
then
95299535
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,12 @@ then
26822682
# -u libsys_s pulls in all symbols in libsys
26832683
Darwin/*)
26842684
LINKFORSHARED="$extra_undefs -framework CoreFoundation"
2685+
2686+
# Issue #18075: the default maximum stack size (8MBytes) is too
2687+
# small for the default recursion limit. Increase the stack size
2688+
# to ensure that tests don't crash
2689+
LINKFORSHARED="-Wl,-stack_size,1000000 $LINKFORSHARED"
2690+
26852691
if test "$enable_framework"
26862692
then
26872693
LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'

0 commit comments

Comments
 (0)