To: vim_dev@googlegroups.com Subject: Patch 8.2.1830 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1830 Problem: MS-Windows: Python3 issue with stdin. Solution: Check if stdin is readable. (Ken Takata, closes #7106) Files: src/if_python3.c *** ../vim-8.2.1829/src/if_python3.c 2020-10-06 19:59:03.470903612 +0200 --- src/if_python3.c 2020-10-10 23:25:40.439174291 +0200 *************** *** 908,915 **** static wchar_t *py_home_buf = NULL; #if defined(MSWIN) && (PY_VERSION_HEX >= 0x030500f0) ! // Python 3.5 or later will abort inside Py_Initialize() when stdin is ! // redirected. Reconnect stdin to NUL. // Note that the python DLL is linked to its own stdio DLL which can be // differ from Vim's stdio. static void --- 908,934 ---- static wchar_t *py_home_buf = NULL; #if defined(MSWIN) && (PY_VERSION_HEX >= 0x030500f0) ! /* ! * Return TRUE if stdin is readable from Python 3. ! */ ! static BOOL ! is_stdin_readable(void) ! { ! DWORD mode, eventnum; ! struct _stat st; ! int fd = fileno(stdin); ! HANDLE hstdin = (HANDLE)_get_osfhandle(fd); ! ! // Check if stdin is connected to the console. ! if (GetConsoleMode(hstdin, &mode)) ! // Check if it is opened as input. ! return GetNumberOfConsoleInputEvents(hstdin, &eventnum); ! ! return _fstat(fd, &st) == 0; ! } ! ! // Python 3.5 or later will abort inside Py_Initialize() when stdin has ! // been closed (i.e. executed by "vim -"). Reconnect stdin to CONIN$. // Note that the python DLL is linked to its own stdio DLL which can be // differ from Vim's stdio. static void *************** *** 917,923 **** { FILE *(*py__acrt_iob_func)(unsigned) = NULL; FILE *(*pyfreopen)(const char *, const char *, FILE *) = NULL; - char *stdin_name = "NUL"; HINSTANCE hinst; # ifdef DYNAMIC_PYTHON3 --- 936,941 ---- *************** *** 925,931 **** # else hinst = GetModuleHandle(PYTHON3_DLL); # endif ! if (hinst == NULL) return; // Get "freopen" and "stdin" which are used in the python DLL. --- 943,949 ---- # else hinst = GetModuleHandle(PYTHON3_DLL); # endif ! if (hinst == NULL || is_stdin_readable()) return; // Get "freopen" and "stdin" which are used in the python DLL. *************** *** 938,951 **** if (hpystdiodll) pyfreopen = (void *)GetProcAddress(hpystdiodll, "freopen"); } - if (isatty(fileno(stdin))) - stdin_name = "CONIN$"; ! // Reconnect stdin to NUL or CONIN$. if (pyfreopen != NULL) ! pyfreopen(stdin_name, "r", py__acrt_iob_func(0)); else ! freopen(stdin_name, "r", stdin); } #else # define reset_stdin() --- 956,967 ---- if (hpystdiodll) pyfreopen = (void *)GetProcAddress(hpystdiodll, "freopen"); } ! // Reconnect stdin to CONIN$. if (pyfreopen != NULL) ! pyfreopen("CONIN$", "r", py__acrt_iob_func(0)); else ! freopen("CONIN$", "r", stdin); } #else # define reset_stdin() *** ../vim-8.2.1829/src/version.c 2020-10-10 22:34:32.582802879 +0200 --- src/version.c 2020-10-10 22:56:28.662944867 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1830, /**/ -- Q: Should I clean my house or work on Vim? A: Whatever contains more bugs. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///