diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py index 6ea27c463f3148..fd209374b0b84c 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -229,6 +229,18 @@ def __getitem__(self, key): self.assertEqual(resource.prlimit(0, resource.RLIMIT_AS, BadSeq()), limits) + # Issue 142317: Setting RLIMIT_STACK not working on Darwin + @unittest.skipIf(sys.platform == "vxworks", + "setting RLIMIT_STACK is not supported on VxWorks") + @unittest.skipUnless(hasattr(resource, 'RLIMIT_FSIZE'), 'requires resource.RLIMIT_FSIZE') + @unittest.skipIf( + sys.platform == "darwin" and support.check_sanitizer(ub=True), + "UBSan on MacOS explicitly compiles with a large stack size which breaks this test" + ) + def test_rlimit_stack(self): + resource.setrlimit( + resource.RLIMIT_STACK, resource.getrlimit(resource.RLIMIT_STACK) + ) if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/macOS/2026-05-20-18-23-16.gh-issue-142317.BDTpn9.rst b/Misc/NEWS.d/next/macOS/2026-05-20-18-23-16.gh-issue-142317.BDTpn9.rst new file mode 100644 index 00000000000000..a755de6b6ad7d5 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2026-05-20-18-23-16.gh-issue-142317.BDTpn9.rst @@ -0,0 +1,3 @@ +Avoid failures to set RLIMIT_STACK with the resource module by no longer +setting a default stack size for the cpython executable in the standard +build configuration. diff --git a/configure b/configure index 63b41117957cab..cce73d385d39af 100755 --- a/configure +++ b/configure @@ -14251,18 +14251,25 @@ then Darwin/*|iOS/*) LINKFORSHARED="$extra_undefs -framework CoreFoundation" - # Issue #18075: the default maximum stack size (8MBytes) is too - # small for the default recursion limit. Increase the stack size - # to ensure that tests don't crash - stack_size="1000000" # 16 MB + # Use the default stack size (0) unless otherwise requested to + # ensure that modifying RLIMIT_STACK works. + stack_size="0" if test "$with_ubsan" = "yes" then # Undefined behavior sanitizer requires an even deeper stack stack_size="4000000" # 64 MB fi + thread_stack_size="$stack_size" + # 0 does not map to a default thread stack size value, so we + # explicitly set the platform default (8MB) here if necessary. + if test "$stack_size" = "0" + then + thread_stack_size="800000" + fi + -printf "%s\n" "#define THREAD_STACK_SIZE 0x$stack_size" >>confdefs.h +printf "%s\n" "#define THREAD_STACK_SIZE 0x$thread_stack_size" >>confdefs.h if test $ac_sys_system = "Darwin"; then diff --git a/configure.ac b/configure.ac index 6df5d1bee31c67..927a9109557846 100644 --- a/configure.ac +++ b/configure.ac @@ -3719,18 +3719,25 @@ then Darwin/*|iOS/*) LINKFORSHARED="$extra_undefs -framework CoreFoundation" - # Issue #18075: the default maximum stack size (8MBytes) is too - # small for the default recursion limit. Increase the stack size - # to ensure that tests don't crash - stack_size="1000000" # 16 MB + # Use the default stack size (0) unless otherwise requested to + # ensure that modifying RLIMIT_STACK works. + stack_size="0" if test "$with_ubsan" = "yes" then # Undefined behavior sanitizer requires an even deeper stack stack_size="4000000" # 64 MB fi + thread_stack_size="$stack_size" + # 0 does not map to a default thread stack size value, so we + # explicitly set the platform default (8MB) here if necessary. + if test "$stack_size" = "0" + then + thread_stack_size="800000" + fi + AC_DEFINE_UNQUOTED([THREAD_STACK_SIZE], - [0x$stack_size], + [0x$thread_stack_size], [Custom thread stack size depending on chosen sanitizer runtimes.]) if test $ac_sys_system = "Darwin"; then