Created
September 29, 2015 02:05
-
-
Save mattn/26f7aeb8b888df92ddbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/os_win32.c b/src/os_win32.c | |
index 6981d2f..57feae6 100644 | |
--- a/src/os_win32.c | |
+++ b/src/os_win32.c | |
@@ -4614,18 +4614,31 @@ mch_system(char *cmd, int options) | |
int ret; | |
/* | |
- * 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 execute external program. Because msys and | |
+ * msys2's programs will call CreateConsoleScreenBuffer and CloseHandle. | |
+ * CreateConsoleScreenBuffer return same handle which created by vim. | |
+ * So it occurs crash. This workaround is required on Windows7. | |
*/ | |
+ HANDLE hTemp = INVALID_HANDLE_VALUE; | |
if (is_win7 && g_fTermcapMode) | |
- SetConsoleActiveScreenBuffer(g_cbNonTermcap.handle); | |
+ { | |
+ if (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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment