Skip to content

Commit e4a7a3d

Browse files
committed
Address review comments
1 parent b274143 commit e4a7a3d

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

Lib/test/test_compile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,7 @@ def check_limit(prefix, repeated, mode="single"):
721721
expect_ok = prefix + repeated * success_depth
722722
compile(expect_ok, '<test>', mode)
723723
broken = prefix + repeated * crash_depth
724-
details = "Compiling ({!r} + {!r} * {})".format(
725-
prefix, repeated, crash_depth)
724+
details = f"Compiling ({prefix!r} + {repeated!r} * {crash_depth})"
726725
with self.assertRaises(RecursionError, msg=details):
727726
compile(broken, '<test>', mode)
728727

Lib/test/test_dynamic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import unittest
66

7-
from test.support import swap_item, swap_attr, is_wasi, Py_DEBUG
7+
from test.support import swap_item, swap_attr, skip_wasi_stack_overflow, Py_DEBUG
88

99

1010
class RebindBuiltinsTests(unittest.TestCase):
@@ -134,7 +134,8 @@ def test_eval_gives_lambda_custom_globals(self):
134134

135135
self.assertEqual(foo(), 7)
136136

137-
@unittest.skipIf(is_wasi, "requires too much stack")
137+
138+
@skip_wasi_stack_overflow()
138139
def test_load_global_specialization_failure_keeps_oparg(self):
139140
# https://github.com/python/cpython/issues/91625
140141
class MyGlobals(dict):

Lib/test/test_json/test_recursion.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ def default(self, o):
7070

7171
@support.skip_emscripten_stack_overflow()
7272
def test_highly_nested_objects_decoding(self):
73+
very_deep = 200000
7374
# test that loading highly-nested objects doesn't segfault when C
7475
# accelerations are used. See #12017
7576
with self.assertRaises(RecursionError):
7677
with support.infinite_recursion():
77-
self.loads('{"a":' * 200000 + '1' + '}' * 200000)
78+
self.loads('{"a":' * very_deep + '1' + '}' * very_deep)
7879
with self.assertRaises(RecursionError):
7980
with support.infinite_recursion():
80-
self.loads('{"a":' * 200000 + '[1]' + '}' * 200000)
81+
self.loads('{"a":' * very_deep + '[1]' + '}' * very_deep)
8182
with self.assertRaises(RecursionError):
8283
with support.infinite_recursion():
83-
self.loads('[' * 200000 + '1' + ']' * 200000)
84+
self.loads('[' * very_deep + '1' + ']' * very_deep)
8485

8586
@support.skip_wasi_stack_overflow()
8687
@support.skip_emscripten_stack_overflow()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Use actual stack limits (from pthread_getattr_np) for linux, and other
2-
systems with _GNU_SOURCE defined, when determining limits for C stack
1+
Use actual stack limits (from :manpage:`pthread_getattr_np(3)`) for linux, and other
2+
systems with ``_GNU_SOURCE`` defined, when determining limits for C stack
33
protection.

Python/ceval.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,11 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
364364
void *stack_addr;
365365
pthread_attr_t attr;
366366
int err = pthread_getattr_np(pthread_self(), &attr);
367-
err |= pthread_attr_getguardsize(&attr, &guard_size);
368-
err |= pthread_attr_getstack(&attr, &stack_addr, &stack_size);
369-
err |= pthread_attr_destroy(&attr);
367+
if (err == 0) {
368+
err = pthread_attr_getguardsize(&attr, &guard_size);
369+
err |= pthread_attr_getstack(&attr, &stack_addr, &stack_size);
370+
err |= pthread_attr_destroy(&attr);
371+
}
370372
if (err == 0) {
371373
uintptr_t base = ((uintptr_t)stack_addr) + guard_size;
372374
_tstate->c_stack_top = base + stack_size;

0 commit comments

Comments
 (0)