https://github.com/python/cpython/commit/a11d4cd2734d780b112649f9cdb692aed27c45b4
commit: a11d4cd2734d780b112649f9cdb692aed27c45b4
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: Yhg1s <[email protected]>
date: 2026-10-14T12:44:00Z
summary:

[3.14] gh-159320: Enable stack size detection on Android (GH-159321) (#159410)

gh-159320: Enable stack size detection on Android (GH-159321)

Extend the use of pthread_getattr_np in stack size detection from any glibc 
linux to any glibc *or* android linux. Update tests for android's new recursion 
limit.
(cherry picked from commit 8ff41c2ae723a62abace675b058dd4da8f90a397)

Co-authored-by: T. Wouters <[email protected]>
Co-authored-by: Malcolm Smith <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-16-38-00.gh-issue-159320._Yhg1s.rst
M Lib/test/test_ast/test_ast.py
M Lib/test/test_compile.py
M Python/ceval.c

diff --git a/Lib/test/test_ast/test_ast.py b/Lib/test/test_ast/test_ast.py
index 94ad8f85b17a24c..c7eb9b3bc78f0e1 100644
--- a/Lib/test/test_ast/test_ast.py
+++ b/Lib/test/test_ast/test_ast.py
@@ -1027,13 +1027,11 @@ def next(self):
         enum._test_simple_enum(_Precedence, _ast_unparse._Precedence)
 
     @support.cpython_only
-    @support.run_with_limited_c_stack(
-        100_000 if sys.platform == "android" else 500_000)
+    @support.run_with_limited_c_stack(500_000)
     @skip_wasi_stack_overflow()
     @skip_emscripten_stack_overflow()
     def test_ast_recursion_limit(self):
-        # Android test devices have less memory.
-        crash_depth = 100_000 if sys.platform == "android" else 500_000
+        crash_depth = 500_000
         success_depth = 200
         if _testinternalcapi is not None:
             remaining = _testinternalcapi.get_c_recursion_remaining()
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 021c3622566d1a2..91d1365a0a21ba4 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -724,14 +724,12 @@ def test_yet_more_evil_still_undecodable(self):
 
     @support.cpython_only
     @unittest.skipIf(support.is_wasi, "exhausts limited stack on WASI")
-    @support.run_with_limited_c_stack(
-        100_000 if sys.platform == "android" else 500_000)
+    @support.run_with_limited_c_stack(500_000)
     @support.skip_emscripten_stack_overflow()
     def test_compiler_recursion_limit(self):
         # Compiler frames are small
         limit = 100
-        # Android test devices have less memory.
-        crash_depth = limit * (1000 if sys.platform == "android" else 5000)
+        crash_depth = limit * 5000
         success_depth = limit
 
         def check_limit(prefix, repeated, mode="single"):
@@ -1037,8 +1035,7 @@ def test_path_like_objects(self):
     # complex statements.
     @support.requires_resource('cpu')
     def test_stack_overflow(self):
-        # Android test devices have less memory.
-        size = 100_000 if sys.platform == "android" else 200_000
+        size = 200_000
         compile("if a: b\n" * size, "<dummy>", "exec")
 
     # Multiple users rely on the fact that CPython does not generate
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-16-38-00.gh-issue-159320._Yhg1s.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-16-38-00.gh-issue-159320._Yhg1s.rst
new file mode 100644
index 000000000000000..25e8745ccc02bb0
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-13-16-38-00.gh-issue-159320._Yhg1s.rst
@@ -0,0 +1,2 @@
+Add dynamic detection of stack sizes on Android, allowing safer deep
+recursion.
diff --git a/Python/ceval.c b/Python/ceval.c
index b3dab2e9da5a716..eca281e37cc7f6c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -457,11 +457,14 @@ hardware_stack_limits(uintptr_t *base, uintptr_t *top, 
uintptr_t sp)
     *top = (uintptr_t)stack_addr;
     *base = ((uintptr_t)stack_addr) - stack_size;
 #else
-    /// XXX musl supports HAVE_PTHRED_GETATTR_NP, but the resulting stack size
-    /// (on alpine at least) is much smaller than expected and imposes undue 
limits
-    /// compared to the old stack size estimation.  (We assume musl is not 
glibc.)
+    // musl supports HAVE_PTHREAD_GETATTR_NP, but the resulting stack size
+    // (on alpine at least) is much smaller than expected and imposes undue
+    // limits compared to the old stack size estimation. musl doesn't give
+    // us a way to detect it, so we have to assume any non-glibc,
+    // non-Android Linux is musl and mustn't rely on pthread_getattr_np.
 #  if defined(HAVE_PTHREAD_GETATTR_NP) && !defined(_AIX) && \
-        !defined(__NetBSD__) && (defined(__GLIBC__) || !defined(__linux__))
+        !defined(__NetBSD__) && \
+        (defined(__GLIBC__) || defined(__ANDROID__) || !defined(__linux__))
     size_t stack_size, guard_size;
     void *stack_addr;
     pthread_attr_t attr;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to