comparison src/if_python3.c @ 22516:c174ec901f7e v8.2.1806

patch 8.2.1806: MS-Windows with Python: Vim freezes after import command Commit: https://github.com/vim/vim/commit/253b16a4abdad1df350b9ddd9a709520b063934c Author: Bram Moolenaar <Bram@vim.org> Date: Tue Oct 6 19:59:06 2020 +0200 patch 8.2.1806: MS-Windows with Python: Vim freezes after import command Problem: MS-Windows with Python: Vim freezes after import command. Solution: Use either "NUL" or "CONIN$" when reopening stdin. (Yasuhiro Matsumoto, closes #7083)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Oct 2020 20:00:04 +0200
parents 93f3cdc296e7
children 48454576b23c
comparison
equal deleted inserted replaced
22515:db179e02143d 22516:c174ec901f7e
915 static void 915 static void
916 reset_stdin(void) 916 reset_stdin(void)
917 { 917 {
918 FILE *(*py__acrt_iob_func)(unsigned) = NULL; 918 FILE *(*py__acrt_iob_func)(unsigned) = NULL;
919 FILE *(*pyfreopen)(const char *, const char *, FILE *) = NULL; 919 FILE *(*pyfreopen)(const char *, const char *, FILE *) = NULL;
920 char *stdin_name = "NUL";
920 HINSTANCE hinst; 921 HINSTANCE hinst;
921 922
922 # ifdef DYNAMIC_PYTHON3 923 # ifdef DYNAMIC_PYTHON3
923 hinst = hinstPy3; 924 hinst = hinstPy3;
924 # else 925 # else
931 // "stdin" is defined as "__acrt_iob_func(0)" in VC++ 2015 or later. 932 // "stdin" is defined as "__acrt_iob_func(0)" in VC++ 2015 or later.
932 py__acrt_iob_func = get_dll_import_func(hinst, "__acrt_iob_func"); 933 py__acrt_iob_func = get_dll_import_func(hinst, "__acrt_iob_func");
933 if (py__acrt_iob_func) 934 if (py__acrt_iob_func)
934 { 935 {
935 HINSTANCE hpystdiodll = find_imported_module_by_funcname(hinst, 936 HINSTANCE hpystdiodll = find_imported_module_by_funcname(hinst,
936 "__acrt_iob_func"); 937 "__acrt_iob_func");
937 if (hpystdiodll) 938 if (hpystdiodll)
938 pyfreopen = (void*)GetProcAddress(hpystdiodll, "freopen"); 939 pyfreopen = (void *)GetProcAddress(hpystdiodll, "freopen");
939 } 940 }
940 941 if (isatty(fileno(stdin)))
941 // Reconnect stdin to NUL. 942 stdin_name = "CONIN$";
942 if (pyfreopen) 943
943 pyfreopen("NUL", "r", py__acrt_iob_func(0)); 944 // Reconnect stdin to NUL or CONIN$.
945 if (pyfreopen != NULL)
946 pyfreopen(stdin_name, "r", py__acrt_iob_func(0));
944 else 947 else
945 freopen("NUL", "r", stdin); 948 freopen(stdin_name, "r", stdin);
946 } 949 }
947 #else 950 #else
948 # define reset_stdin() 951 # define reset_stdin()
949 #endif 952 #endif
950 953