summaryrefslogtreecommitdiffstats
path: root/Include/ceval.h
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-12 22:11:21 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-10-12 22:11:21 (GMT)
commit50856d5ae745d1c9f691afbd78572bf073c941cf (patch)
treed628ac3d10d0fa02551a8a45d43c03d948306600 /Include/ceval.h
parent60f26691f5aeff555f27c62aee11efb07e20ecdc (diff)
downloadcpython-50856d5ae745d1c9f691afbd78572bf073c941cf.zip
cpython-50856d5ae745d1c9f691afbd78572bf073c941cf.tar.gz
cpython-50856d5ae745d1c9f691afbd78572bf073c941cf.tar.bz2
sys.setrecursionlimit() now raises RecursionError
Issue #25274: sys.setrecursionlimit() now raises a RecursionError if the new recursion limit is too low depending at the current recursion depth. Modify also the "lower-water mark" formula to make it monotonic. This mark is used to decide when the overflowed flag of the thread state is reset.
Diffstat (limited to 'Include/ceval.h')
-rw-r--r--Include/ceval.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/Include/ceval.h b/Include/ceval.h
index eb1ee43..b5373a9 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -94,10 +94,16 @@ PyAPI_DATA(int) _Py_CheckRecursionLimit;
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
#endif
+/* Compute the "lower-water mark" for a recursion limit. When
+ * Py_LeaveRecursiveCall() is called with a recursion depth below this mark,
+ * the overflowed flag is reset to 0. */
+#define _Py_RecursionLimitLowerWaterMark(limit) \
+ (((limit) > 200) \
+ ? ((limit) - 50) \
+ : (3 * ((limit) >> 2)))
+
#define _Py_MakeEndRecCheck(x) \
- (--(x) < ((_Py_CheckRecursionLimit > 100) \
- ? (_Py_CheckRecursionLimit - 50) \
- : (3 * (_Py_CheckRecursionLimit >> 2))))
+ (--(x) < _Py_RecursionLimitLowerWaterMark(_Py_CheckRecursionLimit))
#define Py_ALLOW_RECURSION \
do { unsigned char _old = PyThreadState_GET()->recursion_critical;\