summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2023-08-04 09:10:29 (GMT)
committerGitHub <noreply@github.com>2023-08-04 09:10:29 (GMT)
commitfa45958450aa3489607daf9855ca0474a2a20878 (patch)
tree0e7a9b21503a7cf08691b99990ee6a538aa931b5 /Python/ceval.c
parent0bd784b355edf0d1911a7830db5d41c84171e367 (diff)
downloadcpython-fa45958450aa3489607daf9855ca0474a2a20878.zip
cpython-fa45958450aa3489607daf9855ca0474a2a20878.tar.gz
cpython-fa45958450aa3489607daf9855ca0474a2a20878.tar.bz2
GH-107263: Increase C stack limit for most functions, except `_PyEval_EvalFrameDefault()` (GH-107535)
* Set C recursion limit to 1500, set cost of eval loop to 2 frames, and compiler mutliply to 2.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 369b9a6..b85e967 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -624,6 +624,11 @@ extern const struct _PyCode_DEF(8) _Py_InitCleanup;
# pragma warning(disable:4102)
#endif
+
+/* _PyEval_EvalFrameDefault() is a *big* function,
+ * so consume 3 units of C stack */
+#define PY_EVAL_C_STACK_UNITS 2
+
PyObject* _Py_HOT_FUNCTION
_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
{
@@ -676,6 +681,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
frame->previous = &entry_frame;
cframe.current_frame = frame;
+ tstate->c_recursion_remaining -= (PY_EVAL_C_STACK_UNITS - 1);
if (_Py_EnterRecursiveCallTstate(tstate, "")) {
tstate->c_recursion_remaining--;
tstate->py_recursion_remaining--;
@@ -907,7 +913,7 @@ exit_unwind:
/* Restore previous cframe and exit */
tstate->cframe = cframe.previous;
assert(tstate->cframe->current_frame == frame->previous);
- _Py_LeaveRecursiveCallTstate(tstate);
+ tstate->c_recursion_remaining += PY_EVAL_C_STACK_UNITS;
return NULL;
}