[pypy-commit] pypy py3.5: Fix for http://bugs.python.org/issue25274 in sys.setrecursionlimit()
arigo
pypy.commits at gmail.com
Fri Oct 14 09:45:17 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r87788:e9aaf617e117
Date: 2016-10-14 15:44 +0200
http://bitbucket.org/pypy/pypy/changeset/e9aaf617e117/
Log: Fix for http://bugs.python.org/issue25274 in sys.setrecursionlimit()
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -41,6 +41,7 @@
f = ec.getnextframe_nohidden(f)
+ at jit.dont_look_inside
@unwrap_spec(new_limit="c_int")
def setrecursionlimit(space, new_limit):
"""setrecursionlimit() sets the maximum number of nested calls that
@@ -50,11 +51,19 @@
depending on the compiler settings) for ~1400 calls. Setting the
value to N reserves N/1000 times 768KB of stack space.
"""
- from rpython.rlib.rstack import _stack_set_length_fraction
+ from rpython.rlib.rstack import _stack_set_length_fraction, stack_check
+ from rpython.rlib.rstackovf import StackOverflow
if new_limit <= 0:
raise oefmt(space.w_ValueError, "recursion limit must be positive")
+ try:
+ _stack_set_length_fraction(new_limit * 0.001)
+ stack_check()
+ except StackOverflow:
+ old_limit = space.sys.recursionlimit
+ _stack_set_length_fraction(old_limit * 0.001)
+ raise oefmt(space.w_RecursionError,
+ "maximum recursion depth exceeded")
space.sys.recursionlimit = new_limit
- _stack_set_length_fraction(new_limit * 0.001)
def getrecursionlimit(space):
"""Return the last value set by setrecursionlimit().
More information about the pypy-commit
mailing list