Skip to content

Commit 52b27d6

Browse files
committed
Add some asserts and up limits
1 parent 5151a85 commit 52b27d6

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

Lib/test/list_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_repr(self):
6464
@skip_emscripten_stack_overflow()
6565
def test_repr_deep(self):
6666
a = self.type2test([])
67-
for i in range(100_000):
67+
for i in range(150_000):
6868
a = self.type2test([a])
6969
self.assertRaises(RecursionError, repr, a)
7070

Lib/test/support/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,7 @@ def adjust_int_max_str_digits(max_digits):
26282628

26292629
def exceeds_recursion_limit():
26302630
"""For recursion tests, easily exceeds default recursion limit."""
2631-
return 100_000
2631+
return 150_000
26322632

26332633

26342634
# Windows doesn't have os.uname() but it doesn't support s390x.

Lib/test/test_ast/test_ast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def next(self):
755755
@skip_wasi_stack_overflow()
756756
@skip_emscripten_stack_overflow()
757757
def test_ast_recursion_limit(self):
758-
crash_depth = 200_000
758+
crash_depth = 300_000
759759
success_depth = 200
760760
if _testinternalcapi is not None:
761761
remaining = _testinternalcapi.get_c_recursion_remaining()

Lib/test/test_compile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ def test_yet_more_evil_still_undecodable(self):
714714
def test_compiler_recursion_limit(self):
715715
# Compiler frames are small
716716
limit = 100
717-
fail_depth = limit * 1000
718-
crash_depth = limit * 2000
717+
fail_depth = limit * 1500
718+
crash_depth = limit * 3000
719719
success_depth = limit
720720

721721
def check_limit(prefix, repeated, mode="single"):

Python/ceval.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,26 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
360360
_tstate->c_stack_hard_limit = ((uintptr_t)low) + guarantee + PYOS_STACK_MARGIN_BYTES;
361361
_tstate->c_stack_soft_limit = _tstate->c_stack_hard_limit + PYOS_STACK_MARGIN_BYTES;
362362
#else
363+
char here;
364+
uintptr_t here_addr = (uintptr_t)&here;
363365
# if defined(HAVE_PTHREAD_GETATTR_NP)
364366
size_t stack_size, guard_size;
365367
void *stack_addr;
366368
pthread_attr_t attr;
367369
int err = pthread_getattr_np(pthread_self(), &attr);
368370
err |= pthread_attr_getguardsize(&attr, &guard_size);
369371
err |= pthread_attr_getstack(&attr, &stack_addr, &stack_size);
372+
err |= pthread_attr_destroy(&attr);
370373
if (err == 0) {
371374
uintptr_t base = ((uintptr_t)stack_addr) + guard_size;
372375
_tstate->c_stack_top = base + stack_size;
373376
_tstate->c_stack_soft_limit = base + PYOS_STACK_MARGIN_BYTES * 2;
374377
_tstate->c_stack_hard_limit = base + PYOS_STACK_MARGIN_BYTES;
378+
assert(_tstate->c_stack_soft_limit < here_addr);
379+
assert(here_addr < _tstate->c_stack_top);
375380
return;
376381
}
377382
# endif
378-
char here;
379-
uintptr_t here_addr = (uintptr_t)&here;
380383
_tstate->c_stack_top = _Py_SIZE_ROUND_UP(here_addr, 4096);
381384
_tstate->c_stack_soft_limit = _tstate->c_stack_top - Py_C_STACK_SIZE;
382385
_tstate->c_stack_hard_limit = _tstate->c_stack_top - (Py_C_STACK_SIZE + PYOS_STACK_MARGIN_BYTES);

0 commit comments

Comments
 (0)