Skip to content

Commit e3bce0d

Browse files
serhiy-storchakaclaude
authored andcommitted
gh-46927: Detect rl_change_environment with a configure probe
Guard the rl_change_environment assignment with HAVE_RL_CHANGE_ENVIRONMENT, set by a configure link test, instead of the __APPLE__ macro. This compiles it out on any libedit build lacking the symbol, not just on macOS. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8bbc1cf commit e3bce0d

4 files changed

Lines changed: 69 additions & 4 deletions

File tree

Modules/readline.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,10 +1323,10 @@ setup_readline(readlinestate *mod_state)
13231323
/* The name must be defined before initialization */
13241324
rl_readline_name = "python";
13251325

1326-
#if !defined(__APPLE__)
1327-
/* Prevent readline from changing environment variables such as LINES and
1328-
* COLUMNS.
1329-
*/
1326+
#ifdef HAVE_RL_CHANGE_ENVIRONMENT
1327+
/* Prevent readline from setting the LINES and COLUMNS environment
1328+
* variables: ncurses prefers them over an ioctl() query, so a stale value
1329+
* left after a resize breaks SIGWINCH / KEY_RESIZE handling (gh-46927). */
13301330
rl_change_environment = 0;
13311331
#endif
13321332

configure

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6472,6 +6472,17 @@ AS_VAR_IF([with_readline], [no], [
64726472
AC_DEFINE([HAVE_RL_RESIZE_TERMINAL], [1], [Define if you have readline 4.0])
64736473
])
64746474
6475+
# rl_change_environment is in readline 6.3, but not in editline
6476+
AC_CACHE_CHECK([for rl_change_environment in -l$LIBREADLINE], [ac_cv_readline_rl_change_environment], [
6477+
AC_LINK_IFELSE(
6478+
[AC_LANG_PROGRAM([readline_includes], [int x = rl_change_environment])],
6479+
[ac_cv_readline_rl_change_environment=yes], [ac_cv_readline_rl_change_environment=no]
6480+
)
6481+
])
6482+
AS_VAR_IF([ac_cv_readline_rl_change_environment], [yes], [
6483+
AC_DEFINE([HAVE_RL_CHANGE_ENVIRONMENT], [1], [Define if you have readline 6.3])
6484+
])
6485+
64756486
# check for readline 4.2
64766487
AC_CACHE_CHECK([for rl_completion_matches in -l$LIBREADLINE], [ac_cv_readline_rl_completion_matches], [
64776488
AC_LINK_IFELSE(

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,9 @@
10741074
/* Define if you can turn off readline's signal handling. */
10751075
#undef HAVE_RL_CATCH_SIGNAL
10761076

1077+
/* Define if you have readline 6.3 */
1078+
#undef HAVE_RL_CHANGE_ENVIRONMENT
1079+
10771080
/* Define to 1 if the system has the type 'rl_compdisp_func_t'. */
10781081
#undef HAVE_RL_COMPDISP_FUNC_T
10791082

0 commit comments

Comments
 (0)