Skip to content

Commit bc76d98

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 8679c8d commit bc76d98

File tree

2 files changed

+9
-0
lines changed

2 files changed

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

Modules/readline.c

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

1326+
#ifndef WITH_EDITLINE
1327+
/* Prevent readline from changing environment variables such as LINES and
1328+
* COLUMNS.
1329+
*/
1330+
rl_change_environment = 0;
1331+
#endif
1332+
13261333
/* the libedit readline emulation resets key bindings etc
13271334
* when calling rl_initialize. So call it upfront
13281335
*/

0 commit comments

Comments
 (0)