FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-159320: Enable stack size detection on Android (GH-159321) by miss-islington · Pull Request #159409 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 2 additions & 4 deletions Lib/test/test_ast/test_ast.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,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()
Expand Down
9 changes: 3 additions & 6 deletions Lib/test/test_compile.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -1043,8 +1041,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
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add dynamic detection of stack sizes on Android, allowing safer deep
recursion.
11 changes: 7 additions & 4 deletions Python/ceval.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,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;
Expand Down
Loading

Back | FazBrowse Home | New Git URL