summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-02-25 09:24:48 (GMT)
committerGitHub <noreply@github.com>2025-02-25 09:24:48 (GMT)
commit014223649c33b2febbccfa221c2ab7f18a8c0847 (patch)
tree5fb6432982ab3085d9275f20769f8fbcc581666b /Python/pythonrun.c
parent99088ab081279329b8362e1c24533fa0be303e6f (diff)
downloadcpython-014223649c33b2febbccfa221c2ab7f18a8c0847.zip
cpython-014223649c33b2febbccfa221c2ab7f18a8c0847.tar.gz
cpython-014223649c33b2febbccfa221c2ab7f18a8c0847.tar.bz2
GH-130396: Use computed stack limits on linux (GH-130398)
* Implement C recursion protection with limit pointers for Linux, MacOS and Windows * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c27
1 files changed, 3 insertions, 24 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 945e267..36390da 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1528,12 +1528,8 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
}
#if defined(USE_STACKCHECK)
-#if defined(WIN32) && defined(_MSC_VER)
-/* Stack checking for Microsoft C */
-
-#include <malloc.h>
-#include <excpt.h>
+/* Stack checking */
/*
* Return non-zero when we run out of memory on the stack; zero otherwise.
@@ -1541,27 +1537,10 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
int
PyOS_CheckStack(void)
{
- __try {
- /* alloca throws a stack overflow exception if there's
- not enough space left on the stack */
- alloca(PYOS_STACK_MARGIN * sizeof(void*));
- return 0;
- } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ?
- EXCEPTION_EXECUTE_HANDLER :
- EXCEPTION_CONTINUE_SEARCH) {
- int errcode = _resetstkoflw();
- if (errcode == 0)
- {
- Py_FatalError("Could not reset the stack!");
- }
- }
- return 1;
+ PyThreadState *tstate = _PyThreadState_GET();
+ return _Py_ReachedRecursionLimit(tstate);
}
-#endif /* WIN32 && _MSC_VER */
-
-/* Alternate implementations can be added here... */
-
#endif /* USE_STACKCHECK */
/* Deprecated C API functions still provided for binary compatibility */