@@ -342,25 +342,17 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
342342void
343343_Py_UpdateRecursionLimits (PyThreadState * tstate )
344344{
345+ #ifdef WIN32
346+ ULONG_PTR low , high ;
347+ GetCurrentThreadStackLimits (& low , & high );
348+ tstate -> c_stack_top = (uintptr_t )high ;
349+ ULONG guarantee = 0 ;
350+ SetThreadStackGuarantee (& guarantee );
351+ tstate -> c_stack_hard_limit = ((uintptr_t )low ) + guarantee + PYOS_STACK_MARGIN_BYTES ;
352+ tstate -> c_stack_soft_limit = tstate -> c_stack_hard_limit + PYOS_STACK_MARGIN_BYTES ;
353+ #else
345354 char here ;
346355 uintptr_t here_addr = (uintptr_t )& here ;
347- #ifdef USE_STACKCHECK
348- int to_probe = PYOS_STACK_MARGIN_BYTES * 2 ;
349- if (tstate -> c_stack_top == 0 ) {
350- assert (tstate -> c_stack_soft_limit == UINTPTR_MAX );
351- tstate -> c_stack_top = _Py_SIZE_ROUND_UP (here_addr , 4096 );
352- tstate -> c_stack_soft_limit = tstate -> c_stack_top ;
353- to_probe = PYOS_STACK_MARGIN_BYTES * 4 ;
354- }
355- int depth ;
356- uintptr_t implicit_hard_limit = tstate -> c_stack_soft_limit - PYOS_STACK_MARGIN_BYTES ;
357- _Py_StackProbe (implicit_hard_limit , to_probe , & depth );
358- tstate -> c_stack_soft_limit = implicit_hard_limit - depth + PYOS_STACK_MARGIN_BYTES * 2 ;
359- if (depth != to_probe ) {
360- tstate -> c_stack_hard_limit = tstate -> c_stack_soft_limit - PYOS_STACK_MARGIN_BYTES ;
361- }
362- #else
363- assert (tstate -> c_stack_top == 0 );
364356 tstate -> c_stack_top = _Py_SIZE_ROUND_UP (here_addr , 4096 );
365357 tstate -> c_stack_soft_limit = tstate -> c_stack_top - Py_C_STACK_SIZE ;
366358 tstate -> c_stack_hard_limit = tstate -> c_stack_top - (Py_C_STACK_SIZE + PYOS_STACK_MARGIN_BYTES );
0 commit comments