diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h index e0b1f099abd613..db46e188b860e7 100644 --- a/Include/internal/pycore_ceval.h +++ b/Include/internal/pycore_ceval.h @@ -16,13 +16,6 @@ extern "C" { #include "pycore_stats.h" // EVAL_CALL_STAT_INC() #include "pycore_typedefs.h" // _PyInterpreterFrame -/* HP PA-RISC has a stack that goes up */ -#ifdef __hppa__ -# define _Py_STACK_GROWS_DOWN 0 -#else -# define _Py_STACK_GROWS_DOWN 1 -#endif - /* Forward declarations */ struct _ceval_runtime_state; diff --git a/Include/pyport.h b/Include/pyport.h index 62db8d07701d1d..c2e7beba86b5e5 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -682,4 +682,10 @@ extern "C" { #endif +// Assume the stack grows down if not specified by autoconf +#ifndef _Py_STACK_GROWS_DOWN +# define _Py_STACK_GROWS_DOWN 1 +#endif + + #endif /* Py_PYPORT_H */ diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 4e73be20e1b709..e451b656c82ea7 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3324,6 +3324,10 @@ _testcapi_exec(PyObject *m) PyModule_AddObject(m, "INT64_MAX", PyLong_FromInt64(INT64_MAX)); PyModule_AddObject(m, "UINT64_MAX", PyLong_FromUInt64(UINT64_MAX)); + if (PyModule_AddIntMacro(m, _Py_STACK_GROWS_DOWN)) { + return -1; + } + if (PyModule_AddIntMacro(m, Py_single_input)) { return -1; } diff --git a/configure b/configure index 211f84399064a0..37a3068725bfba 100755 --- a/configure +++ b/configure @@ -965,6 +965,7 @@ LDLIBRARY LIBRARY BUILDEXEEXT NO_AS_NEEDED +_Py_STACK_GROWS_DOWN MULTIARCH_CPPFLAGS PLATFORM_TRIPLET MULTIARCH @@ -7211,6 +7212,18 @@ if test x$MULTIARCH != x; then fi +# Guess C stack direction +case $host in #( + hppa-*) : + _Py_STACK_GROWS_DOWN=0 ;; #( + *) : + _Py_STACK_GROWS_DOWN=1 ;; +esac + +printf "%s\n" "#define _Py_STACK_GROWS_DOWN $_Py_STACK_GROWS_DOWN" >>confdefs.h + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for PEP 11 support tier" >&5 printf %s "checking for PEP 11 support tier... " >&6; } case $host/$ac_cv_cc_name in #( diff --git a/configure.ac b/configure.ac index 35bf153a8987b2..eab6c02a110800 100644 --- a/configure.ac +++ b/configure.ac @@ -1202,6 +1202,14 @@ if test x$MULTIARCH != x; then fi AC_SUBST([MULTIARCH_CPPFLAGS]) +# Guess C stack direction +AS_CASE([$host], + [hppa-*], [_Py_STACK_GROWS_DOWN=0], + [_Py_STACK_GROWS_DOWN=1]) +AC_DEFINE_UNQUOTED([_Py_STACK_GROWS_DOWN], [$_Py_STACK_GROWS_DOWN], + [Define to 1 if the machine stack grows down (default); 0 if it grows up.]) +AC_SUBST([_Py_STACK_GROWS_DOWN]) + dnl Support tiers according to https://peps.python.org/pep-0011/ dnl dnl NOTE: Windows support tiers are defined in PC/pyconfig.h. diff --git a/pyconfig.h.in b/pyconfig.h.in index 72870411bc086a..3919315466e0f3 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -2026,6 +2026,9 @@ /* HACL* library can compile SIMD256 implementations */ #undef _Py_HACL_CAN_COMPILE_VEC256 +/* Define to 1 if the machine stack grows down (default); 0 if it grows up. */ +#undef _Py_STACK_GROWS_DOWN + /* Define if you want to use tail-calling interpreters in CPython. */ #undef _Py_TAIL_CALL_INTERP