@@ -347,20 +347,20 @@ _Py_ReachedRecursionLimitWithMargin(PyThreadState *tstate, int margin_count)
347347{
348348 uintptr_t here_addr = _Py_get_machine_stack_pointer ();
349349 _PyThreadStateImpl * _tstate = (_PyThreadStateImpl * )tstate ;
350- #ifdef __hppa__
351- if (here_addr <= _tstate -> c_stack_soft_limit - margin_count * _PyOS_STACK_MARGIN_BYTES ) {
352- #else
350+ #if _Py_STACK_GROWS_DOWN
353351 if (here_addr > _tstate -> c_stack_soft_limit + margin_count * _PyOS_STACK_MARGIN_BYTES ) {
352+ #else
353+ if (here_addr <= _tstate -> c_stack_soft_limit - margin_count * _PyOS_STACK_MARGIN_BYTES ) {
354354#endif
355355 return 0 ;
356356 }
357357 if (_tstate -> c_stack_hard_limit == 0 ) {
358358 _Py_InitializeRecursionLimits (tstate );
359359 }
360- #ifdef __hppa__
361- return here_addr > _tstate -> c_stack_soft_limit - margin_count * _PyOS_STACK_MARGIN_BYTES ;
362- #else
360+ #if _Py_STACK_GROWS_DOWN
363361 return here_addr <= _tstate -> c_stack_soft_limit + margin_count * _PyOS_STACK_MARGIN_BYTES ;
362+ #else
363+ return here_addr > _tstate -> c_stack_soft_limit - margin_count * _PyOS_STACK_MARGIN_BYTES ;
364364#endif
365365}
366366
@@ -369,10 +369,10 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
369369{
370370 uintptr_t here_addr = _Py_get_machine_stack_pointer ();
371371 _PyThreadStateImpl * _tstate = (_PyThreadStateImpl * )tstate ;
372- #ifdef __hppa__
373- if (here_addr > _tstate -> c_stack_hard_limit ) {
374- #else
372+ #if _Py_STACK_GROWS_DOWN
375373 if (here_addr < _tstate -> c_stack_hard_limit ) {
374+ #else
375+ if (here_addr > _tstate -> c_stack_hard_limit ) {
376376#endif
377377 Py_FatalError ("Unchecked stack overflow." );
378378 }
@@ -503,21 +503,21 @@ _Py_InitializeRecursionLimits(PyThreadState *tstate)
503503#ifdef _Py_THREAD_SANITIZER
504504 // Thread sanitizer crashes if we use more than half the stack.
505505 uintptr_t stacksize = top - base ;
506- # ifdef __hppa__
507- top -= stacksize /2 ;
508- # else
506+ # if _Py_STACK_GROWS_DOWN
509507 base += stacksize /2 ;
508+ # else
509+ top -= stacksize /2 ;
510510# endif
511511#endif
512512 _PyThreadStateImpl * _tstate = (_PyThreadStateImpl * )tstate ;
513- #ifdef __hppa__
514- _tstate -> c_stack_top = base ;
515- _tstate -> c_stack_hard_limit = top - _PyOS_STACK_MARGIN_BYTES ;
516- _tstate -> c_stack_soft_limit = top - _PyOS_STACK_MARGIN_BYTES * 2 ;
517- #else
513+ #if _Py_STACK_GROWS_DOWN
518514 _tstate -> c_stack_top = top ;
519515 _tstate -> c_stack_hard_limit = base + _PyOS_STACK_MARGIN_BYTES ;
520516 _tstate -> c_stack_soft_limit = base + _PyOS_STACK_MARGIN_BYTES * 2 ;
517+ #else
518+ _tstate -> c_stack_top = base ;
519+ _tstate -> c_stack_hard_limit = top - _PyOS_STACK_MARGIN_BYTES ;
520+ _tstate -> c_stack_soft_limit = top - _PyOS_STACK_MARGIN_BYTES * 2 ;
521521#endif
522522}
523523
@@ -530,14 +530,14 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
530530 uintptr_t here_addr = _Py_get_machine_stack_pointer ();
531531 assert (_tstate -> c_stack_soft_limit != 0 );
532532 assert (_tstate -> c_stack_hard_limit != 0 );
533- #ifdef __hppa__
534- if (here_addr > _tstate -> c_stack_hard_limit ) {
535- /* Overflowing while handling an overflow. Give up. */
536- int kbytes_used = (int )(here_addr - _tstate -> c_stack_top )/1024 ;
537- #else
533+ #if _Py_STACK_GROWS_DOWN
538534 if (here_addr < _tstate -> c_stack_hard_limit ) {
539535 /* Overflowing while handling an overflow. Give up. */
540536 int kbytes_used = (int )(_tstate -> c_stack_top - here_addr )/1024 ;
537+ #else
538+ if (here_addr > _tstate -> c_stack_hard_limit ) {
539+ /* Overflowing while handling an overflow. Give up. */
540+ int kbytes_used = (int )(here_addr - _tstate -> c_stack_top )/1024 ;
541541#endif
542542 char buffer [80 ];
543543 snprintf (buffer , 80 , "Unrecoverable stack overflow (used %d kB)%s" , kbytes_used , where );
@@ -547,10 +547,10 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
547547 return 0 ;
548548 }
549549 else {
550- #ifdef __hppa__
551- int kbytes_used = (int )(here_addr - _tstate -> c_stack_top )/1024 ;
552- #else
550+ #if _Py_STACK_GROWS_DOWN
553551 int kbytes_used = (int )(_tstate -> c_stack_top - here_addr )/1024 ;
552+ #else
553+ int kbytes_used = (int )(here_addr - _tstate -> c_stack_top )/1024 ;
554554#endif
555555 tstate -> recursion_headroom ++ ;
556556 _PyErr_Format (tstate , PyExc_RecursionError ,
0 commit comments