From 7cfc4e5146be5666419451bdd516f1f3f264d24a Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Sun, 25 Jan 2015 14:42:51 +0100 Subject: Imported Upstream version 8.5~beta1+dfsg --- ide/ide_win32_stubs.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'ide/ide_win32_stubs.c') diff --git a/ide/ide_win32_stubs.c b/ide/ide_win32_stubs.c index c170b1a9..c09bf37d 100644 --- a/ide/ide_win32_stubs.c +++ b/ide/ide_win32_stubs.c @@ -19,33 +19,31 @@ CAMLprim value win32_kill(value pseudopid) { CAMLreturn(Val_unit); } -/* Win32 emulation of a kill -2 (SIGINT) */ -/* For simplicity, we signal all processes sharing a console with coqide. - This shouldn't be an issue since currently at most one coqtop is busy - at a given time. Earlier, we tried to be more precise via - FreeConsole and AttachConsole before generating the Ctrl-C, but - that wasn't working so well (see #2869). - This code rely now on the fact that coqide is a console app, - and that coqide itself ignores Ctrl-C. -*/ +/* Win32 emulation of a kill -2 (SIGINT) */ -CAMLprim value win32_interrupt_all(value unit) { - CAMLparam1(unit); - GenerateConsoleCtrlEvent(CTRL_C_EVENT,0); - CAMLreturn(Val_unit); -} +/* This code rely of the fact that coqide is now without initial console. + Otherwise, no console creation in win32unix/createprocess.c, hence + the same console for coqide and all coqtop, and everybody will be + signaled at the same time by the code below. */ -/* Get rid of the nasty console window (only if we created it) */ +/* Moreover, AttachConsole exists only since WinXP, and GetProcessId + since WinXP SP1. For avoiding the GetProcessId, we could adapt code + from win32unix/createprocess.c to make it return both the pid and the + handle. For avoiding the AttachConsole, I don't know, maybe having + an intermediate process between coqide and coqtop ? */ -CAMLprim value win32_hide_console (value unit) { - CAMLparam1(unit); +CAMLprim value win32_interrupt(value pseudopid) { + CAMLparam1(pseudopid); + HANDLE h; DWORD pid; - HWND hw = GetConsoleWindow(); - if (hw != NULL) { - GetWindowThreadProcessId(hw, &pid); - if (pid == GetCurrentProcessId()) - ShowWindow(hw, SW_HIDE); - } + FreeConsole(); /* Normally unnecessary, just to be sure... */ + h = (HANDLE)(Long_val(pseudopid)); + pid = GetProcessId(h); + AttachConsole(pid); + /* We want to survive the Ctrl-C that will also concerns us */ + SetConsoleCtrlHandler(NULL,TRUE); /* NULL + TRUE means ignore */ + GenerateConsoleCtrlEvent(CTRL_C_EVENT,0); /* signal our co-console */ + FreeConsole(); CAMLreturn(Val_unit); } -- cgit v1.2.3