From: Serhiy Storchaka Date: Mon, 29 Jun 2026 14:20:14 +0000 (+0300) Subject: [3.15] gh-152502: Detect optional curses functions with configure probes (GH-152504... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a4ffa6f2128308ba5ba81a7c8912fb781a271e0;p=thirdparty%2FPython%2Fcpython.git [3.15] gh-152502: Detect optional curses functions with configure probes (GH-152504) (GH-152589) set_escdelay(), set_tabsize() and the ESCDELAY and TABSIZE variables were gated only by the ncurses-specific NCURSES_EXT_FUNCS macro, which excluded them when building against other curses implementations such as NetBSD curses even when they provided them. Detect each with a configure capability probe and gate on HAVE_CURSES_*. (cherry picked from commit 0635e55b47e306aa6cc0610105775849b0699e2c) Co-authored-by: Claude Opus 4.8 --- diff --git a/Misc/NEWS.d/next/Build/2026-06-28-16-17-55.gh-issue-152502.6SNqMg.rst b/Misc/NEWS.d/next/Build/2026-06-28-16-17-55.gh-issue-152502.6SNqMg.rst new file mode 100644 index 000000000000..cc0fabed10f1 --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-06-28-16-17-55.gh-issue-152502.6SNqMg.rst @@ -0,0 +1,5 @@ +The :mod:`curses` module now detects ``set_escdelay()``, ``set_tabsize()`` and +the ``ESCDELAY`` and ``TABSIZE`` variables with :program:`configure` capability +probes instead of the ncurses-specific ``NCURSES_EXT_FUNCS`` macro, so they are +exposed when building against other curses implementations such as NetBSD curses +that provide them. diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index b7195264c7f0..f474174ef7c9 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -4027,9 +4027,7 @@ _curses_setupterm_impl(PyObject *module, const char *term, int fd) Py_RETURN_NONE; } -#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102 -// https://invisible-island.net/ncurses/NEWS.html#index-t20080119 - +#ifdef HAVE_CURSES_ESCDELAY /*[clinic input] _curses.get_escdelay @@ -4046,6 +4044,9 @@ _curses_get_escdelay_impl(PyObject *module) { return PyLong_FromLong(ESCDELAY); } +#endif /* HAVE_CURSES_ESCDELAY */ + +#ifdef HAVE_CURSES_SET_ESCDELAY /*[clinic input] _curses.set_escdelay ms: int @@ -4070,7 +4071,9 @@ _curses_set_escdelay_impl(PyObject *module, int ms) return curses_check_err(module, set_escdelay(ms), "set_escdelay", NULL); } +#endif /* HAVE_CURSES_SET_ESCDELAY */ +#ifdef HAVE_CURSES_TABSIZE /*[clinic input] _curses.get_tabsize @@ -4086,6 +4089,9 @@ _curses_get_tabsize_impl(PyObject *module) { return PyLong_FromLong(TABSIZE); } +#endif /* HAVE_CURSES_TABSIZE */ + +#ifdef HAVE_CURSES_SET_TABSIZE /*[clinic input] _curses.set_tabsize size: int @@ -4109,7 +4115,7 @@ _curses_set_tabsize_impl(PyObject *module, int size) return curses_check_err(module, set_tabsize(size), "set_tabsize", NULL); } -#endif +#endif /* HAVE_CURSES_SET_TABSIZE */ /*[clinic input] _curses.intrflush @@ -5372,10 +5378,8 @@ static PyMethodDef cursesmodule_methods[] = { _CURSES_RESIZETERM_METHODDEF _CURSES_RESIZE_TERM_METHODDEF _CURSES_SAVETTY_METHODDEF -#if defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102 _CURSES_GET_ESCDELAY_METHODDEF _CURSES_SET_ESCDELAY_METHODDEF -#endif _CURSES_GET_TABSIZE_METHODDEF _CURSES_SET_TABSIZE_METHODDEF _CURSES_SETSYX_METHODDEF diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h index cab9b068a561..9235586587e8 100644 --- a/Modules/clinic/_cursesmodule.c.h +++ b/Modules/clinic/_cursesmodule.c.h @@ -2792,7 +2792,7 @@ exit: return return_value; } -#if (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) +#if defined(HAVE_CURSES_ESCDELAY) PyDoc_STRVAR(_curses_get_escdelay__doc__, "get_escdelay($module, /)\n" @@ -2816,9 +2816,9 @@ _curses_get_escdelay(PyObject *module, PyObject *Py_UNUSED(ignored)) return _curses_get_escdelay_impl(module); } -#endif /* (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) */ +#endif /* defined(HAVE_CURSES_ESCDELAY) */ -#if (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) +#if defined(HAVE_CURSES_SET_ESCDELAY) PyDoc_STRVAR(_curses_set_escdelay__doc__, "set_escdelay($module, ms, /)\n" @@ -2855,9 +2855,9 @@ exit: return return_value; } -#endif /* (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) */ +#endif /* defined(HAVE_CURSES_SET_ESCDELAY) */ -#if (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) +#if defined(HAVE_CURSES_TABSIZE) PyDoc_STRVAR(_curses_get_tabsize__doc__, "get_tabsize($module, /)\n" @@ -2880,9 +2880,9 @@ _curses_get_tabsize(PyObject *module, PyObject *Py_UNUSED(ignored)) return _curses_get_tabsize_impl(module); } -#endif /* (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) */ +#endif /* defined(HAVE_CURSES_TABSIZE) */ -#if (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) +#if defined(HAVE_CURSES_SET_TABSIZE) PyDoc_STRVAR(_curses_set_tabsize__doc__, "set_tabsize($module, size, /)\n" @@ -2918,7 +2918,7 @@ exit: return return_value; } -#endif /* (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20081102) */ +#endif /* defined(HAVE_CURSES_SET_TABSIZE) */ PyDoc_STRVAR(_curses_intrflush__doc__, "intrflush($module, flag, /)\n" @@ -4486,4 +4486,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored #ifndef _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF #define _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF #endif /* !defined(_CURSES_ASSUME_DEFAULT_COLORS_METHODDEF) */ -/*[clinic end generated code: output=11ab7c93cbc13e75 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7835b44ce9413f7f input=a9049054013a1b77]*/ diff --git a/configure b/configure index a296f76a030a..d17240882ec9 100755 --- a/configure +++ b/configure @@ -29714,6 +29714,8 @@ fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for curses function is_pad" >&5 printf %s "checking for curses function is_pad... " >&6; } if test ${ac_cv_lib_curses_is_pad+y} @@ -30372,6 +30374,242 @@ fi + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for curses function set_escdelay" >&5 +printf %s "checking for curses function set_escdelay... " >&6; } +if test ${ac_cv_lib_curses_set_escdelay+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define NCURSES_OPAQUE 0 +#if defined(HAVE_NCURSESW_NCURSES_H) +# include +#elif defined(HAVE_NCURSESW_CURSES_H) +# include +#elif defined(HAVE_NCURSES_NCURSES_H) +# include +#elif defined(HAVE_NCURSES_CURSES_H) +# include +#elif defined(HAVE_NCURSES_H) +# include +#elif defined(HAVE_CURSES_H) +# include +#endif + +int +main (void) +{ + + #ifndef set_escdelay + void *x=set_escdelay + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_lib_curses_set_escdelay=yes +else case e in #( + e) ac_cv_lib_curses_set_escdelay=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curses_set_escdelay" >&5 +printf "%s\n" "$ac_cv_lib_curses_set_escdelay" >&6; } + if test "x$ac_cv_lib_curses_set_escdelay" = xyes +then : + +printf "%s\n" "#define HAVE_CURSES_SET_ESCDELAY 1" >>confdefs.h + +fi + + + + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for curses function set_tabsize" >&5 +printf %s "checking for curses function set_tabsize... " >&6; } +if test ${ac_cv_lib_curses_set_tabsize+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define NCURSES_OPAQUE 0 +#if defined(HAVE_NCURSESW_NCURSES_H) +# include +#elif defined(HAVE_NCURSESW_CURSES_H) +# include +#elif defined(HAVE_NCURSES_NCURSES_H) +# include +#elif defined(HAVE_NCURSES_CURSES_H) +# include +#elif defined(HAVE_NCURSES_H) +# include +#elif defined(HAVE_CURSES_H) +# include +#endif + +int +main (void) +{ + + #ifndef set_tabsize + void *x=set_tabsize + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_lib_curses_set_tabsize=yes +else case e in #( + e) ac_cv_lib_curses_set_tabsize=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curses_set_tabsize" >&5 +printf "%s\n" "$ac_cv_lib_curses_set_tabsize" >&6; } + if test "x$ac_cv_lib_curses_set_tabsize" = xyes +then : + +printf "%s\n" "#define HAVE_CURSES_SET_TABSIZE 1" >>confdefs.h + +fi + + + + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for curses variable ESCDELAY" >&5 +printf %s "checking for curses variable ESCDELAY... " >&6; } +if test ${ac_cv_lib_curses_ESCDELAY+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define NCURSES_OPAQUE 0 +#if defined(HAVE_NCURSESW_NCURSES_H) +# include +#elif defined(HAVE_NCURSESW_CURSES_H) +# include +#elif defined(HAVE_NCURSES_NCURSES_H) +# include +#elif defined(HAVE_NCURSES_CURSES_H) +# include +#elif defined(HAVE_NCURSES_H) +# include +#elif defined(HAVE_CURSES_H) +# include +#endif + +int +main (void) +{ + + int x = ESCDELAY; (void)x; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_lib_curses_ESCDELAY=yes +else case e in #( + e) ac_cv_lib_curses_ESCDELAY=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curses_ESCDELAY" >&5 +printf "%s\n" "$ac_cv_lib_curses_ESCDELAY" >&6; } + if test "x$ac_cv_lib_curses_ESCDELAY" = xyes +then : + +printf "%s\n" "#define HAVE_CURSES_ESCDELAY 1" >>confdefs.h + +fi + + + + + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for curses variable TABSIZE" >&5 +printf %s "checking for curses variable TABSIZE... " >&6; } +if test ${ac_cv_lib_curses_TABSIZE+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#define NCURSES_OPAQUE 0 +#if defined(HAVE_NCURSESW_NCURSES_H) +# include +#elif defined(HAVE_NCURSESW_CURSES_H) +# include +#elif defined(HAVE_NCURSES_NCURSES_H) +# include +#elif defined(HAVE_NCURSES_CURSES_H) +# include +#elif defined(HAVE_NCURSES_H) +# include +#elif defined(HAVE_CURSES_H) +# include +#endif + +int +main (void) +{ + + int x = TABSIZE; (void)x; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_lib_curses_TABSIZE=yes +else case e in #( + e) ac_cv_lib_curses_TABSIZE=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_curses_TABSIZE" >&5 +printf "%s\n" "$ac_cv_lib_curses_TABSIZE" >&6; } + if test "x$ac_cv_lib_curses_TABSIZE" = xyes +then : + +printf "%s\n" "#define HAVE_CURSES_TABSIZE 1" >>confdefs.h + +fi + + + CPPFLAGS=$ac_save_cppflags fi diff --git a/configure.ac b/configure.ac index f7931cfab580..0cf3d3f24506 100644 --- a/configure.ac +++ b/configure.ac @@ -7248,6 +7248,30 @@ AC_DEFUN([PY_CHECK_CURSES_FUNC], AS_VAR_POPDEF([py_define]) ]) +dnl PY_CHECK_CURSES_VAR(VARIABLE) +dnl Like PY_CHECK_CURSES_FUNC, but for an integer variable (or macro), such as +dnl ESCDELAY, which a function probe cannot detect. +AC_DEFUN([PY_CHECK_CURSES_VAR], +[ AS_VAR_PUSHDEF([py_var], [ac_cv_lib_curses_$1]) + AS_VAR_PUSHDEF([py_define], [HAVE_CURSES_]m4_toupper($1)) + AC_CACHE_CHECK( + [for curses variable $1], + [py_var], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM(_CURSES_INCLUDES, [ + int x = $1; (void)x; + ])], + [AS_VAR_SET([py_var], [yes])], + [AS_VAR_SET([py_var], [no])])] + ) + AS_VAR_IF( + [py_var], + [yes], + [AC_DEFINE([py_define], [1], [Define if you have the '$1' variable.])]) + AS_VAR_POPDEF([py_var]) + AS_VAR_POPDEF([py_define]) +]) + PY_CHECK_CURSES_FUNC([is_pad]) PY_CHECK_CURSES_FUNC([is_term_resized]) PY_CHECK_CURSES_FUNC([resize_term]) @@ -7259,6 +7283,10 @@ PY_CHECK_CURSES_FUNC([filter]) PY_CHECK_CURSES_FUNC([has_key]) PY_CHECK_CURSES_FUNC([typeahead]) PY_CHECK_CURSES_FUNC([use_env]) +PY_CHECK_CURSES_FUNC([set_escdelay]) +PY_CHECK_CURSES_FUNC([set_tabsize]) +PY_CHECK_CURSES_VAR([ESCDELAY]) +PY_CHECK_CURSES_VAR([TABSIZE]) CPPFLAGS=$ac_save_cppflags ])dnl have_curses != no ])dnl save env diff --git a/pyconfig.h.in b/pyconfig.h.in index 318a9e1ba063..058fc9f0a42f 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -185,6 +185,9 @@ /* Define if you have the 'ctermid_r' function. */ #undef HAVE_CTERMID_R +/* Define if you have the 'ESCDELAY' variable. */ +#undef HAVE_CURSES_ESCDELAY + /* Define if you have the 'filter' function. */ #undef HAVE_CURSES_FILTER @@ -209,9 +212,18 @@ /* Define if you have the 'resize_term' function. */ #undef HAVE_CURSES_RESIZE_TERM +/* Define if you have the 'set_escdelay' function. */ +#undef HAVE_CURSES_SET_ESCDELAY + +/* Define if you have the 'set_tabsize' function. */ +#undef HAVE_CURSES_SET_TABSIZE + /* Define if you have the 'syncok' function. */ #undef HAVE_CURSES_SYNCOK +/* Define if you have the 'TABSIZE' variable. */ +#undef HAVE_CURSES_TABSIZE + /* Define if you have the 'typeahead' function. */ #undef HAVE_CURSES_TYPEAHEAD