https://github.com/python/cpython/commit/2db8ca79e0d10f134768250ac530bad45ce2758b
commit: 2db8ca79e0d10f134768250ac530bad45ce2758b
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-07-27T14:04:51+03:00
summary:

gh-154070: Build the curses module wide by capability, not by name (GH-154071)

configure built the module wide (HAVE_NCURSESW) only for a backend named
ncursesw.  Probe for the wide API in the ncurses and auto backends too, so
a widec-built ncurses keeping the plain name (pkgsrc, macOS) is built wide.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

files:
A Misc/NEWS.d/next/Build/2026-07-19-12-16-31.gh-issue-154070.f5da07.rst
M configure
M configure.ac

diff --git 
a/Misc/NEWS.d/next/Build/2026-07-19-12-16-31.gh-issue-154070.f5da07.rst 
b/Misc/NEWS.d/next/Build/2026-07-19-12-16-31.gh-issue-154070.f5da07.rst
new file mode 100644
index 000000000000000..31c6fd3ece35322
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2026-07-19-12-16-31.gh-issue-154070.f5da07.rst
@@ -0,0 +1,4 @@
+Build the :mod:`curses` module against a wide-character capable ncurses
+even when it is not named ``ncursesw`` -- for example the pkgsrc ncurses on
+NetBSD and illumos, or the system ncurses on macOS.  Such a library
+previously produced a narrow build.
diff --git a/configure b/configure
index 08b493311a3f92e..dc23b9f7c20da2f 100755
--- a/configure
+++ b/configure
@@ -30910,9 +30910,13 @@ fi
 
 PANEL_CFLAGS=$(echo $PANEL_CFLAGS | sed 's/-D_XOPEN_SOURCE=600//g')
 
-if test "x$with_curses" = xcurses
-then :
+case $with_curses in #(
+  ncursesw|no) :
+     ;; #(
+  *) :
 
+          save_curses_cppflags=$CPPFLAGS
+  as_fn_append CPPFLAGS " $CURSES_CFLAGS"
   { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether curses 
supports wide characters" >&5
 printf %s "checking whether curses supports wide characters... " >&6; }
 if test ${ac_cv_curses_wide+y}
@@ -30962,13 +30966,14 @@ esac
 fi
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_curses_wide" >&5
 printf "%s\n" "$ac_cv_curses_wide" >&6; }
+  CPPFLAGS=$save_curses_cppflags
       if test "x$ac_cv_curses_wide" = xyes
 then :
   printf "%s\n" "#define HAVE_NCURSESW 1" >>confdefs.h
 
 fi
-
-fi
+ ;;
+esac
 
 # On Solaris, term.h requires curses.h
 ac_fn_c_check_header_compile "$LINENO" "term.h" "ac_cv_header_term_h" "
diff --git a/configure.ac b/configure.ac
index f40db5bc82e24a8..5a59e70d64bab31 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7248,12 +7248,18 @@ AS_VAR_IF([ac_sys_system], [Darwin], [
 dnl pyconfig.h defines _XOPEN_SOURCE=700
 PANEL_CFLAGS=$(echo $PANEL_CFLAGS | sed 's/-D_XOPEN_SOURCE=600//g')
 
-dnl Native curses ("curses") may be wide-character capable (e.g. on NetBSD)
-dnl even though it is not ncursesw.  Probe for the wide API; if present, build
-dnl the module against it like ncursesw by defining HAVE_NCURSESW.  ncursesw
-dnl already defines HAVE_NCURSESW, and ncurses must stay narrow, so only the
-dnl native backend is probed here.
-AS_VAR_IF([with_curses], [curses], [
+dnl A curses that is not named "ncursesw" can still be wide-character capable:
+dnl the system curses of NetBSD, or an ncurses built with --enable-widec that
+dnl keeps the plain name (pkgsrc, macOS).  Probe for the wide API and, if
+dnl present, build the module wide by defining HAVE_NCURSESW.  The "ncursesw"
+dnl backend already defines it, so only the other backends are probed.
+AS_CASE([$with_curses], [ncursesw|no], [], [
+  dnl Use the adjusted CURSES_CFLAGS (e.g. macOS's -D_XOPEN_SOURCE_EXTENDED)
+  dnl so the wide-character declarations are visible to the probe.  This runs
+  dnl inside an outer WITH_SAVE_ENV, whose single CPPFLAGS save slot is not
+  dnl reentrant, so save and restore CPPFLAGS with a dedicated variable here.
+  save_curses_cppflags=$CPPFLAGS
+  AS_VAR_APPEND([CPPFLAGS], [" $CURSES_CFLAGS"])
   AC_CACHE_CHECK([whether curses supports wide characters],
     [ac_cv_curses_wide],
     [AC_LINK_IFELSE(
@@ -7264,6 +7270,7 @@ AS_VAR_IF([with_curses], [curses], [
       ]])],
       [ac_cv_curses_wide=yes],
       [ac_cv_curses_wide=no])])
+  CPPFLAGS=$save_curses_cppflags
   dnl HAVE_NCURSESW marks the wide (cchar_t) curses API; its template comes
   dnl from the ncursesw pkg-config check above, so no description here.
   AS_VAR_IF([ac_cv_curses_wide], [yes], [AC_DEFINE([HAVE_NCURSESW], [1])])

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to