summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2025-02-24 10:16:08 (GMT)
committerGitHub <noreply@github.com>2025-02-24 10:16:08 (GMT)
commitef29104f7d7ad7864f5f153cd7391af73d7cef63 (patch)
tree38c76b08e114a9e6e993081b828b64978bfefa2e /Python/pythonrun.c
parent0ff16115741aeaaaf7f963f68d5c575efb960277 (diff)
downloadcpython-ef29104f7d7ad7864f5f153cd7391af73d7cef63.zip
cpython-ef29104f7d7ad7864f5f153cd7391af73d7cef63.tar.gz
cpython-ef29104f7d7ad7864f5f153cd7391af73d7cef63.tar.bz2
GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now (GH130413)
Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now Unfortunatlely, the change broke some buildbots. This reverts commit 2498c22fa0a2b560491bc503fa676585c1a603d0.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 36390da..945e267 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1528,8 +1528,12 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
}
#if defined(USE_STACKCHECK)
+#if defined(WIN32) && defined(_MSC_VER)
-/* Stack checking */
+/* Stack checking for Microsoft C */
+
+#include <malloc.h>
+#include <excpt.h>
/*
* Return non-zero when we run out of memory on the stack; zero otherwise.
@@ -1537,10 +1541,27 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
int
PyOS_CheckStack(void)
{
- PyThreadState *tstate = _PyThreadState_GET();
- return _Py_ReachedRecursionLimit(tstate);
+ __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;
}
+#endif /* WIN32 && _MSC_VER */
+
+/* Alternate implementations can be added here... */
+
#endif /* USE_STACKCHECK */
/* Deprecated C API functions still provided for binary compatibility */