summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-08-31 19:23:01 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-08-31 19:23:01 (GMT)
commitee5adfbae6df9a4ae8d73bccc4f3a55b7f382d11 (patch)
treeecbac10d7a319d2d655ad1ddffcfdb9b75c9c70b /Python/ceval.c
parentc88b99ce060e37a9098708483b7e3c8b5db87fbd (diff)
downloadcpython-ee5adfbae6df9a4ae8d73bccc4f3a55b7f382d11.zip
cpython-ee5adfbae6df9a4ae8d73bccc4f3a55b7f382d11.tar.gz
cpython-ee5adfbae6df9a4ae8d73bccc4f3a55b7f382d11.tar.bz2
add user-modifiable recursion_limit
ceval.c: define recurion_limit (static), default value is 2500 define Py_GetRecursionLimit and Py_SetRecursionLimit raise RuntimeError if limit is exceeded PC/config.h: remove plat-specific definition sysmodule.c: add sys.(get|set)recursionlimit
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index b399b63..7e11250 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -298,6 +298,20 @@ Py_MakePendingCalls(void)
}
+/* The interpreter's recursion limit */
+
+static int recursion_limit = 2500;
+
+int Py_GetRecursionLimit(void)
+{
+ return recursion_limit;
+}
+
+void Py_SetRecursionLimit(int new_limit)
+{
+ recursion_limit = new_limit;
+}
+
/* Status code for main loop (reason for stack unwind) */
enum why_code {
@@ -326,10 +340,6 @@ PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals)
/* Interpreter main loop */
-#ifndef MAX_RECURSION_DEPTH
-#define MAX_RECURSION_DEPTH 10000
-#endif
-
static PyObject *
eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
PyObject **args, int argcount, PyObject **kws, int kwcount,
@@ -565,7 +575,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
}
}
- if (++tstate->recursion_depth > MAX_RECURSION_DEPTH) {
+ if (++tstate->recursion_depth > recursion_limit) {
--tstate->recursion_depth;
PyErr_SetString(PyExc_RuntimeError,
"Maximum recursion depth exceeded");