From 2ed54ffee66ef3598b0022b6b7844721fc131bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Sat, 23 Jan 2016 18:07:40 +0100 Subject: [PATCH 1/4] cleanup: unixint: remove dead code Old implementation of `asynchronous_signal_servicing_thread' was reimplemented long time ago. Old implementation was still present in sources surrounded with `#if 0 ... #endif'. Remove it. --- src/c/unixint.d | 73 +------------------------------------------------ 1 file changed, 1 insertion(+), 72 deletions(-) diff --git a/src/c/unixint.d b/src/c/unixint.d index 014d60a10..861c6dc12 100644 --- a/src/c/unixint.d +++ b/src/c/unixint.d @@ -8,6 +8,7 @@ Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya. Copyright (c) 1990, Giuseppe Attardi. Copyright (c) 2001, Juan Jose Garcia Ripoll. + Copyright (c) 2016, Daniel KochmaƄski. ECL is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -1129,78 +1130,6 @@ BOOL WINAPI W32_console_ctrl_handler(DWORD type) } #endif /* ECL_WINDOWS_THREADS */ -#if 0 -static cl_object -asynchronous_signal_servicing_thread() -{ - const cl_env_ptr the_env = ecl_process_env(); - sigset_t handled_set; - cl_object signal_code; - int signo; - int interrupt_signal = 0; - if (ecl_option_values[ECL_OPT_TRAP_INTERRUPT_SIGNAL]) { - interrupt_signal = ecl_option_values[ECL_OPT_THREAD_INTERRUPT_SIGNAL]; - } - /* - * We wait here for all signals that are blocked in all other - * threads. It would be desirable to be able to wait for _all_ - * signals, but this can not be done for SIGFPE, SIGSEGV, etc. - */ - pthread_sigmask(SIG_SETMASK, NULL, &handled_set); - /* - * Under OS X we also have to explicitely add the signal we - * use to communicate process interrupts. For some unknown - * reason those signals may get lost. - */ - if (interrupt_signal) { - sigaddset(&handled_set, interrupt_signal); - pthread_sigmask(SIG_SETMASK, &handled_set, NULL); - } - ECL_CATCH_ALL_BEGIN(the_env) { - for (;;) { - /* Waiting may fail! */ - int status = sigwait(&handled_set, &signo); - if (status == 0) { -#if 0 - if (signo == interrupt_signal) { - /* If we get this signal it may be because - * of two reasons. One is that it is just - * an awake message. Then the queue is empty - * and we continue ... */ - signal_code = pop_signal(the_env); - if (Null(signal_code)) - continue; - /* ... the other one is that we are being - * interrupted, but this only happens when - * we quit */ - break; - } -#else - if (signo == interrupt_signal) { - break; - } -#endif -#ifdef SIGCHLD - if (signo == SIGCHLD) { - si_wait_for_all_processes(0); - continue; - } -#endif - signal_code = ecl_gethash_safe(ecl_make_fixnum(signo), - cl_core.known_signals, - ECL_NIL); - if (!Null(signal_code)) { - mp_process_run_function(3, @'si::handle-signal', - @'si::handle-signal', - signal_code); - } - } - } - } ECL_CATCH_ALL_END; - ecl_return0(the_env); -} -#endif - cl_object si_trap_fpe(cl_object condition, cl_object flag) { From 2f1517c9a86642021da1513c50c62c355a6aa363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Tue, 2 Feb 2016 12:53:25 +0100 Subject: [PATCH 2/4] config.h.in: fix preprocessor typo should be __WIN64__, not __WING64__ --- src/h/config.h.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/h/config.h.in b/src/h/config.h.in index 7bd23902b..1dc3c7aba 100644 --- a/src/h/config.h.in +++ b/src/h/config.h.in @@ -16,7 +16,7 @@ See file '../Copyright' for full details. */ -#if defined(_MSC_VER) || defined(__MINGW32__) || __WIN32__ || __WING64__ +#if defined(_MSC_VER) || defined(__MINGW32__) || __WIN32__ || __WIN64__ #define ECL_MS_WINDOWS_HOST #endif From a119b491c06bb2d89d4c04f9fc7556ab39bc121c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Tue, 2 Feb 2016 13:14:36 +0100 Subject: [PATCH 3/4] windows: handle events --- src/c/unixint.d | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/c/unixint.d b/src/c/unixint.d index 861c6dc12..a0d0d95ee 100644 --- a/src/c/unixint.d +++ b/src/c/unixint.d @@ -1119,10 +1119,32 @@ _ecl_w32_exception_filter(struct _EXCEPTION_POINTERS* ep) return excpt_result; } +static cl_object +W32_handle_in_new_thread(cl_object signal_code) +{ + int outside_ecl = ecl_import_current_thread(@'si::handle-signal', ECL_NIL); + mp_process_run_function(4, @'si::handle-signal', + @'si::handle-signal', + signal_code, ECL_NIL); + if (outside_ecl) ecl_release_current_thread(); +} + BOOL WINAPI W32_console_ctrl_handler(DWORD type) { switch (type) { - case CTRL_C_EVENT: /* Catch CTRL-C (ignore interrupt) */ + case CTRL_C_EVENT: + case CTRL_BREAK_EVENT: { + cl_object function = ECL_SYM_FUN(@'si::terminal-interrupt'); + if (function) + W32_handle_in_new_thread(function); + return TRUE; + } + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + cl_object function = ECL_SYM_FUN(@'si::quit'); + if (function) + W32_handle_in_new_thread(function); return TRUE; default: return FALSE; From cd2e04bb22b1a3f40fa5ae0885de7fbda197daed Mon Sep 17 00:00:00 2001 From: Daniel Kochmanski Date: Wed, 3 Feb 2016 15:13:39 +0100 Subject: [PATCH 4/4] windows: some love for this poor system --- msvc/Makefile | 1 + src/c/unixint.d | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/msvc/Makefile b/msvc/Makefile index 4ad0a8fc3..ed2c70e8c 100755 --- a/msvc/Makefile +++ b/msvc/Makefile @@ -297,6 +297,7 @@ cmp/load.lsp: $(srcdir)/cmp/load.lsp.in $(CP) $(srcdir)\cmp\load.lsp.in cmp\load.lsp cmp/cmpdefs.lsp: $(srcdir)/cmp/cmpdefs.lsp Makefile c\cut "@ECL_CC@" "$(CC)" \ + "@CC_IS_CXX@" "nil" \ "@CFLAGS@" "$(CFLAGS)" \ "@CFLAGS_OPTIMIZE@" "$(CFLAGS_OPTIMIZE)" \ "@ECL_CFLAGS@" "" \ diff --git a/src/c/unixint.d b/src/c/unixint.d index a0d0d95ee..087b87c5c 100644 --- a/src/c/unixint.d +++ b/src/c/unixint.d @@ -1122,11 +1122,16 @@ _ecl_w32_exception_filter(struct _EXCEPTION_POINTERS* ep) static cl_object W32_handle_in_new_thread(cl_object signal_code) { + /* XXX: there is some bug present only on windows platform + with importing the current thread. Don't know how to track + it though. */ +#if 0 int outside_ecl = ecl_import_current_thread(@'si::handle-signal', ECL_NIL); mp_process_run_function(4, @'si::handle-signal', @'si::handle-signal', signal_code, ECL_NIL); if (outside_ecl) ecl_release_current_thread(); +#endif /* 0 */ } BOOL WINAPI W32_console_ctrl_handler(DWORD type) @@ -1134,17 +1139,19 @@ BOOL WINAPI W32_console_ctrl_handler(DWORD type) switch (type) { case CTRL_C_EVENT: case CTRL_BREAK_EVENT: { - cl_object function = ECL_SYM_FUN(@'si::terminal-interrupt'); - if (function) - W32_handle_in_new_thread(function); + /* cl_object function = */ + /* ECL_SYM_FUN(@'si::terminal-interrupt'); */ + /* if (function) */ + /* W32_handle_in_new_thread(function); */ return TRUE; } case CTRL_CLOSE_EVENT: case CTRL_LOGOFF_EVENT: case CTRL_SHUTDOWN_EVENT: - cl_object function = ECL_SYM_FUN(@'si::quit'); - if (function) - W32_handle_in_new_thread(function); + /* Doing nothing is arguably the most + reasonable. Calling (quit) causes process to exit + and Windows has problems, because "process has + unexpectably died.*/ return TRUE; default: return FALSE;