Skip to content

Commit 23ea56e

Browse files
committed
gh-46927: Prevent readline from overriding environment
Readline library will set the LINES and COLUMNS environment variables during initialization. One might expect these variables to be updated later on SIGWINCH, but this is not the case with cpython. As a consequence, when the readline module is imported, any process launched from cpython with the default environment will have LINES and COLUMNS variables set, potentially to a wrong value. Use the rl_change_environment global variable to disable this initial setup of the environment variables.
1 parent 945bf8c commit 23ea56e

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent :mod:`readline` from overriding the ``COLUMNS`` and ``LINES``
2+
environment variables, as values are not updated on terminal resize.

Modules/readline.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,13 @@ setup_readline(readlinestate *mod_state)
13491349
/* The name must be defined before initialization */
13501350
rl_readline_name = "python";
13511351

1352+
#ifndef WITH_EDITLINE
1353+
/* Prevent readline from changing environment variables such as LINES and
1354+
* COLUMNS.
1355+
*/
1356+
rl_change_environment = 0;
1357+
#endif
1358+
13521359
/* the libedit readline emulation resets key bindings etc
13531360
* when calling rl_initialize. So call it upfront
13541361
*/

0 commit comments

Comments
 (0)