From cfb986a1a239f1a00af745a53235b8473b1bd54a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 20 Jun 2022 16:10:47 +0200 Subject: [PATCH] gh-93937: PyOS_StdioReadline() uses PyConfig.legacy_windows_stdio (#94024) On Windows, PyOS_StdioReadline() now gets PyConfig.legacy_windows_stdio from _PyOS_ReadlineTState, rather than using the deprecated global Py_LegacyWindowsStdioFlag variable. Fix also a compiler warning in Py_SetStandardStreamEncoding(). --- Parser/myreadline.c | 3 ++- Python/initconfig.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Parser/myreadline.c b/Parser/myreadline.c index b10d306255bb67..d55fcefbb6f206 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -247,7 +247,8 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) assert(tstate != NULL); #ifdef MS_WINDOWS - if (!Py_LegacyWindowsStdioFlag && sys_stdin == stdin) { + const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); + if (!config->legacy_windows_stdio && sys_stdin == stdin) { HANDLE hStdIn, hStdErr; hStdIn = _Py_get_osfhandle_noraise(fileno(sys_stdin)); diff --git a/Python/initconfig.c b/Python/initconfig.c index 62f1f67473d57e..355f9869290bbd 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -543,8 +543,11 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) } #ifdef MS_WINDOWS if (_Py_StandardStreamEncoding) { +_Py_COMP_DIAG_PUSH +_Py_COMP_DIAG_IGNORE_DEPR_DECLS /* Overriding the stream encoding implies legacy streams */ Py_LegacyWindowsStdioFlag = 1; +_Py_COMP_DIAG_POP } #endif