@@ -1552,47 +1552,18 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
15521552#include <malloc.h>
15531553#include <excpt.h>
15541554
1555- void _Py_StackProbe (uintptr_t from , int bytes , int * probed )
1556- {
1557- assert ((bytes & 4095 ) == 0 );
1558- int depth = 4096 ;
1559- char here ;
1560- uintptr_t here_addr = (uintptr_t )& here ;
1561- __try
1562- {
1563- while (depth <= bytes ) {
1564- uintptr_t probe_point = from - depth + 64 ;
1565- if (probe_point < here_addr ) {
1566- /* alloca throws a stack overflow exception if there's
1567- * not enough space left on the stack */
1568- alloca (here_addr - probe_point );
1569- }
1570- * probed = depth ;
1571- depth += 4096 ;
1572- }
1573- }
1574- __except (GetExceptionCode () == STATUS_STACK_OVERFLOW ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH )
1575- {
1576- int errcode = _resetstkoflw ();
1577- if (errcode == 0 )
1578- {
1579- Py_FatalError ("Could not reset the stack!" );
1580- }
1581- }
1582- }
1583-
15841555/*
15851556 * Return non-zero when we run out of memory on the stack; zero otherwise.
15861557 */
15871558int PyOS_CheckStack (void )
15881559{
15891560 char here ;
15901561 uintptr_t here_addr = (uintptr_t )& here ;
1591- uintptr_t from = _Py_SIZE_ROUND_UP ( here_addr , 4096 );
1592- int depth ;
1593- _Py_StackProbe ( from , PYOS_STACK_MARGIN_BYTES * 2 , & depth );
1594- assert ( depth <= PYOS_STACK_MARGIN_BYTES * 2 );
1595- if (depth == PYOS_STACK_MARGIN_BYTES * 2 ) {
1562+ PyThreadState * tstate = _PyThreadState_GET ( );
1563+ if ( tstate -> c_stack_hard_limit == 0 ) {
1564+ _Py_InitializeRecursionLimits ( tstate );
1565+ }
1566+ if (here_addr >= tstate -> c_stack_soft_limit ) {
15961567 return 0 ;
15971568 }
15981569 else {
0 commit comments