From c4821d62b4f777a530f20aecd03fd819c4f4a009 Mon Sep 17 00:00:00 2001 From: Zachary Ware Date: Fri, 21 Nov 2014 23:35:12 -0600 Subject: Closes #22869: Move PyOS_CheckStack back to pythonrun.c --- Python/pythonrun.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'Python/pythonrun.c') diff --git a/Python/pythonrun.c b/Python/pythonrun.c index d435ef40fc..992a5a3ed0 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1376,6 +1376,43 @@ cleanup: } +#if defined(USE_STACKCHECK) +#if defined(WIN32) && defined(_MSC_VER) + +/* Stack checking for Microsoft C */ + +#include +#include + +/* + * Return non-zero when we run out of memory on the stack; zero otherwise. + */ +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; +} + +#endif /* WIN32 && _MSC_VER */ + +/* Alternate implementations can be added here... */ + +#endif /* USE_STACKCHECK */ + /* Deprecated C API functions still provided for binary compatiblity */ #undef PyParser_SimpleParseFile -- cgit v1.2.1