]> granicus.if.org Git - vim/commitdiff
patch 7.4.886 v7.4.886
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Sep 2015 12:01:12 +0000 (14:01 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Sep 2015 12:01:12 +0000 (14:01 +0200)
Problem:    Windows7: Switching screen buffer causes flicker when using
            system().
Solution:   Instead of actually switching screen buffer, duplicate the handle.
            (Yasuhiro Matsumoto)

src/os_win32.c
src/version.c

index 6981d2f31c81e44abe446986cd9034e9f783ac48..5114863faecefea7c160ad98ddcf81a17faddd08 100644 (file)
@@ -4612,20 +4612,34 @@ mch_system1(char *cmd, int options)
 mch_system(char *cmd, int options)
 {
     int ret;
+    HANDLE hTemp = INVALID_HANDLE_VALUE;
 
     /*
-     * Restore non-termcap screen buffer before execute external program, and
-     * revert it after.  Because msys and msys2's programs will cause freeze
-     * or crash conhost.exe (Windows's console window provider) and vim.exe,
-     * if active screen buffer is vim's one on Windows7.
+     * Call DuplicateHandle before executing an external program, because msys
+     * and msys2's programs will call CreateConsoleScreenBuffer and
+     * CloseHandle.  CreateConsoleScreenBuffer returns the same handle which
+     * created by vim.  This causes a crash. This workaround is required on
+     * Windows7.
      */
-    if (is_win7 && g_fTermcapMode)
-       SetConsoleActiveScreenBuffer(g_cbNonTermcap.handle);
+    if (is_win7
+           && g_fTermcapMode
+           && DuplicateHandle(
+                   GetCurrentProcess(),
+                   g_hConOut,
+                   GetCurrentProcess(),
+                   &hTemp,
+                   0,
+                   TRUE,
+                   DUPLICATE_SAME_ACCESS))
+       SetConsoleActiveScreenBuffer(hTemp);
 
     ret = mch_system1(cmd, options);
 
-    if (is_win7 && g_fTermcapMode)
-       SetConsoleActiveScreenBuffer(g_cbTermcap.handle);
+    if (hTemp != INVALID_HANDLE_VALUE)
+    {
+       SetConsoleActiveScreenBuffer(g_hConOut);
+       CloseHandle(hTemp);
+    }
 
     return ret;
 }
index f31f1bd1cb28913fefde952064e01cb02f7796d4..51602989d9b377db7c9fb866f8da27e362cf0462 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    886,
 /**/
     885,
 /**/