Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@ def test_write_read_limited_history(self):
# So, we've only tested that the read did not fail.
# See TestHistoryManipulation for the full test.

def test_environment_is_not_modified(self):
# os.environ contains enviroment at the time "os" module was loaded, so
# before the "readline" module is loaded.
original_env = dict(os.environ)
Comment thread
mbriand marked this conversation as resolved.

# Force refresh of os.environ and make sure it is the same as before the
# refresh.
os.reload_environ()
self.assertEqual(dict(os.environ), original_env)

@unittest.skipUnless(support.Py_GIL_DISABLED, 'these tests can only possibly fail with GIL disabled')
class FreeThreadingTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Prevent :mod:`readline` from overriding the ``COLUMNS`` and ``LINES``
environment variables, as values are not updated on terminal resize.
7 changes: 7 additions & 0 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,13 @@ setup_readline(readlinestate *mod_state)
/* The name must be defined before initialization */
rl_readline_name = "python";

#ifdef HAVE_RL_CHANGE_ENVIRONMENT
/* Prevent readline from setting the LINES and COLUMNS environment
* variables: ncurses prefers them over an ioctl() query, so a stale value
* left after a resize breaks SIGWINCH / KEY_RESIZE handling (gh-46927). */
rl_change_environment = 0;
#endif

/* the libedit readline emulation resets key bindings etc
* when calling rl_initialize. So call it upfront
*/
Expand Down
51 changes: 51 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6472,6 +6472,17 @@ AS_VAR_IF([with_readline], [no], [
AC_DEFINE([HAVE_RL_RESIZE_TERMINAL], [1], [Define if you have readline 4.0])
])

# rl_change_environment is in readline 6.3, but not in editline
AC_CACHE_CHECK([for rl_change_environment in -l$LIBREADLINE], [ac_cv_readline_rl_change_environment], [
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([readline_includes], [int x = rl_change_environment])],
[ac_cv_readline_rl_change_environment=yes], [ac_cv_readline_rl_change_environment=no]
)
])
AS_VAR_IF([ac_cv_readline_rl_change_environment], [yes], [
AC_DEFINE([HAVE_RL_CHANGE_ENVIRONMENT], [1], [Define if you have readline 6.3])
])

# check for readline 4.2
AC_CACHE_CHECK([for rl_completion_matches in -l$LIBREADLINE], [ac_cv_readline_rl_completion_matches], [
AC_LINK_IFELSE(
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,9 @@
/* Define if you can turn off readline's signal handling. */
#undef HAVE_RL_CATCH_SIGNAL

/* Define if you have readline 6.3 */
#undef HAVE_RL_CHANGE_ENVIRONMENT

/* Define to 1 if the system has the type 'rl_compdisp_func_t'. */
#undef HAVE_RL_COMPDISP_FUNC_T

Expand Down